I'm working on the multi price triggered alert script, but the script has the error.
I'm doing the alert for the stop-loss triggered and 3 take profit triggered. Once the first take-profit is triggered, and no alert for stop-loss. Here is the script.
if strategy.position_size>0 and strategy.opentrades>0
sl_alert_price := strategy.opentrades.entry_price(0)-ta.atr(1)*1
tp1_alert_price := strategy.opentrades.entry_price(0)+ta.atr(1)*1
tp2_alert_price := strategy.opentrades.entry_price(0)+ta.atr(1)*2
tp3_alert_price := strategy.opentrades.entry_price(0)+ta.atr(1)*3
if strategy.position_size<0 and strategy.opentrades>0
sl_alert_price := strategy.opentrades.entry_price(0)+ta.atr(1)*1
tp1_alert_price := strategy.opentrades.entry_price(0)-ta.atr(1)*1
tp2_alert_price := strategy.opentrades.entry_price(0)-ta.atr(1)*2
tp3_alert_price := strategy.opentrades.entry_price(0)-ta.atr(1)*3
if longcond or shortcond or long_alert_test
isAlertTriggered_sl1_cond := false
isAlertTriggered_tp1_cond := false
isAlertTriggered_tp2_cond := false
isAlertTriggered_tp3_cond := false
if isAlertTriggered_sl1_cond==false and ta.cross(close,sl_alert_price)
alert(message= syminfo.ticker + " : SL")
isAlertTriggered_sl1_cond := true
isAlertTriggered_tp1_cond := true
isAlertTriggered_tp2_cond := true
isAlertTriggered_tp3_cond := true
if isAlertTriggered_tp1_cond==false and ta.cross(close,tp1_alert_price)
alert(message= syminfo.ticker + " : TP1")
isAlertTriggered_sl1_cond := true
isAlertTriggered_tp1_cond := true
isAlertTriggered_tp2_cond := false
isAlertTriggered_tp3_cond := false
if isAlertTriggered_tp2_cond==false and ta.cross(close,tp2_alert_price)
alert(message= syminfo.ticker + " : TP2")
isAlertTriggered_sl1_cond := true
isAlertTriggered_tp1_cond := true
isAlertTriggered_tp2_cond := true
isAlertTriggered_tp3_cond := false
if isAlertTriggered_tp3_cond==false and ta.cross(close,tp3_alert_price)
alert(message= syminfo.ticker + " : TP3")
isAlertTriggered_sl1_cond := true
isAlertTriggered_tp1_cond := true
isAlertTriggered_tp2_cond := true
isAlertTriggered_tp3_cond := true
When I use this, the alert is not generated as the rules. Sometimes TP Alert still triggered after the SL is hit. Can anyone please revise the script ? Sincerely big thanks