Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.19 12:20 

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 

Marco vd Heijden
Moderator
4680
Marco vd Heijden 2016.07.19 12:35  
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++;
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.19 16:06  

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

ticket[x]=OrderTicket();
Marco vd Heijden
Moderator
4680
Marco vd Heijden 2016.07.19 16:29  
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.

Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.19 16:39  
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
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.20 03:37  

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
41043
Nurudeen Amedu 2016.07.20 03:42  
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
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.20 03:49  
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
Marco vd Heijden
Moderator
4680
Marco vd Heijden 2016.07.20 08:42  
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;
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.20 11:21  
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;}
               }
            }   
        }
   }
}
Nurudeen Amedu
41043
Nurudeen Amedu 2016.07.20 11:29  
i've been testing and i noticed some of them are brought back twice and some are not brought back at all
/ /12
To add comments, please log in or register