我们可以只绘制 pine 脚本中的最新级别吗?
此代码绘制了波动高点和波动低点水平。但这显示了两个级别(高级别和低级别)。我们可以在图表上仅显示最新水平吗? 示例:您在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
plot()
函数来做到这一点。但是,如果您使用line()
函数,则可以使用line.delete()
函数删除前一个。下面的示例展示了如何使用
标签
来做到这一点。那么,你明白了吗?它会创建一个标签,但会删除旧的标签,因此您只有一个标签。
注意:不要一遍又一遍地创建和删除对象,建议使用修改 函数并将线条移动到新位置。这会带来更好的性能。
编辑:
line.new()
具有以下签名:您可以向
y1
或y2
参数添加任何您想要的值,然后它将在 y 轴上移动该线。如果您的脚本是overlay=true
,它将绘制在主图表上。You cannot do that with the
plot()
function. If, however, you use theline()
function, you can delete the previous one with theline.delete()
function.Below example shows how to do that with a
label
.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:You can add whatever value you want to the
y1
ory2
arguments then it will move the line on the y-axis. If your script'soverlay=true
, it will be drawn on the main chart.