Pinescript 初始化 [英] Pinescript initialisation

查看:80
本文介绍了Pinescript 初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解以下 pinescript 指标代码 - https://www.tradingview.com/script/XzcIRUHv-JMA-RSX-Clone-LazyBear/

I am trying to understand the following pinescript indicator code - https://www.tradingview.com/script/XzcIRUHv-JMA-RSX-Clone-LazyBear/

我不确定 f90、f88 等变量的值是什么.它们是其他东西的预定义捷径吗?它们似乎是数组,因为它们与索引一起使用.例如:

I am not sure what values variables like f90, f88 hold. Are they predefined short-cuts for something else? They seem to be arrays because they are used with index. E.g.:

f90_ = (nz(f90_[1]) == 0.0) ? 1.0 : (nz(f88[1]) <= nz(f90_[1])) ? nz(f88[1])+1 : nz(f90_[1])+1

推荐答案

它们不是内置变量.

pine-script 版本 1 和 2 允许您使用 [] 结合 nz() 即使变量尚未声明.因此,以下内容在 version 1version 2 中有效:

pine-script versions 1 and 2 allow you to access variables with [] in combination with nz() even though the variable is not yet declared. So, the following is valid in version 1 and version 2:

f90_ = (nz(f90_[1]) == 0.0) ? 1.0 : (nz(f88[1]) <= nz(f90_[1])) ? nz(f88[1])+1 : nz(f90_[1])+1

如果您在 //@version=3 中尝试此操作,您将收到 Undeclared identifier 错误.

If you try this in //@version=3, you will get an Undeclared identifier error.

让我们将代码缩短为以下内容:

Let's shorten the code to the following:

//@version=2
study(title="JMA RSX Clone [LazyBear]", shorttitle="RSXC_LB", overlay=false)
length=input(14)

f90_ = (nz(f90_[1]) == 0.0) ? 1.0 : (nz(f88[1]) <= nz(f90_[1])) ? nz(f88[1])+1 : nz(f90_[1])+1
f88 = (nz(f90_[1]) == 0.0) and (length-1 >= 5) ? length-1.0 : 5.0 
plot(f90_, title="f90", color=orange, linewidth=4)
plot(f88, title="f88", color=red, linewidth=4)

让我们看看 f90_f88 对于第一个小节会发生什么.

Let's look at what happens to f90_ and f88 for the very first bar.

f90_ = (nz(f90_[1]) == 0.0) ? 1.0 : (nz(f88[1]) <= nz(f90_[1])) ? nz(f88[1])+1 : nz(f90_[1])+1

这里的条件是(nz(f90_[1]) == 0.0).f90_[1] 基本上是询问前一个柱的值,但这是第一个柱(还记得吗?),所以没有前一个值.所以,答案是 NaN(不是数字).

The condition here is (nz(f90_[1]) == 0.0). f90_[1] is basically asking the value of one previous bar, but this is the first bar (remember?), so there is no previous value. So, the answer is NaN (Not A Number).

现在,如果你把它放在 nz() 中,它将返回 .因为 nz()zeros 替换了 NaN 值.

Now, if you put this in nz(), it will return zero. Because nz() replaces NaN values with zeros.

所以第一个条形的条件为真,并且 f90_ 将被分配给 1.0.

So the condition will be true for the first bar, and f90_ will be assigned to 1.0.

现在让我们看看 f88,再次查看 第一个栏.

Let's look at f88 now, again for the very first bar.

f88 = (nz(f90_[1]) == 0.0) and (length-1 >= 5) ? length-1.0 : 5.0 

这里的第一个条件是(nz(f90_[1]) == 0.0).由于上述相同的原因,这应该返回 true.

The first condition here is (nz(f90_[1]) == 0.0). This should return true, because of the same reason above.

第二个条件是(length-1 >= 5).对于默认输入 (14),这也应该返回 true.

The second condition is (length-1 >= 5). This should also return true for the default input (14).

因此,对于第一小节,f88 将被分配给 14-1 = 13.

So, f88 will be assigned to 14-1 = 13 for the first bar.

我认为您可以从这里继续.尝试运行我提供的短代码并查看图表.

I think you can continue from here on. Try to run the short code I provided and see the chart.

这篇关于Pinescript 初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆