Help with arrays

 

Please how do i save orders i create manually to an array so i can access the array later

for example, all orders i create at a particular price, i will be creating one order at 1 particular price up to 10 orders at 10 different prices and they will all have a specific comment

as soon as any of them is closed on MT4, i want to go to history to find the order with that exact price and restore it

how do i do this 

 
Nurudeen Amedu:

Please how do i save orders i create manually to an array so i can access the array later

for example, all orders i create at a particular price, i will be creating one order at 1 particular price up to 10 orders at 10 different prices and they will all have a specific comment

as soon as any of them is closed on MT4, i want to go to history to find the order with that exact price and restore it

how do i do this 

int x=0;

int ticket[];

ArrayResize(ticket,numberofticketstostore,0);

ticket[x]=OrderSend(....

x++;
 

so after looping through open orders and i find the orders with the comment i want, i say

ticket[x]=OrderTicket();
 
Nurudeen Amedu:

so after looping through open orders and i find the orders with the comment i want, i say

Yes but the danger will be if one order from MODE_TRADES gets closed a new ticket will overwrite a previous filled array position.

So you either make a shadow copy of the entire thing to make sure there can not be any questions as to what is where (static), or you code it in a way that it will allow for dynamically adjustments.

 
Marco vd Heijden:

Yes but the danger will be if one order from MODE_TRADES gets closed a new ticket will overwrite a previous filled array position.

So you either make a shadow copy of the entire thing to make sure there can not be any questions as to what is where (static), or you code it in a way that it will allow for dynamically adjustments.

ok, thanks
 

i did this to loop through all trades in history and compare result with array ticket values, but it doesnt seem to loop through correctly

the function that stores trade values to arrays work perfectly as i followed your instructions and i was able to display the ticket and price values to the chart

void FindOrders(){
       int lastorderticket, lastordertype;
       double lastorderprice;
       //stp, btp,
       for(int pos=OrdersHistoryTotal(); pos >= 0; pos--){
        
       if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
       if( OrderSymbol()==Symbol() &&  (OrderType()== OP_SELLLIMIT||OrderType()==OP_BUYLIMIT)){
            
            lastorderticket=OrderTicket();
            lastordertype=OrderType();
            lastorderprice=OrderOpenPrice();
            
            for(int y=x+1; y>0; y--){
               
               int arrayTicket=ticket[y];
               
               Comment(arrayTicket, " ", OrderTicket(), " ", x); //I see this comment when i put EA on chart and both values are displayed
               
               if(OrderTicket()==arrayTicket){ //This is where the problem most likely is
                  
                     OrderSend(Symbol(),lastordertype,LotSize,lastorderprice,10,0,0,"copied",1342,0,clrBlue);
               }
            }   
        }
   }
}
 
Nurudeen Amedu:

i did this to loop through all trades in history and compare result with array ticket values, but it doesnt seem to loop through correctly

the function that stores trade values to arrays work perfectly as i followed your instructions and i was able to display the ticket and price values to the chart

i just tried again and the code works
 
Marco vd Heijden:

Yes but the danger will be if one order from MODE_TRADES gets closed a new ticket will overwrite a previous filled array position.

So you either make a shadow copy of the entire thing to make sure there can not be any questions as to what is where (static), or you code it in a way that it will allow for dynamically adjustments.

please how do i delete an array element like after trade is placed i want to delete the array ticket and open price so that it does not get reopened again as orders keep opening over and over in a loop
 
Nurudeen Amedu:
please how do i delete an array element like after trade is placed i want to delete the array ticket and open price so that it does not get reopened again as orders keep opening over and over in a loop

Im not shure what you mean by that but if you want to reset the values

ticket[x]=0;
 
Marco vd Heijden:

Im not shure what you mean by that but if you want to reset the values

it works, when i delete 1 order it is restored but when i delete the second order, it restores both the first deleted order and the second, bringing 1 second and 2 first

please can you suggest a way i can solve this

void FindOrders(){
       int lastorderticket, lastordertype;
       int result=0;
       double lastorderprice;
       //stp, btp,
       for(int pos=OrdersHistoryTotal(); pos >= 0; pos--){
        
       if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
       if( OrderSymbol()==Symbol() &&  (OrderType()== OP_SELLLIMIT||OrderType()==OP_BUYLIMIT)){
            
            lastorderticket=OrderTicket();
            lastordertype=OrderType();
            lastorderprice=OrderOpenPrice();
            
            for(int y=x+1; y>0; y--){
               
               int arrayTicket=ticket[y];
               
               Comment(arrayTicket, " ", OrderTicket(), " ", x);
               
               if(OrderTicket()==arrayTicket){
                  
                     result = OrderSend(Symbol(),lastordertype,LotSize,lastorderprice,10,0,0,"copied",1342,0,clrBlue);
                     if(result>0){ticket[y]=0;}
               }
            }   
        }
   }
}
 
i've been testing and i noticed some of them are brought back twice and some are not brought back at all
Reason: