open a new order only when another is close after cross

 

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);

        }
     }
  }
 
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?

Reason: