[英]Trading View Pine Script : How to Draw a Simple Line Using line.new function from market open to market close?
[英]How to create alert for line.new function in Pine Script?
我在 TradingView 中创建了一个 pine 脚本来绘制从 pivot 到 pivot 的线,就像一条有斜率但不是水平的趋势线。 现在我想为这些线添加警报,以便当价格越过最后一条线时我可以获得警报。 这是示例代码:
line upper = line.new(x1, y1, x2, y2, extend=extend.right, color=color1, width=width1)
line lower = line.new(x1, y1, x2, y2, extend=extend.right, color=color2, width=width1)
那么如何向这一行添加警报呢?
您可以使用line.get_*()
function 获取线的值。如果您希望获取特定柱的线价格值,您需要获取使用line.get_y2()
function 计算的y2
值.
这是一个示例代码:
//@version=5
indicator("My script", overlay=true)
upperY = high[1] * 1.01
lowerY = low[1] * 0.99
line upper = line.new(bar_index - 1, upperY[1], bar_index, upperY)
line lower = line.new(bar_index - 1, lowerY[1], bar_index, lowerY)
upperYvalue = line.get_y2(upper)
lowerYvalue = line.get_y2(lower)
if ta.crossover(close, upperYvalue)
label.new(x=bar_index, y=high * 1.07, text=str.tostring(upperYvalue), color=color.green)
if ta.crossunder(close, lowerYvalue)
label.new(x=bar_index, y=low * 0.93, text=str.tostring(upperYvalue), color=color.red, style=label.style_label_up)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.