how to select all the open buy orders and open sell orders from a bunch of mixed up of orders in EA?

 

hi there....i need some help in EA......can someone give the code snippet to select all the open buy orders from a bunch of mixed open orders??.....thanks in advance!!

 

How many variations do you want ?

Try this: http://crum.be/select

 
RaptorUK:

How many variations do you want ?

Try this: http://crum.be/select

  BuildOpenBuyArray();
  OpenBuyCount = ArraySize(OpenBuyTickets);
  ArraySort(OpenBuyTickets, WHOLE_ARRAY);
  for (i = 0; i < TicketCount; i++)
   {
    OrderSelect(OpenBuyTickets[i],SELECT_BY_TICKET);
    Print("OrderTicket());
    ..........
   }
    

The above code snippet will call the function below (place at the end of your EA) ito collect all buy tickets in an array called OpenBuyTickets. It will then print all the open tickets in ascending order and/or what ever you put in the .... bit.

void BuildOpenBuyArray()
 {
  OpenBuyCount = 0;
  ArrayResize(OpenBuyTickets,0);
  for (i = 0; i < OrdersTotal(); i++) 
   {
    ArrayResize(OpenBuyTickets, OpenBuyCount + 1);
    OrderSelect(i, SELECT_BY_POS);
    if (OrderType() != 0) continue;
    OpenBuyTickets[OpenBuyCount] = OrderTicket();
    OpenBuyCount = OpenBuyCount + 1;
   }
 }
 
kmnatarajan:

hi there....i need some help in EA......can someone give the code snippet to select all the open buy orders from a bunch of mixed open orders??.....thanks in advance!!

Always count DOWN in the presence of multiple order (multiple charts.) Always test return codes including orderSelect. If you keep an array of ticket numbers, what do you do on a terminal restart (crash, power fail, reboot, BSOD, etc.)
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         == OP_BUY
    ){
       :
Reason: