How to control a number of order placement?

 

Hi, 

I am building a simple EA to place an order based on MA. (i.e. when a bid price is above MA then to place a buy order....). I want to place only one order placement for each candle. Do you know how to control for this?

Best, 

Mygreen

 

If you need to open one order for each new candle you need a function to check if the new incoming tick generate a new candle or not.

// Global variables
datetime lastBar = 0;

// OnTick
   bool IsNewBar = iTime(NULL,0,0) > lastBar;
   if( IsNewBar ) {
      lastBar = iTime(NULL,0,0);
      // Code for each new bar
   }
 

Thank you Fabio. I will try with it. 

Best regards, 

MyGreen

Reason: