*已解决* Pine 脚本输入不匹配,预计 'end of line without line continuation'

*Resolved* Pine Script mismatched input, expecting 'end of line without line continuation'

我正在尝试用 pine 脚本编写交易策略。我的代码在第 100 行有一个小问题:

第 100 行:输入不匹配 'strategy.entry' 期望 'end of line without line continuation'

我试着自己搜索,但一无所获,这就是我在这里问的原因。顺便说一下,我现在是 pine 脚本的第 4 版。


buytrend = 0

if supertrend == 1 and supertrend2 == 1
    buytrend = 1
else if supertrend3 == 1 and supertrend == 1
    buytrend = 1
if supertrend2 == 1 and supertrend3 == 1
    buytrend = 1

if supertrend == -1 and supertrend2 == -1
    buytrend = 0
else if supertrend3 == -1 and supertrend == -1
    buytrend = 0
if supertrend2 == -1 and supertrend3 == -1
    buytrend = 0


//plot marketprice

marketprice = ema(close,1)
plot(marketprice,"Marketprice",color.yellow)

//signals

Buysignal = crossover(k, d) and k < 20 and marketprice > ema and buytrend == 1
Sellsignal = crossunder(k, d)
Sellsignal2 = if buytrend == 0

//strategy

strategy.entry("Trade",strategy.long,when = Buysignal)
strategy.close("Trade",when = Sellsignal)
strategy.exit("Trade",when = Sellsignal2) ```

Sellsignal2 = if buytrend == 0

这是一个未完成的陈述。你的问题就在那里。

vitruvius 的回答是正确的,但具体来说,如果您尝试将 Sellsignal2 设置为等于 TrueFalse,那么您不需要 if

只需将 buytrend == 0 的计算结果赋值给它,如:

Sellsignal2 = buytrend == 0