organize all open orders in arrays

 

Hi guys,

I've been trying to separate my open orders from BUY/SELL and also sort then, this can be done at the OrderSend() level. but then I will close some of my orders and I would need to be able to delete and add array elements and shift the elements and still maintain the order 

I couldn't find any function that would do this, so I guess I would have to create my own but idk how.

Any help would be appreciated.

Thanks. 

 
  1. angomes: I've been trying to separate my open orders from BUY/SELL  and also sort then

    What is the difference between open orders and BUY/SELL orders?
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  2. Why do you need to sort them?

  3. angomes: but then I will close some of my orders and I would need to be able to delete and add array elements and shift the elements and still maintain the order 

    Yes.

  4. angomes: so I guess I would have to create my own but idk how. Any help would be appreciated.

    Please post only in English on this forum. Idk is not a word. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation.
              Please don't write ur - it's "you are" or "your" - MQL4 programming forum 2014.03.04

  5. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

 
William Roeder:
  1. What is the difference between open orders and BUY/SELL orders?
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  2. Why do you need to sort them?

  3. Yes.

  4. Please post only in English on this forum. Idk is not a word. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation.
              Please don't write ur - it's "you are" or "your" - MQL4 programming forum 2014.03.04

  5. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

 Thanks for the reply, I would like to have buy and sell orders separately and ordered on arrays. I need them separately because of my current coding logic, my EA uses martingale and will monitor the progress of the open trades and depending on the DD it will close orders on pairs always the furthest loser with the most profit order, and depending on the DD it will close more or less trades and so on.


I will post below what I did came up with, my logic was to loop through all orders and separate buys and sells, and  store the OpenOrderPrice on an array then sort it, and now I could loop the orders with the OrderOpenPrice that matched the order and make another array where all OrderTickets would be sorted and I could use it to close my trades. but I found that too complicated and most likely there is a better way.


So now I'm thinking that I can use the order send and make my array that way without any loop to go through all orders, I just need to then in my close order function delete the OrderTicket from the array and maintain the others and also shift to fill the indexed that was erased but mantain the order either ascending or descending doesn't matter I just need to code accordingly.


This is the code I first tried using OrderOpenPrice to sort it and then using that to compare and make another array for the order tickets


if(CheckOpenOrders(wyckoff)){
 
   if(ArraySize(ordersPriceBuy) != CountOrders(wyckoff, OP_BUY)){
    
    
      TotalNumberOfOrders = OrdersTotal();
     
     for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
      if(OrderMagicNumber() == magicNumber 
           && OrderSymbol() == Symbol() 
           && OrderComment() == wyckoff 
           && OrderType() == OP_BUY){
            
            ordersPriceBuy[PositionIndex] = OrderOpenPrice();
           
           }
     }
     
      ArrayResize(ordersPriceBuy, CountOrders(wyckoff, OP_BUY));
      ArraySort(ordersPriceBuy,WHOLE_ARRAY,0,MODE_ASCEND); 
     
     TotalNumberOfOrders = ArraySize(ordersPriceBuy);
      int orders = OrdersTotal();
           
    for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
        
      int position;
      for(position = orders - 1; position >= 0 ; position --)  
         {
      
      OrderSelect(position, SELECT_BY_POS, MODE_TRADES);  
        if(OrderMagicNumber() == magicNumber 
           && OrderSymbol() == Symbol() 
           && OrderComment() == wyckoff 
           && OrderType() == OP_BUY
           && OrderOpenPrice() == ordersPriceBuy[position]){
                  ordersTicketBuy[PositionIndex] = OrderTicket();
                  Print("BUY: " + OrderTicket());
                  break;
               }
             }
           }
           
           ArrayResize(ordersTicketBuy, CountOrders(wyckoff, OP_BUY));
                     
   }
   
   if(ArraySize(ordersPriceSell) != CountOrders(wyckoff, OP_SELL)){
      
      TotalNumberOfOrders = OrdersTotal();
     
     for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
      if(OrderMagicNumber() == magicNumber 
           && OrderSymbol() == Symbol() 
           && OrderComment() == wyckoff 
           && OrderType() == OP_SELL){
            
            ordersPriceSell[PositionIndex] = OrderOpenPrice();
           
           }
     }
     
      ArrayResize(ordersPriceSell, CountOrders(wyckoff, OP_SELL));
      ArraySort(ordersPriceSell,WHOLE_ARRAY,0,MODE_ASCEND); 
     
   
   
   TotalNumberOfOrders = ArraySize(ordersPriceSell);
   int orders = OrdersTotal();       
      
      
         
   for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
   {
        
      int position;
      
      for(position = orders - 1; position >= 0 ; position --)  
         {
      
      OrderSelect(position, SELECT_BY_POS, MODE_TRADES);  
        if(OrderMagicNumber() == magicNumber 
           && OrderSymbol() == Symbol() 
           && OrderComment() == wyckoff 
           && OrderType() == OP_SELL
           && OrderOpenPrice() == ordersPriceSell[position]){
                  ordersTicketSell[PositionIndex] = OrderTicket();
                  Print("SELL: " + OrderTicket());
                  break;
               }
             }
           } 
             
         ArrayResize(ordersTicketSell, CountOrders(wyckoff, OP_SELL));
   
   }
 
  
  }