将多个 V1 函数转换为 V5(Tradingview – Pine Script)。

huangapple go评论82阅读模式
英文:

Converting multiple iff V1 Function to V5 (Tradingview - Pine Script)

问题

I tried to convert pine v1 iff function to v3 (and afterwards convert it automatically to V5) but I kept getting this error:

extraneous input 'if' expecting 'end of line without line continuation'

This is the V1 code

bcolor = iff( val > 0, 
            iff( val > nz(val[1]), lime, green),
            iff( val < nz(val[1]), red, maroon))

This is what I tried to convert it to V3

bcolor = if (val > 0) and (val > nz(val[1]))
    lime
else if
    (val < 0) and (val > nz(val[1]))
    green
else if
    (val > 0) and (val < nz(val[1]))
    red
else
    maroon

Does this even make sense in a logical way? Im not quite sure if I did it correctly so that the result is the same like in the iff function.

英文:

I tried to convert pine v1 iff function to v3 (and afterwards convert it automatically to V5) but I kept getting this error:

> extraneous input 'if' expecting 'end of line without line continuation'

This is the V1 code


bcolor = iff( val &gt; 0, 
            iff( val &gt; nz(val[1]), lime, green),
            iff( val &lt; nz(val[1]), red, maroon))

This is what I tried to convert it to V3


bcolor = if (val &gt; 0) and (val &gt; nz(val[1]))
    lime
else if
    (val &lt; 0) and (val &gt; nz(val[1]))
    green
else if
    (val &gt; 0) and (val &lt; nz(val[1]))
    red
else
    maroon

Does this even make sense in a logical way? Im not quite sure if I did it correctly so that the result is the same like in the iff function.

答案1

得分: 1

iff() 的设计如下:

iff(condition, result1, result2)

如果 conditiontrue,它将返回 result1。否则,它将返回 result2

将该代码块正确转换为:

bcolor = if (val > 0)
    if (val > nz(val[1]))
        lime
    else
        green
else
    if (val < nz(val[1]))
        red
    else
        maroon
英文:

iff() designed this way:

iff(condition, result1, result2)

If condition is true, it will return result1. Else, it will return result2.

The correct way of converting that block would be:

bcolor = if (val &gt; 0)
    if (val &gt; nz(val[1]))
        lime
    else
        green
else
    if (val &lt; nz(val[1]))
        red
    else
        maroon

huangapple
  • 本文由 发表于 2023年6月13日 00:04:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定