Prevent EA Code from executing again a second time

 

Hello

With MQL4, I have always the same problem in general. Take a look at the following code:

int start()
  {
//----
   if(AccountEquity()>2000) ShowMessageBox();
//----
   return(0);
  }
  
  void ShowMessageBox()
{
 
Messagebox("This is the Messagebox");
 
 }

Problem is, as soon as the Equity is over 2000, the message box is shown at EVERY tick move. Even when the messagebox is closed, it appears again at the next tick (of course only when the equity is over than 2000).

The messagebox is only an example. Instead of a messagebox, I use another code i. e. to open Limit orders. But there is the same problem as with the messagebox.

Is it modify the code so that as soon as the equity is over 2000 the following code executes only once, and then never again no matter what happens?

 

Make a flag

 

int start()
   {
    
   static int loopCount, messageCount;   static bool Flag = false;
   if(AccountEquity()>2000 && Triggered == false) {   
      messageCount++;      
      ShowMessageBox();
      Flag = true;
   }
   loopCount++;   
   Comment("\n  Loopcount = "+loopCount+"\n  MessageCount = "+messageCount);   
   return(0);
}
  
void ShowMessageBox()
{ 
   Messagebox("This is the Messagebox"); 
}
 
Great! Exactly what I was looking for. Many Thanks!!