0

Why does it trigger multiple times after the alert conditions have been met for the alertcondition(confirmed_signal, title="Price crosses upper range with confirmation", message="Price has crossed the upper range with confirmation") ?

I am using the lower_range_confirmed as confirmation for the alert when it cross upper range so that if lower range is my exit the alert would need to go back to exit and confirm before a second short trigger.

var lower_range_confirmed = false

if close < offset1

    lower_range_confirmed := true

//alert condition for the second VWAP (upper range) with confirmation

price2 = close

confirmed_signal = price2 > offset2 and lower_range_confirmed

alertcondition(confirmed_signal, title="Price crosses upper range with confirmation", message="Price has crossed the upper range with confirmation")

// Reset the confirmation flag after the lower range trigger

if confirmed_signal

    lower_range_confirmed := false

3 Answers3

0

Anytime close < offset1 is true, you reset your flag. This could happen multiple times during a bar's lifetime.

You can add barstate.isconfirmed to your condition to make it non-repaint. With that, it will only execute your alert when the bar is closed (last update).

vitruvius
  • 15,740
  • 3
  • 16
  • 26
0
if confirmed_signal
    alert('your message here', alert.freq_once_per_bar_close)
  • Yes you can use alert.freq_once_per_bar, but you will receive alert at the first time of your condition at the bar, but when the bar close your condition may change and it might be changed many times per bar, I recommend to use alert.freq_once_per_bar_close, it's more reliable and more correct. I always use and check all conditions in my scripts at closed bars. – Novelty Trade Jul 31 '23 at 11:20
  • thank you soo much ❤️ i have been at this for like 4 day i thougth it was impossible and couldnt be implemented in pinescript it now works thanks once more – Fred Ratty Aug 01 '23 at 03:10
0

incase anybody also needs an answer the answer is acturally use varip instead of var

also change from alertcondition to this type

if confirmed_signal
    alert('your message here', alert.freq_all)