【发布时间】:2020-05-04 11:41:40
【问题描述】:
当满足以下条件时,我正在尝试在交易视图中进行回测,
1) 多头 = RSI > 50 且 MACD > SIGNAL(简称反之)
2) 当两者都满足时,进入 OPEN(0) > HIGH(满足上述条件时的信号条)
并在达到利润目标时退出。
3) 并且只有再次发生重新交叉...而不是立即发生我无法在 pine 脚本中完成并需要帮助
以下是相同的代码:
//@version=4
strategy("Test1 script",overlay=false)
var a = 0
var hiBar = 0
var loBar = 0
//MACD
fast = 12, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, 9)
//RSI
rsiSource = close //input(title="RSI Source", type=input.source, defval=close)
rsiLength = 7 //input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = 70 //nput(title="RSI Overbought Level", type=input.integer, defval=80)
rsiOversold = 30 //input(title="RSI Oversold Level", type=input.integer, defval=20)
rsiValue = rsi(rsiSource, rsiLength)
isRsiOB = rsiValue >= rsiOverbought
isRsiOS = rsiValue <= rsiOversold
uptrend1 = rsiValue > 50 and macd > signal
downtrend1 = rsiValue < 50 and macd < signal
if uptrend1 or downtrend1
a := 10
else
a := 20
if uptrend1
hiBar := bar_index
if downtrend1
loBar := bar_index
barcolor(uptrend1 ? color.purple:downtrend1 ? color.yellow: a == 20 ? color.gray: na)
if uptrend1
strategy.entry("Long", strategy.long,when = close[0] > high[hiBar-1] or open[0] > high[hiBar-1])
strategy.exit("exit long","Long", profit = 2400, loss = 1200)
if downtrend1
strategy.entry("Short", strategy.short)
strategy.exit("exit short", "Short", profit = 2800, loss = 1200)
还附上回测的图片
【问题讨论】:
-
这还不清楚:3) 再走很长时间,只会再次发生重新交叉……不是立即发生。能再解释一下吗?
-
我重新附上了一张带有一些解释的图片,请看一下,让我知道这是否足够,或者我也可以提供更多信息。 @PineCoders-LucF
标签: pine-script