如何在Pine脚本中使用VAR?

发布于 2025-02-10 03:41:08 字数 452 浏览 0 评论 0原文

这是一个指标:

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网白 2025-02-17 03:41:08

var是用于分配变量和一次性初始化的关键字。

当您执行longStopPrice = bottombox [0]时,它将初始化``longstopprice in bottombox`在 in of of of of of of ''除非您明确地这样做,否则切勿更改其价值。

它将采用bottombox几个bar以获取任何na值,因为您正在使用gixes() and barssince()> /代码>。

如果绘制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 ofBottomBox` 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 none na value because you are using functions like highest() and barssince().

If you plot BottomBox, you will see that it will take a few bars until it gets a valid number value.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文