MetaTrader 4 MT4 Expert Advisors MQL4 Implementation of onTrade Event Handler – EA MetaTrader 4

MQL4 Implementation of onTrade Event Handler – EA MetaTrader 4

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:

Alternative:   BrainTrend1 and BrainTrend2 - indicator MetaTrader 5



📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks