MQL - run code on candle opening/closing?

Dear all,

How can I run some code on candle opening/closing or once per candle? I am building an EA based on moving average crossover, but a crossover can happen multiple times in one period (one 4H candle for example) and I want to open only one trade, not multiple trades (one every time the crossover happens).

Thank you in advance!!!

Maybe you should try the MQL5 site they probably already have something made.

I found the answer and it works like a charm :slight_smile:

int BarsCount = 0;

int start()
{

if (Bars > BarsCount)
{
//your code to be executed only once per bar goes here

BarsCount = Bars;

}

return(0);
}