Pinescript V5 错误:“时间范围”参数与具有副作用的函数不兼容

jwh*_*whi 2 pine-script pine-script-v5

我有一个脚本,我试图在 2 mA 与 line.new 交叉的地方绘制一个 X 我已经在另一个脚本中尝试了 line.new ,它似乎有效,所以我不知道为什么它不起作用这个脚本。我只是设置 y 但收到错误。

//@version=5
indicator(title="My MACD with crosses", shorttitle="My MACD", timeframe="", timeframe_gaps=true)

// Get User Input
i_showCross = input.bool(title="Show MA Crossovers", defval=true)

// Calculate MA's using user input selections
fast_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_fast_length) : ta.ema(i_src, i_fast_length)
slow_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_slow_length) : ta.ema(i_src, i_slow_length)

crossOver = ta.crossover(fast_ma, slow_ma)
crossUnder = ta.crossunder(slow_ma, fast_ma)

// show label
crossX = label.new(bar_index, na, str.tostring(fast_ma) + "crossed under " + str.tostring(slow_ma), style=label.style_xcross, size=size.small, color=color.red, textcolor=color.red)
    label.set_y(crossX,slow_ma)
Run Code Online (Sandbox Code Playgroud)

Bar*_*kut 6

仔细阅读错误消息。

“时间范围”参数与具有副作用的函数不兼容

争论timeframe是在你的indicator()电话中,所以你不应该在其他地方寻找。

如果您不需要更改时间范围,只需timeframe="", timeframe_gaps=trueindicator()通话中删除即可。

所以应该是:

indicator(title="My MACD with crosses", shorttitle="My MACD")
Run Code Online (Sandbox Code Playgroud)

如果您需要多时间范围分析,您应该使用security()函数。