0
votes

Please can someone help me with the mql4 code for alternating buy and sell order.that is if buy order hit a stop loss a sell order should be executed and if a sell order hit a stop loss buy order should be executed.

1

1 Answers

0
votes

If your request to loop over orders and do action based on type, then the below might help:

// We go through all the open orders
   for(int b = OrdersTotal()-1; b>=0; b--)
     {
      // we select an order
      if(OrderSelect(b,SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
                // Do something on buy trades
              }
              }
            if(OrderType()==OP_SELL)
              {
                // Do something on buy trades
               }
            }
        }
    }