Download MetaTrader 5

Repeating Alert Problem

To add comments, please log in or register
Forex Trader
114267
Forex Trader 2008.02.08 18:22 
Hi,
I am trying to learn to write this code and cannot seem to figure out the problem here. \Basically once the alert condition is met the indicator continues to send alerts on every tick. How can I change the code so that only one alert is sent when the condition is met? Any help would be greatly apperciated.

  if(SellAlert)
      {
         if(ExtMapBuffer8[i]>=ExtMapBuffer1[i])
         {
            SendMail("TestSignal:"+Symbol()+" SELL ALERT ",Symbol()+" has generated a SELL Signal "+MarketInfo(Symbol(),MODE_ASK)+" on the"+Period()+" minute chart.");
            Alert("TestSignal SELL ALERT:"+Symbol()+" entered a SELL ZONE at "+MarketInfo(Symbol(),MODE_ASK)+" on the "+Period()+" minute chart.");
            
         }

Forex Trader
114267
Forex Trader 2008.02.08 23:06  
Add a flag

bool Alerted = false;

int start(){
...
... // somewhere put a reset of the flag to false after alert is triggered
...

if(SellAlert && Alerted == false)
      {
         if(ExtMapBuffer8[i]>=ExtMapBuffer1[i])
         {
            SendMail("TestSignal:"+Symbol()+" SELL ALERT ",Symbol()+" has generated a SELL Signal "+MarketInfo(Symbol(),MODE_ASK)+" on the"+Period()+" minute chart.");
            Alert("TestSignal SELL ALERT:"+Symbol()+" entered a SELL ZONE at "+MarketInfo(Symbol(),MODE_ASK)+" on the "+Period()+" minute chart.");
            Alerted = true;
            
         }




Forex Trader
114267
Forex Trader 2008.02.08 23:33  
many thanks!!
fxtptp
5
fxtptp 2016.09.19 17:11  
Forex Trader:
many thanks!!

Hi 

Is the Boolean Alerted written in Init()?

But it only initialized once, then the Alerted will stay True forever. 

Marco vd Heijden
Moderator
4728
Marco vd Heijden 2016.09.19 17:29  

Well not if you set it back to zero somewhere.

And that depends on the strategy really.

You can have what is called a single shot which means an alert is given for every time the level goes above or below a pre defined value.

But you can also have a flip-flop this setup means it will oscillate alerts between high and low values, and will not give multipe alerts for a series of high breaches so to speak.

To add comments, please log in or register