I’m struggling to write a script for tradingview in pine editor that triggers an alert when the all-time high (ATH) drops below a certain percentage, for example, 1%. Unfortunately, it gives me no alarm.
//@version=5
indicator("ATH - 1% Alarm", overlay=true)
ath = ta.highest(high, 5000) // Calculates the ATH over the last 5000 candles
alert_level = ath * 0.99 // 1% below ATH (should be 20% in my case)
plot(alert_level, title="Alarm-Level", color=color.red, style=plot.style_stepline)
alertcondition(close < alert_level, title="ATH -1%", message="Price is 1% below ATH!")
plot(close)
I’m struggling to write a script for tradingview in pine editor that triggers an alert when the all-time high (ATH) drops below a certain percentage, for example, 1%. Unfortunately, it gives me no alarm.
//@version=5
indicator("ATH - 1% Alarm", overlay=true)
ath = ta.highest(high, 5000) // Calculates the ATH over the last 5000 candles
alert_level = ath * 0.99 // 1% below ATH (should be 20% in my case)
plot(alert_level, title="Alarm-Level", color=color.red, style=plot.style_stepline)
alertcondition(close < alert_level, title="ATH -1%", message="Price is 1% below ATH!")
plot(close)
Share
Improve this question
asked Feb 14 at 14:34
BullzBullz
1
1 Answer
Reset to default 0For debug, plotchar you alertcondition
plotchar(close < alert_level)
Your script sends multiple alerts
To send a single alert, try this:
//@version=5
indicator("ATH - 1% Alarm", overlay=true)
ath = ta.highest(high, 5000) // Calculates the ATH over the last 5000 candles
alert_level = ath * 0.99 // 1% below ATH (should be 20% in my case)
plot(alert_level, title="Alarm-Level", color=color.red, style=plot.style_stepline)
alertcondition(close < alert_level and close[1] > alert_level, title="ATH -1%", message="Price is 1% below ATH!")
plotchar(close < alert_level and close[1] > alert_level)