繁体   English   中英

Pinescript 错误 - 交易视图指标 - 请问如何解决?

[英]Pinescript error- trading view indicator - how to fix it please?

我收到以下错误:编译错误。 第 27 行:输入“没有行继续的行尾”处的语法错误。知道这里出了什么问题吗?

//@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)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM