Help with arrays - page 2

 

Well i always first make a shadow copy of the entire thing so then i can work with it outside of the actual orderselect loop.

I can not tell what you are trying to do from that code but i guess the loops allow for errors.

//+---------------------------------------------------------
void FindOrders()
  {
   int orders=OrdersHistoryTotal();
   string symbol[];ArrayResize(symbol,orders,0);
   int ticket[];ArrayResize(ticket,orders,0);
   int type[];ArrayResize(type,orders,0);
   datetime opentime[];ArrayResize(opentime,orders,0);
   double openprice[];ArrayResize(openprice,orders,0);
   
//--- shadow
   for(int pos=orders; pos>=0; pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         symbol[pos]=OrderSymbol();
         ticket[pos]=OrderTicket();
         type[pos]=OrderType();
         opentime[pos]=OrderOpenTime();
         openprice[pos]=OrderOpenPrice();
        }
     }

//--- now what are you looking for ?
   datetime timeindex=0;int posindex=0;
   for(int pos=orders; pos>=0; pos--)
     {
      if(symbol[pos]==Symbol())
        {
         if(type[pos]==OP_SELLLIMIT ||type[pos]==OP_BUYLIMIT)
           {
            if(opentime[pos]>timeindex)
             {
              timeindex=opentime[pos];
              posindex=pos;
             }
           }
        }
     }
     
//--- result
      int lastorderticket=ticket[posindex];
      int lastordertype=type[posindex];
      double lastorderprice=price[posindex]; 
      
//--- now what ?
              
}
//+------------------------------------------------------------------+
 

I am trying to restore any pending order that gets deleted while the EA is working using the ticket of the order

If for example I have 10 orders and 1 gets deleted, the EA will loop through history, if it finds a ticket that is in its array, it will restore that order and set that ticket to 0, so that it doesn't use the ticket a second time

 

Okay but you can not influence the ticket as it is a response from the server and will never be the same number.

To find if the order has been closed it's OrderCloseTime() has to be analyzed.

If the value !=0 the order was closed and you can reopen it and set the ticket position (and time) to zero to make sure it will not be found again.

Note that as soon as you update the orderselect loop the old and the new ticket will again be loaded from history.

I do not understand why you want to reopen a closed position make sure it does not result in a cascade event where your robot starts to open and close orders until the account blows.

 
Marco vd Heijden:

Okay but you can not influence the ticket as it is a response from the server and will never be the same number.

To find if the order has been closed it's OrderCloseTime() has to be analyzed.

If the value !=0 the order was closed and you can reopen it and set the ticket position (and time) to zero to make sure it will not be found again.

Note that as soon as you update the orderselect loop the old and the new ticket will again be loaded from history.

I do not understand why you want to reopen a closed position make sure it does not result in a cascade event where your robot starts to open and close orders until the account blows.

Ok, it won't, I will be disabling it manually when I can't monitor 
 
Nurudeen Amedu:
Ok, it won't, I will be disabling it manually when I can't monitor 

Well if that ever happens it will take mere microseconds and you will never be fast enough to hit the disable button.

Then the only hope that will be left, is that all those trades turn out to be profitable.

 
Marco vd Heijden:

Well if that ever happens it will take mere microseconds and you will never be fast enough to hit the disable button.

Then the only hope that will be left, is that all those trades turn out to be profitable.

i have gotten what i want, but now my only problem is array out of range error, is there a way for me to repopulate array every time an order is restored

meaning that when a buy limit or sell limit is placed, how can i make the array loop and gather its values again 

 
Nurudeen Amedu:

i have gotten what i want, but now my only problem is array out of range error, is there a way for me to repopulate array every time an order is restored

meaning that when a buy limit or sell limit is placed, how can i make the array loop and gather its values again 

It means you have to also increase size dynamically.

ArrayResize(somearray,ArraySize(somearray)+1,0):
 
Marco vd Heijden:

It means you have to also increase size dynamically.

ok i'll try it thanks
Reason: