【问题标题】:Pine script trade, can't get If else statement workingPine 脚本交易,无法使用 If else 语句
【发布时间】:2020-05-03 05:46:49
【问题描述】:

我有一个可以正常工作的下拉选项,但不知道如何获取 If else 声明工作。为所有这些都尝试了如果,那么如果没有,则没有任何效果。否则(typ4 == rma)

Pine 给出以下错误,任何帮助都非常感激 不匹配的输入“wma”期望“行尾没有续行”。

//@version=4
strategy("Testing", overlay=true)
showSMA2 = input(title="Toggle WMA/RMA/VWMA/VWAP/HullMA", type=input.bool, defval=true)
typ4 = input(title="Choice", defval="WMA", options=["WMA", "RMA", "VWMA", "VWAP", "HullMA"])
len4 = input(9, minval=1, maxval=8, title="Length")
src4 = input(title="Source OHLC", type=input.source, defval=close)

out =   if (typ4 == wma)
            wma(src4, len4)
        if typ4 == rma
            rma(src4, len4)

        if (typ4 == vwma)
            vwma(src4, len4)
        if (typ4 == vwap)
            vwap(src4, len4)

        if (typ4 == hullma)
            hullma(src4, len4)

plot(out, title="Custom", color=iff(showSMA2, color.green, na))

下面也试过了,行尾错误out4 不匹配的输入“WMA1”期望“行尾没有续行”。

WMA1 = wma(src4, len4)
RMA1 = rma(src4, len4)
VWMA1 = vwma(src4, len4)
VWAP1 = vwap(src4, len4)
HullMA = wma(src4, len4)

out4 = if (typ4 == WMA) WMA1
     if (typ4 == RMA) RMA1
     if (typ4 == VWMA) VWMA1
     if (typ4 == VWAP) VWAP1
     if (typ4 == HullMA) HullMA1

【问题讨论】:

    标签: if-statement pine-script


    【解决方案1】:

    解决了,我应该更好地阅读文档以了解下拉输入要求,而不是假设它会如何,思考的坏习惯

    //@version=4
    strategy("Testing", overlay=true)
    type1 = input(title="Choice", defval="WMA", options=["WMA", "RMA", "VWMA"])
    len4 = input(9, minval=1, maxval=50, title="Length")
    src4 = input(title="Source OHLC", type=input.source, defval=close)
    plot(type1 == "WMA" ? wma(src4,len4) : type1 == "RMA" ? rma(src4,len4) : na)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多