英文:
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 > 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.
答案1
得分: 1
iff()
的设计如下:
iff(condition, result1, result2)
如果 condition
是 true
,它将返回 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 > 0)
if (val > nz(val[1]))
lime
else
green
else
if (val < nz(val[1]))
red
else
maroon
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论