【问题标题】:Pinescript - function should be called on each calculationPinescript - 每次计算都应该调用函数
【发布时间】:2021-05-14 10:54:17
【问题描述】:

我收到此错误 第 5 行:应在每次计算时调用函数 'sma' 以保持一致性。建议从三元运算符或作用域中提取调用。

我正在尝试找出原因,但无法解决。这是我想要调整的交易视图的内置指标,但我什至还没开始就被卡住了。脚本有效,但我希望它没有建议

//@version=4
study(title="Williams Alligator", shorttitle="Alligator", overlay=true, resolution="")
smma(src, length) =>
    smma =  0.0
    smma := na(smma[1]) ? sma(src, length) : (smma[1] * (length - 1) + src) / length
    smma
jawLength = input(13, minval=1, title="Jaw Length")
teethLength = input(8, minval=1, title="Teeth Length")
lipsLength = input(5, minval=1, title="Lips Length")
jawOffset = input(8, title="Jaw Offset")
teethOffset = input(5, title="Teeth Offset")
lipsOffset = input(3, title="Lips Offset")
jaw = smma(hl2, jawLength)
teeth = smma(hl2, teethLength)
lips = smma(hl2, lipsLength)
plot(jaw, "Jaw", offset = jawOffset, color=#3BB3E4)
plot(teeth, "Teeth", offset = teethOffset, color=#FF006E)
plot(lips, "Lips", offset = lipsOffset, color=#36C711)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    我想通了 我在条件行之前插入了一行并声明了 smma 值 'sma(src, length)' 而不是 '0' 获得完全相同的结果而不会出错

    smma(src, length) =>
        smma = sma(src, length) 
        smma := na(smma[1]) ? smma : (smma[1] * (length - 1) + src) / length
        smma
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 2010-10-23
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多