Pine Script语言语法

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

Pine Script language syntax

问题

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

  1. 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 将返回 NaNNaN 不是一个数字,因此在条件中运行它将返回 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.

huangapple
  • 本文由 发表于 2023年6月26日 02:29:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551875.html
匿名

发表评论

匿名网友

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

确定