我无法调试错误消息。请帮忙,非常感谢。
以前,我使用ivothigh()和valuewhen()进行编码,可以完美地工作,但是在设置警报时收到警告消息。
因此,我使用Dif [2]> Dif [1]和Dif [2]> Dif等等来替换axishigh()。
但是它可以被编译但是不能正常工作,并且表明引用了太多蜡烛。
//@version=4
maxbarsback=1000
study(title="MACD v3",max_bars_back=maxbarsback)
dh1=0.0,dh2=0.0,dh3=0.0,dph1=0,dph2=0,dph3=0
var line ll=na
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
dif = ema(close,9)-ema(close,26)
signal = ema(dif, 9)
hist = dif - signal
condition1=dif[2]>dif[1] and dif[2]>dif and dif[2]>dif[3] and dif[2]>dif[4]
if condition1
dh3:=dh2[1]
dh2:=dh1[1]
dh1:=dif[2]
dph3:=dph2[1]
dph2:=dph1[1]
dph1:=bar_index-2
condition2=dph3!=0 and dh2>=dh1 and high[bar_index-dph1]>high[bar_index-dph2]
if condition2 and not condition2[1]
ll:=line.new(dph2,dif[bar_index-dph2],dph1,dif[bar_index-dph1],extend=extend.none,color=color.red,width=2,style=line.style_dotted)
plotshape(title='+DC', series=condition2 and not condition2[1] ?dif[2] : na, text='+DC', style=shape.labeldown, location=location.absolute, color=color.maroon, textcolor=color.white,offset=-2)
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
plot(dif, title="DIF", color=color.white, transp=0)
plot(signal, title="MACD", color=color.gray, transp=0)
答案 0 :(得分:0)
我今天遇到并解决了同样的错误,所以我会解释一下。
Tradingview 对您可以参考的柱线数量有限制,这通常不是问题,因为它处理摆脱历史柱线,并且只计算可用的柱线。但是,使用基于 bar_index
的值很容易与此行为相矛盾。在这种情况下,似乎是通过将 bar_index 传递给一个变量,然后继续将其传递给其他变量。您可以这样做,但如果当前 bar_index 和用于引用的 bar_index 之间的差异大于可用的柱线数量,您将收到此错误。
在我的场景中,我在数组中收集 bar_index
以在它们之间绘制线条,并绘制更多线条连接这些线条。随着程序的进行,有时会出现条形数量超过可用数量的情况。
解决方案相对简单,任何依赖于最初使用 bar_index
作为其源的变量的计算都应该在 if 语句中使用。在我的代码中做
if bar_index - storedBarIndex < 5000
// Do something that depends on the storedBarIndex to set or access a value
我不记得一般有多少条可用,而且可能因帐户而异。