MACD+CCI Strategy

Rocnon · strategy · 34 行 · 点赞 1,148 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
//Author: RvZ14
//Based on Joseph Nemeth MACD+CCI strategy
//Reference reading: https://sites.google.com/site/forexjosephnemeth/home/macd-cci
 
strategy(title="MACD+CCI Strategy", shorttitle="macd/cci")
length = input(14, minval=1)
fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(2,minval=1)
src = input(close, title="CCI Source")
 
//cci
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))
plot(cci, title = "cci", color=#5DADE2,linewidth = 1,transp = 0)
band1 = hline(100, color=gray, linestyle=dashed,linewidth = 1)
band0 = hline(-100, color=gray, linestyle=dashed,linewidth = 1)
fill(band1, band0, color= #F9E79F)
 
//macd
source = close
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
macd = fastMA - slowMA
signal = ema(macd, signalLength)
hist = macd - signal
plot(hist, color=#EC7063, style=histogram)
plot(macd, title = "macd", color=#5DADE2, linewidth = 1,transp = 0)
plot(signal, title = "signal", color=#F5B041,linewidth = 1,transp = 0)
 
longCond = cci > 100 and macd > 0 or cci > -100 and macd < 0
shortCond = cci < -100 and macd < 0 or cci < 100 and macd > 0
strategy.entry("long",strategy.long,when = longCond == true)
strategy.entry("short",strategy.short,when=shortCond == true)

← 返回列表