Alert repeats several times

 
     

Hi
I want to have an alert when the volume is going upper than the volume of 2 min before.

long Prev_Vol=iVolume(NULL,PERIOD_M1,2);
   long This_Vol=iVolume(NULL,PERIOD_M1,0);

      if( This_Vol>Prev_Vol) { Alert("Alert");}

the problem is it makes several alerts because after the first alert , condition will steal true until the next bar starts.


how can I solve this problem?

sorry for poor english

 
Reza nasimi:

Hi
I want to have an alert when the volume is going upper than the volume of 2 min before.

the problem is it makes several alerts because after the first alert , condition will steal true until the next bar starts.


how can I solve this problem?

sorry for poor english


Hi,

You need to save last alert, and refresh it back at new bar.

1. Create variable lastbar as datetime, and alert_done as bool

datetime lastbar;
bool alert_done=false;

2. In the main loop

  //--check once at every new bar
  if(lastbar!=Time[0])
  {
    //--do something ... 
    alert_done = false;
    //--
    lastbar=Time[0];
  }//-- end lastbar

  long Prev_Vol=iVolume(NULL,PERIOD_M1,2);
  long This_Vol=iVolume(NULL,PERIOD_M1,0); //--your running volume now

  if(!alert_done && This_Vol>Prev_Vol)  //--you will get alert just once, until new bar to come
  {
    Alert("Alert");
    alert_done=true;
  }

Good luck (^̮^)

 
Yohana Parmi:

Hi,

You need to save last alert, and refresh it back at new bar.

1. Create variable lastbar as datetime, and alert_done as bool

2. In the main loop

Good luck (^̮^)


Thank you very much dear yohana :)

 
  1. if(lastbar!=Time[0])
    Yohana Parmi's method will alert once per bar, but the alert is based on the M1. If they aren't the same TF, that may not be what you want.

  2. if( This_Vol>Prev_Vol) { Alert("Alert");}
    You are looking at a signal. You can alert on a change of signal.
              Too many orders - MQL4 and MetaTrader 4 - MQL4 programming forum