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
...
?:
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
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.