Indicator alerts again when Timeframe is changed

 

Hi, 

so as I wrote in the title, I coded an Indicator that gives me an alert when the last candle crossed the 21 Ema. I also check, if the alert was allready send on that candle by saving and then checking the value Time[0].
Now when I get an alert and change the timeframe on that chart, I get the same alert again. I guess thats because the Indicator gets loaded again.

does anyone know how to stop the indicator from sending the alert again, when i change the timeframe?

 
  1. You change TF and still get a cross? You should only be looking at bar 2/1 for the alert. Fix your broken code.
  2. Don't alert on first run (prev_calculated is zero.)
  3. Or use persistent storage such as Global Variables of the Terminal to restore your static variable on init.
 
whroeder1:
  1. You change TF and still get a cross? You should only be looking at bar 2/1 for the alert. Fix your broken code.
  2. Don't alert on first run (prev_calculated is zero.)
  3. Or use persistent storage such as Global Variables of the Terminal to restore your static variable on init.

I'm only looking at bar 2/1 for the alert.

oh and forgot to tell I'm on mql4.

can you explain what you mean with prev_calculated is zero?

I tried to save it in a library cause I found that here somewhere but that doesnt work either

 

Bockwurst14:

oh and forgot to tell I'm on mql4.

can you explain what you mean with prev_calculated is zero?
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. How do you decide what bars to compute? You should stop using the old IndicatorCounted and start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference
 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. How do you decide what bars to compute? You should stop using the old IndicatorCounted and start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference

Completly forgot to check :D

I just had an idea, that the problem might be that I use Time[0] to check if the alert was allready sent for the current bar.
Because if I switch the timeframe, Time[0] contains the opening Time of a bar of a different timeframe right?

So how can I do that differently?

 
Felix Argast:

Completly forgot to check :D

I just had an idea, that the problem might be that I use Time[0] to check if the alert was allready sent for the current bar.
Because if I switch the timeframe, Time[0] contains the opening Time of a bar of a different timeframe right?

So how can I do that differently?

how did you take care of this issue? , i am having the same problem with time[0]

 
Namu Makwembo:

how did you take care of this issue? , i am having the same problem with time[0]

Use iTime with the specific timeframe you want to check for alerts 
 
Felix Argast:
Use iTime with the specific timeframe you want to check for alerts 

I don't see how that will work if you are using static or globalscope variables.

When you change time-frame these are reset with indicators.