英文:
Pine Script language syntax
问题
if (float)
float = float ? float : float
float ph = ta.pivothigh(prd, prd)
float pl = ta.pivotlow(prd, prd)
float lastpp = ph ? ph : pl ? pl : na
if lastpp
...
英文:
I just start to learning Pine Script. And I cant find any information about this issue in language documentation or google. This code is working and I find it in someones indicator script.
I want to understand what this means:
-
if (float)
float = float ? float : float
float ph = ta.pivothigh(prd, prd)
float pl = ta.pivotlow(prd, prd)
float lastpp = ph ? ph : pl ? pl : na
if lastpp
...
答案1
得分: 1
?:
被称为三元运算符。
它的工作方式是,它会检查一个条件,如果条件为true
,则返回value1
,否则返回value2
。
condition ? value1: value2
你可以使用一个if
块来写出相同的检查,如下所示:
if (condition)
value1
else
value2
编辑:
如果没有枢轴,ta.pivothigh
将返回 NaN
。NaN
不是一个数字,因此在条件中运行它将返回 false
。
实质上,ph ?
检查的是是否存在枢轴高点。
英文:
?:
is called ternary operator.
The way it works is, it will check a condition and return value1
if the condition is true
and return value2
otherwise.
condition ? value1: value2
You can write the same check with an if
block as below:
if (condition)
value1
else
value2
Edit:
ta.pivothigh
will return NaN
if there is no pivot. NaN
is not a number so when you run it in a condition it will return false
.
Essentially, what ph ?
checks is to see if there is a pivot high or not.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论