简体   繁体   中英

Alert Condition/Consecutive Signal pinescript

I have this code where bars change color if they are above/below an EMA. I got the alert working. However, it alerts me on every single candle.

I would appreciate it if anyone could help me achieve the alert to be run only once.

Here is the code and please do feel free to post your more advanced version.

study(title="Bar Color", shorttitle="BColor", overlay=true)
src = close, len = input(20, minval=1, title="EMA")
p1= ema(src,len)
plot(p1)

ut   = close > p1 and close[1] > p1 
dt = close < p1 and close[1] < p1

uc = close > close[1] or high > high[1] and low > low[1]
dc = close < close[1] or high < high[1] and low < low[1]

barColour = (ut and uc) ? #53B987 :
    (ut and dc) ? #53B987 :
    (dt and dc) ? #EB4D5C :
    (dt and uc) ? #EB4D5C :
    na

barcolor(color=barColour)

alertcondition(ut, title="Buy Alert")
alertcondition(dt, title="Sell Alert")

Thank you

You can compare change the alert condition to check for current bar signal and previous bar signal. If previous bar signal is false and current bar signal is true then send the alert. Example below

alertcondition(ut and not ut[1], title="Buy Alert")
alertcondition(dt and not dt[1], title="Sell Alert")

为什么不使用警报菜单中的“仅一次”警报选项?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM