如何在Pine脚本中使用VAR?
这是一个指标:
//box
boxp=input(5, "BOX LENGTH")
LL = lowest(low,boxp)
k1=highest(high,boxp)
k2=highest(high,boxp-1)
k3=highest(high,boxp-2)
NH = valuewhen(high>k1[1],high,0)
box1 =k3<k2
TopBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, NH, 0)
BottomBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, LL, 0)
我使用变量: var longStopPrice = bottombox [0],
但是当我绘制longStopprice时,无法显示该值。 谁能帮我吗?
This is an indicator:
//box
boxp=input(5, "BOX LENGTH")
LL = lowest(low,boxp)
k1=highest(high,boxp)
k2=highest(high,boxp-1)
k3=highest(high,boxp-2)
NH = valuewhen(high>k1[1],high,0)
box1 =k3<k2
TopBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, NH, 0)
BottomBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, LL, 0)
and I use variable:
var longstopprice = BottomBox[0]
but it isn't available to display the value when I plot longstopprice.
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
var
是用于分配变量和一次性初始化的关键字。当您执行
longStopPrice = bottombox [0]
时,它将初始化``longstoppricein
bottombox`在 in of of of of of of ''除非您明确地这样做,否则切勿更改其价值。它将采用
bottombox
几个bar以获取任何na
值,因为您正在使用gixes()
andbarssince()
> /代码>。
如果绘制
BottomBox
,您将看到它需要几个条,直到获得有效的数字值。var
is the keyword used for assigning and one-time initializing of the variable.When you do
longstopprice = BottomBox[0]
, it will initialize ´longstoppricewith the value of
BottomBox` on the very first bar and it will never change its value unless you explicitly do that.It will take
BottomBox
several bars to get any nonena
value because you are using functions likehighest()
andbarssince()
.If you plot
BottomBox
, you will see that it will take a few bars until it gets a valid number value.