【问题标题】:Pine script if else ifPine 脚本 if else if
【发布时间】:2021-04-15 00:58:08
【问题描述】:

我是 Pine 的新手,如果要处理选择输入,则无法获得以下内容

// Backtest
entrySource = input(title="Enter On", defval = "Buy Big Green", options=["Buy Small Green", "Buy Big Green", "Buy Big Green Div"])
exitSource = input(title="Exit On", defval = "Sell Big Red", options=["Sell Small Red", "Sell Big Red", "Sell Big Red Div"])

entry = if entrySource == "Buy Small Green"
            wtCross and wtCrossUp
        else if entrySource == "Buy Big Green"
            entry = buySignal
        else if entrySource == "Sell Small Red"
            entry = buySignalDiv
        else
            na
    
exit = if exitSource == "Buy Small Green"
            wtCross and wtCrossDown
        else if entrySource == "Sell Big Red"
            buySignal
        else if entrySource == "Sell Small Red"
            buySignalDiv
        else
            na

我得到了经典的 line 489: Mismatched input 'wtCross' expecting 'end of line without line continuation'. 错误,但我不知道为什么。

【问题讨论】:

标签: if-statement pine-script trading


【解决方案1】:

您在格式化 if else if 表达式时犯了一个小错误,请尝试删除如下所示的缩进:

//@version=4
study("Backtest", overlay=true)
entrySource = input(title="Enter On", defval = "Buy Big Green", options=["Buy Small Green", "Buy Big Green", "Buy Big Green Div"])
exitSource = input(title="Exit On", defval = "Sell Big Red", options=["Sell Small Red", "Sell Big Red", "Sell Big Red Div"])
wtCross = true, wtCrossUp = true, wtCrossDown = true, buySignal = true, buySignalDiv = true

entry = if entrySource == "Buy Small Green"
    wtCross and wtCrossUp
else if entrySource == "Buy Big Green"
    buySignal
else if entrySource == "Sell Small Red"
    buySignalDiv
else
    na
    
exit = if exitSource == "Buy Small Green"
    wtCross and wtCrossDown
else if entrySource == "Sell Big Red"
    buySignal
else if entrySource == "Sell Small Red"
    buySignalDiv
else
    na
plot(entry ? 1 : 0)
plot(exit ? 1 : 0)

【讨论】:

  • 啊,太棒了,谢谢!我仍然对这种格式感到困惑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 2017-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多