我们可以只绘制 pine 脚本中的最新级别吗?

发布于 2025-01-12 04:52:11 字数 984 浏览 0 评论 0原文

此代码绘制了波动高点和波动低点水平。但这显示了两个级别(高级别和低级别)。我们可以在图表上仅显示最新水平吗? 示例:您在 10:15 处出现波动低点,在此低点处将绘制一条线,但是一旦出现新的波动高点(例如在 12:30),则在 10:15 绘制的旧水平应为隐藏并且仅应绘制新水平,即 12:30 的波动高水平。 我们可以这样做吗? 提前致谢。

//@version=5
indicator('Last Pivot', overlay=true)

left = 50
right = 25
quick_right = 2  // Used to try and detect a more recent significant swing.

pivot_high = ta.pivothigh(high, left, right)
pivot_lows = ta.pivotlow(low, left, right)

quick_pivot_high = ta.pivothigh(high, left, quick_right)
quick_pivot_lows = ta.pivotlow(low, left, quick_right)

lhigh = ta.valuewhen(quick_pivot_high, high[quick_right], 0)
llow = ta.valuewhen(quick_pivot_lows, low[quick_right], 0)




level1_col = close >= lhigh ? color.green : color.red
level2_col = close >= llow ? color.green : color.red

plot(lhigh, style=plot.style_line, color=level1_col, show_last=1, linewidth=3, trackprice=true)
plot(llow, style=plot.style_line, color=level2_col, show_last=1, linewidth=3, trackprice=true)

this code plots the swing high and swing low levels. But this show both the levels (high level and low level). Can we show only the latest level on the chart.?
Example: you got a swing low at 10:15 there will be a line drawn at this low, but once when there is a new swing high, lets say at 12:30, the old level which was drawn at 10:15 should be hidden and only the new level i.e 12:30's swing high level only should be plotted.
Can we do this?
Thanks in advance.

//@version=5
indicator('Last Pivot', overlay=true)

left = 50
right = 25
quick_right = 2  // Used to try and detect a more recent significant swing.

pivot_high = ta.pivothigh(high, left, right)
pivot_lows = ta.pivotlow(low, left, right)

quick_pivot_high = ta.pivothigh(high, left, quick_right)
quick_pivot_lows = ta.pivotlow(low, left, quick_right)

lhigh = ta.valuewhen(quick_pivot_high, high[quick_right], 0)
llow = ta.valuewhen(quick_pivot_lows, low[quick_right], 0)




level1_col = close >= lhigh ? color.green : color.red
level2_col = close >= llow ? color.green : color.red

plot(lhigh, style=plot.style_line, color=level1_col, show_last=1, linewidth=3, trackprice=true)
plot(llow, style=plot.style_line, color=level2_col, show_last=1, linewidth=3, trackprice=true)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

拥抱我好吗 2025-01-19 04:52:11

您不能使用 plot() 函数来做到这一点。但是,如果您使用 line() 函数,则可以使用 line.delete() 函数删除前一个。

下面的示例展示了如何使用标签来做到这一点。

//@version=4
study("Last Bar Close 1", overlay=true)

c = close >= open ? color.lime : color.red
l = label.new(bar_index, na,
  text=tostring(close), color=c,
  style=label.style_label_down, yloc=yloc.abovebar)

label.delete(l[1])

那么,你明白了吗?它会创建一个标签,但会删除旧的标签,因此您只有一个标签。

注意:不要一遍又一遍地创建和删除对象,建议使用修改 函数并将线条移动到新位置。这会带来更好的性能。

编辑:

line.new() 具有以下签名:

line.new(x1, y1, x2, y2, xloc, 扩展, 颜色, 样式, 宽度) → 系列
线

您可以向 y1y2 参数添加任何您想要的值,然后它将在 y 轴上移动该线。如果您的脚本是 overlay=true,它将绘制在主图表上。

You cannot do that with the plot() function. If, however, you use the line() function, you can delete the previous one with the line.delete() function.

Below example shows how to do that with a label.

//@version=4
study("Last Bar Close 1", overlay=true)

c = close >= open ? color.lime : color.red
l = label.new(bar_index, na,
  text=tostring(close), color=c,
  style=label.style_label_down, yloc=yloc.abovebar)

label.delete(l[1])

enter image description here

So, you see? It creates a label but deletes the old one so you only have one label.

Note: Instead of creating and deleting the objects over and over again, it is recommended to use the modifying functions and just move the line to a new location. This results in better performance.

Edit:

line.new() has the following signature:

line.new(x1, y1, x2, y2, xloc, extend, color, style, width) → series
line

You can add whatever value you want to the y1 or y2 arguments then it will move the line on the y-axis. If your script's overlay=true, it will be drawn on the main chart.

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