如何在 pine 脚本中添加警报

发布于 2025-01-11 13:15:25 字数 1514 浏览 3 评论 0原文

我试图在标签出现在脚本中时添加警报。尝试去做,但没能成功。我不擅长编码,但尝试对其他代码进行一些更改。我为其他代码添加了警报条件,但这不起作用。可以添加警报吗? 谢谢。

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

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

发布评论

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

评论(1

森末i 2025-01-18 13:15:25

使用 alert() 而不是 alertcondition() 并将其放在标签出现在脚本中之后。

  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) 
            alert("BUY")
        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) 
            alert("SELL")
    

Use alert() instead of alertcondition() and put it right after when the label comes in the script.

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