如何在 pine 脚本中添加警报
我试图在标签出现在脚本中时添加警报。尝试去做,但没能成功。我不擅长编码,但尝试对其他代码进行一些更改。我为其他代码添加了警报条件,但这不起作用。可以添加警报吗? 谢谢。
//@version=4
study("BDW",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0)
if barstate.isfirst
for i = 0 to 499
array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
for i = 0 to min(499,n-1)
sum = 0.
sumw = 0.
for j = 0 to min(499,n-1)
w = exp(-(pow(i-j,2)/(h*h*2)))
sum += src[j]*w
sumw += w
y2 := sum/sumw
d = y2 - y1
l := array.get(ln,i)
line.set_xy1(l,n-i+1,y1)
line.set_xy2(l,n-i,y2)
line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
line.set_width(l,2)
if d > 0 and y1_d < 0
label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_circle,textcolor=#39ff14,textalign=text.align_center)
if d < 0 and y1_d > 0
label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_circle,textcolor=#ff1100,textalign=text.align_center)
y1 := y2
y1_d := d
crossOverAlert =if d > 0 and y1_d < 0
alertcondition(condition=crossOverAlert,title="BUY", message="BUY")
crossUnderAlert = if d < 0 and y1_d > 0
alertcondition(condition=crossUnderAlert,title="SELL", message="SELL")
I was trying to add alerts when the label comes in the script. Tried to do it, but was not able to make it out. I am not pro in coding but tried to make some change seeing other code. I added the alert condition for an other code but this was not working. Can the alerts be added to this.?
Thank you.
//@version=4
study("BDW",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0)
if barstate.isfirst
for i = 0 to 499
array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
for i = 0 to min(499,n-1)
sum = 0.
sumw = 0.
for j = 0 to min(499,n-1)
w = exp(-(pow(i-j,2)/(h*h*2)))
sum += src[j]*w
sumw += w
y2 := sum/sumw
d = y2 - y1
l := array.get(ln,i)
line.set_xy1(l,n-i+1,y1)
line.set_xy2(l,n-i,y2)
line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
line.set_width(l,2)
if d > 0 and y1_d < 0
label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_circle,textcolor=#39ff14,textalign=text.align_center)
if d < 0 and y1_d > 0
label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_circle,textcolor=#ff1100,textalign=text.align_center)
y1 := y2
y1_d := d
crossOverAlert =if d > 0 and y1_d < 0
alertcondition(condition=crossOverAlert,title="BUY", message="BUY")
crossUnderAlert = if d < 0 and y1_d > 0
alertcondition(condition=crossUnderAlert,title="SELL", message="SELL")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
alert()
而不是alertcondition()
并将其放在标签出现在脚本中之后。Use
alert()
instead ofalertcondition()
and put it right after when the label comes in the script.