Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 4 Expert Advisor | MQL4 Implementation of onTrade Event Handler

The code keeps track of orders' tickets in an CArrayInt. Monitoring the changes to the list of tickets in onTimer it triggers these event handlers:

//+------------------------------------------------------------------+  //| Event handler when stop loss is hit                              |  //+------------------------------------------------------------------+  void onStopLoss(ulong ticket);    //+------------------------------------------------------------------+  //| Event handler when take profit is hit                            |  //+------------------------------------------------------------------+  void onTakeProfit(ulong ticket);    //+------------------------------------------------------------------+  //| Event handler when a new order is opened                         |  //+------------------------------------------------------------------+  void onTradeEntry(ulong ticket);    //+------------------------------------------------------------------+  //| Event handler when an order is closed(removed)                   |  //+------------------------------------------------------------------+  void onTradeExit(ulong ticket);  

note: Not all features of the MQL5 onTradeTransaction handler has been implemented here. It is just a basic approach.

In the screenshot below you can see the output log for the EA:

MetaTrader Experts, Indicators, Scripts and Libraries

49474