Pinescript错误-交易视图指标-如何修复它请?



我得到以下错误:第27行:输入' Line end of Line without Line continuation'时出现语法错误,知道是哪里出了问题吗?

//@version=5
strategy("Consecutive", overlay=true)
// Define variables for the MACD and signal line
macd = macd(close, 12, 26)
signal = sma(macd, 9)
// Define a variable to keep track of the number of consecutive green candles
greenCandleCount = 0
// Loop through each bar in the chart
for i = 1 to bar_count - 1
// If the current bar is green, increment the green candle count
if close[i] > open[i]
greenCandleCount := greenCandleCount + 1
else
greenCandleCount := 0
plot(na)
end
// If we have 3 consecutive green candles and the MACD crosses down, plot the "LONG" message
if greenCandleCount == 3 and macd[i] < signal[i] and macd[i+1] > signal[i+1]
plot(high, "LONG", color=green, linewidth=2)
else
plot(na)
end 
end

要在图表上绘制指标,它不能编译。

不能在本地循环中使用plot()。我也不认为你需要一个for循环。

如果你想检查是否有3个连续的绿色蜡烛,如果MACD向下交叉,你可以这样做:

is_green = close > open
is_macd_cross = ta.crossunder(macd, signal)
barssince_macd_cross = ta.barssince(is_macd_cross)
is_green_cnt = math.sum(is_green, 3) // Count the number of green bars in the last 3 candles
is_cond = (is_green_cnt ==3) and (barssince_macd_cross > 0) and (barssince_macd_cross <= 3)
plot(is_cond ? high : na, "LONG", color.green, 2)

还没有测试过,只是想给你一个想法。

相关内容

最新更新