0

I have a condition on higher timeframe when the alert must be triggered and it works fine, but this condition may last for hours and I have the alert on a smaller timeframe, so I keep getting the same alert many many times in a row.

I created a boolean variable (trigger) to change it from True to False once the alert is triggered in order to make sure that I get the alert only once. This trigger will only reset back to True after the next condition happens.

It totally makes sense, right? At least for me :-) However if I add this additional trigger condition it just stops firing alerts at all and I have no idea why it's happening.

Can someone please explain what am I doing wrong here?

var bool Trigger = true // adding the Trigger as true by default

if LongSignal and Trigger // when LongSignal happens and Trigger is still set to true
    alert("Long Signal", alert.freq_once_per_bar_close)
    Trigger := false // Switch Trigger to false

The code above is enough to make the alerts stop working, I guess no need to paste the code how I was going to switch the Trigger back, but anyway it would be like this:

if ExitLongSignal and not Trigger // when ExitLongSignal happens and Trigger is set to false
    alert("Exit Long Signal", alert.freq_once_per_bar_close)
    Trigger := true // Switch Trigger back to true

I really need help with this :-( I've seen some solutions with "barssince" but I didn't understand how and why that works and I first need to understand what's wrong with this straightforward method which I'm trying to apply. Thank you!

vitruvius
  • 15,740
  • 3
  • 16
  • 26
Piner1337
  • 1
  • 1

1 Answers1

0

Adding

and ta.barssince(LongSignal)[1]

seems to stop multiple alerts and no Trigger variable is required at all

If LongSignal and ta.barssince(LongSignal)[1]

I hope I won't run into other issues with this when I start creating Exit LongSignal alerts...

Piner1337
  • 1
  • 1