Code for one trade per candle

samyjo222  

Hi all 

Please could someone assist with the code required to ensure that only one buy/sell order is executed per candle? 

Many thanks

Sam 

Fernando Carreiro  
samyjo222: Please could someone assist with the code required to ensure that only one buy/sell order is executed per candle? 

That has been requested in the forum so many times, that us old-timers are getting a bit tired of it.

Search the Forum. There are many such requests. See the answers.

Search the CodeBase. There are many types of EAs both simple ones and complex ones. Study them. Use them. Adapt them. Learn to code from them.

And lastly, here is some code on how to detect the opening of a new bar/candle:

Code Base

Detecting the start of a new bar or candle

Fernando Carreiro, 2022.04.24 00:38

Detecting the start of a new bar or candle, in the OnTick() event handler of an expert advisor.

maximo  
   int timeframe = PERIOD_CURRENT;

   int bars_since_open = iBarShift(_Symbol,timeframe,OrderOpenTime());


 OrderOpenTime()  // is an inbuilt function in MT4, so for MT5  this can be a custom function to retrieve this information.

Reason: