Listening to new order opened event

To add comments, please log in or register
ziomek
10
ziomek  

Hi,

I am looking for a method which will tell me in Expert Advisor that an user has placed order (buy / sell). I mean I want to start an action when such event occurs. 

Is there any available? Can't find it in documentation.

 

Cheers 

Kaleem Haider
359343
Kaleem Haider  
ziomek:

Hi,

I am looking for a method which will tell me in Expert Advisor that an user has placed order (buy / sell). I mean I want to start an action when such event occurs. 

Is there any available? Can't find it in documentation.

 

Cheers 

try this https://www.mql5.com/en/docs/basis/function/events#ontrade
Alexander Fedosov
18789
Alexander Fedosov  
void OnTrade() 
  { 
//--- static members for storing trading account status 
   static int prev_positions=0,prev_orders=0,prev_deals=0,prev_history_orders=0;
//--- request trading history 
   bool update=HistorySelect(history_start,TimeCurrent()); 
   PrintFormat("HistorySelect(%s , %s) = %s"
               TimeToString(history_start),TimeToString(TimeCurrent()),(string)update);
//--- heading named after trading event's handler function  
   Print("=> ",__FUNCTION__," at ",TimeToString(TimeCurrent(),TIME_SECONDS)); 
//--- display handler's name and the number of orders at the moment of handling 
   int curr_positions=PositionsTotal(); 
   int curr_orders=OrdersTotal(); 
   int curr_deals=HistoryOrdersTotal(); 
   int curr_history_orders=HistoryDealsTotal(); 
//--- display the number of orders, positions, deals, as well as changes in parentheses 
   PrintFormat("PositionsTotal() = %d (%+d)"
               curr_positions,(curr_positions-prev_positions)); 
   PrintFormat("OrdersTotal() = %d (%+d)"
               curr_orders,curr_orders-prev_orders); 
   PrintFormat("HistoryOrdersTotal() = %d (%+d)"
               curr_deals,curr_deals-prev_deals); 
   PrintFormat("HistoryDealsTotal() = %d (%+d)"
               curr_history_orders,curr_history_orders-prev_history_orders); 
//--- insert a string break to view the log more conveniently 
   Print(""); 
//--- save the account status 
   prev_positions=curr_positions; 
   prev_orders=curr_orders; 
   prev_deals=curr_deals; 
   prev_history_orders=curr_history_orders; 
//--- 
  }
//----//
ziomek
10
ziomek  
Many thanks!
To add comments, please log in or register