I’m working on a Pine Script indicator in TradingView that needs to trigger alerts based on the close of 15-minute bars, even though my chart is set to a 30-minute timeframe. I’m encountering issues with the alert configuration. i set an alert for once-per-bar but it triggers as soon as i create the alert. Here is the relevant part of my Pine Script code:
// Define the timeframe to monitor (15-minute in this case)
timeframe_to_check = "15"
// Get the close price from the 15-minute timeframe
close_15m = request.security(syminfo.tickerid, timeframe_to_check, close)
// Reset stop_triggered at the start of a new 15-minute bar
var bool stop_triggered = false
if (close_15m < sl_price) and open_position
stop_triggered := true
else
stop_triggered := false
// Alert condition for stop-loss hit
alert_if_price_hit_stop = stop_triggered and open_position
alertcondition(alert_if_price_hit_stop, title="Stop Loss Hit", message="The stop loss level has been hit in {{ticker}}")
I tried setting up the alert in TradingView with the “Once per bar close” option, but it triggers based on the 30-minute bar close, not the 15-minute bar close as intended. I also considered using “Once per minute,” but I’m not sure if this is the correct approach to ensure accurate 15-minute bar close detection while avoiding unnecessary alerts.
I expected the alert to trigger based on the close of the 15-minute bars, even though my chart is set to a 30-minute timeframe. The goal is to accurately detect and respond to the 15-minute bar closes within the higher timeframe chart.
Osi_Bad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.