Download MetaTrader 5

how to alert once at a time

To add comments, please log in or register
Harshan Lakshitha Dias
125
Harshan Lakshitha Dias  

my code didnt perform well. ex :

if(normal logic... ){

if( !hasSentAlertOnce ){

Alert(" Alert " + Symbol() +" "+ Period());

hasSentAlertOnce= true;

}

}else {

hasSentAlertOnce = false;

}

anything wrong in this code (bt didnt wrk :( alert over n over ) . still couldnt figure out

Airat Safin
1308
Airat Safin  

..

static bool hasSentAlertOnce = false ;

..

if(normal logic... ){

if( !hasSentAlertOnce ){

Alert(" Alert " + Symbol() +" "+ Period());

hasSentAlertOnce= true;

}

}else {

hasSentAlertOnce = false;

}

Harshan Lakshitha Dias
125
Harshan Lakshitha Dias  
Ais:

..

static bool hasSentAlertOnce = false ;

..

if(normal logic... ){

if( !hasSentAlertOnce ){

Alert(" Alert " + Symbol() +" "+ Period());

hasSentAlertOnce= true;

}

}else {

hasSentAlertOnce = false;

}

hasSentAlertOnce is global variable on my code.so is it necessary to set static ?
whroeder1
17111
whroeder1  
  1. Global == static

  2. Depending on the how often your 'normal logic' triggers, you might want to suppress the alert for a period of time:

    static datetime allowAlert;
    if (TimeCurrent() > allowAlert){ allowAlert=TimeCurrent()+ 5*60; Alert(...
Airat Safin
1308
Airat Safin  

..

//< Initialization >

bool hasSentAlertOnce = false ;

//</Initialization >

..

if(normal logic... ){

if( !hasSentAlertOnce ){

Alert(" Alert " + Symbol() +" "+ Period());

hasSentAlertOnce= true;

}

}else {

hasSentAlertOnce = false;

}

Harshan Lakshitha Dias
125
Harshan Lakshitha Dias  
still no luk :(
hasayama
633
hasayama  

You set your flag to TRUE

if( !hasSentAlertOnce ){
Alert(" Alert " + Symbol() +" "+ Period());
hasSentAlertOnce= true;
}

than a signal repeats and it is FALSE again,

}else {
hasSentAlertOnce = false;
}

thus no sense in changing the flag so often.

Use another trick:

if ( ALERT_CONDITION ) { Alert(); wasAlert = true; }

if ( ANTI_ALERT_CONDITION ) { wasAlert = false; }

ANTI_ALERT_CONDITION must be different from ALERT_CONDITION but not a simple "else".

If you have sell and buy signals alert it is better to use a switch:

int Last_Signal = 0; //--no signal so far

if ( buySignalAppeared && Last_Signal <= 0 ) { Alert(); Last_Signal = 1; } //--was sell, become buy

if ( sellSignalAppeared && Last_Signal >= 0 ) { Alert(); Last_Signal = -1; } //--was buy, become sell

Airat Safin
1308
Airat Safin  

..

//< Initialization >

bool hasSentAlertOnce = false ;

//</Initialization >

..

if(normal logic... ){

if( !hasSentAlertOnce ){

Alert(" Alert " + Symbol() +" "+ Period());

hasSentAlertOnce= true;

}

}//else {

//hasSentAlertOnce = false;

//}

jurcekmpt
592
jurcekmpt  
double alertTag;
if (rule for alert && alertTag!=Time[0]){
   Alert (blablabla);
   alertTag=Time[0];
}
This will give you alert only once per bar, but if on next bar open rule for alert is still true it will gives you alert again on so on.
indy231
11
indy231  
jurcekmpt:
This will give you alert only once per bar, but if on next bar open rule for alert is still true it will gives you alert again on so on.

This solution works well for me, butI had to declare "alertTag" as a STATIC DATETIME variable not a Double.

Thanks

whroeder1
17111
whroeder1  
  1. Of course you do.
  2. Do you really expect the original poster to be waiting for your post after seven (7) years? Don't resurrect old threads unless you have a good reason.
12
To add comments, please log in or register