Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Why are you checking closed trades?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all, I'm trying to code an ea that opens only one order after the cross of two averages; pull back strategy on the retracement of the two candles. I can't find a code that opens only one order for each cross even if a second condition of a pull back occurs.
bool OneOrder(){
int i = OrdersHistoryTotal();
int a = OrdersHistoryTotal() -1;
int b = OrdersHistoryTotal();
{
for(i = a; i < b ; i++)
{
if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY) ==true)
return (true);
else
if(((MA2>DSMA2&&MA1<DSMA1)||(MA2<DSMA2&&MA1>DSMA1)) ==true)
return(false);
}
}
}