Identify orders

 
In mt4 how can I know an order executed by EA from which chart if I am using multiple windows of same currency pair
 
Ebrahim Hasan:
In mt4 how can I know an order executed by EA from which chart if I am using multiple windows of same currency pair

You can use the MagicNumber field in the order sent and have each instance of your EA have a different magic number . You can expose the input to that number for ease of setup.

 
Lorentzos Roussos #:

You can use the MagicNumber field in the order sent and have each instance of your EA have a different magic number . You can expose the input to that number for ease of setup.

Thanks Lorentzos, smart

But how can where can I see the Magic Number in the orders history?
 
Ebrahim Hasan #:

Thanks Lorentzos, smart

But how can where can I see the Magic Number in the orders history?

You can use this function to roll in the orders and collect the tickets that interest you :

int findByMagicNumber(bool find_in_history,
                      bool find_in_active,
                      int which_magic_number,
                      int &results_ticket_list[],
                      string restrict_by_symbol=NULL){
int found=0;
ArrayFree(results_ticket_list);//empty the list
//in history 
  if(find_in_history){
  int total=OrdersHistoryTotal();
  for(int i=0;i<total;i++){
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
     //if the magic number matches the one you asked for 
       if(OrderMagicNumber()==which_magic_number){
         //if the symbol matches or we don't care about the symbol 
           if(restrict_by_symbol==NULL||OrderSymbol()==restrict_by_symbol){
             //then we have a match 
               //increase found counter 
                 found++;
               //expand the list by 1
                 ArrayResize(results_ticket_list,ArraySize(results_ticket_list)+1,0);
               //add the ticket of the order in the list 
                 results_ticket_list[found-1]=OrderTicket();
             }
         }
     }
     }
  }
//in active
  if(find_in_active){
  int total=OrdersTotal();
  for(int i=0;i<total;i++){
     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
     //if the magic number matches the one you asked for 
       if(OrderMagicNumber()==which_magic_number){
         //if the symbol matches or we don't care about the symbol 
           if(restrict_by_symbol==NULL||OrderSymbol()==restrict_by_symbol){
             //then we have a match 
               //increase found counter 
                 found++;
               //expand the list by 1
                 ArrayResize(results_ticket_list,ArraySize(results_ticket_list)+1,0);
               //add the ticket of the order in the list 
                 results_ticket_list[found-1]=OrderTicket();
             }
         }
     }
     }
  }
return(found);
}
                      

and this is how you would call it (you would make sure not to call it constantly on every tick , its just an example syntax)

void OnTick()
  {
//---
  int tickets[];
  int found=findByMagicNumber(true,true,123,tickets,_Symbol);
  //then to access the tickets found one by one 
    for(int i=0;i<found;i++){
       tickets[i];//this is the ticket for you to select the order with 
       }
  }
 
Lorentzos Roussos #:

You can use this function to roll in the orders and collect the tickets that interest you :

and this is how you would call it (you would make sure not to call it constantly on every tick , its just an example syntax)

Thanks Lorentzos for your efforts.