[Help] - EA Bar length alert

 

Dear pro,

I try to code EA to alert if bar length > 20pip in M15 chart. But when running, alert is continuous and cannot stop. I just need alert 1 time/1 bar. Pls help me to check code below. Thanks a lot!

void OnTick()

  {

  

 double a = iHigh(Symbol(), PERIOD_M15 ,0);

 double b = iLow (Symbol(), PERIOD_M15,0);

 double candle = a - b;

 double e = 2;

  

 if ( candle > 0.20 && e > 0)

 { e = e -1;};

 

 if ( e ==1)

 { 

 Alert( "Candle Alert on: ", candle);

 }; 

 return;

 } 

Files:
Candle.mq4  2 kb
Candle.ex4  6 kb
 
use static with time, try some search
 
Samuel Akinbowale:
use static with time, try some search
https://www.mql5.com/en/forum/129048
 

I tried with new code:

But why when e = 0, condition for if function is not ok, but it still Alert repeatedly?!!


void OnTick()

  {

  double a = iHigh(Symbol(), PERIOD_M15 ,0);

 double b = iLow (Symbol(), PERIOD_M15,0);

 double candle = a - b;

 double e = 1;

 if ( candle > 0.20 && e > 0)

 { e = e -1;

 Alert( "Candle Alert on: ", candle);

 }; 

 return;

 } 

 
  1.  double candle = a - b;
     if ( candle > 0.20 ){ 
        Alert( "Candle Alert on: ", candle);
    You're running that code every tick. Why do you expect it to not repeatedly alert, once the current M15 bar becomes larger than 20 pips on JPY pair or 2000 pips on others.
               What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Either only check once on a new bar or Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. Stop opening new posts. This is the fourth time you have been answered. The others have been deleted.
Reason: