Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

MQL4 implementation of onTrade event handler - MetaTrader 4 Expert - MT4/MT5 Resources

author EAcpu | 4 reads | 0 comments |

MQL4 Implementation of onTrade Event Handler - expert for MetaTrader 4

MQL4 Implementation of onTrade Event Handler - expert for MetaTrader 4

The code keeps track of the order's tickets in a CArrayInt way. It monitors the ticket list for changes with a timer and it fires these event handlers:

 //+------------------------------------------------------------------+
//|Event handler when stop loss is hit |
//+------------------------------------------------------------------+
Blank stop loss ( own ticket); //+--------------------------------------------------------------------------------+
//|Event handler when take profit is reached |
//+------------------------------------------------------------------+
Blank take profit ( own ticket); //+--------------------------------------------------------------------------------+
//|Event handler when opening a new order |
//+------------------------------------------------------------------+
Blank transaction input ( own ticket); //+---------------------------------------------------------------------------------+
//|Event handler when order is closed (deleted) |
//+------------------------------------------------------------------+
Blank transaction exit ( own ticket);

Note : Not all features of the MQL5 onTradeTransaction handler are implemented here. This is just a basic method.

In the screenshot below you can see the EA's output log:

MQL4 Implementation of onTrade Event Handler - expert for MetaTrader 4


Attachment download

📎 ontrade.mq4 (9.23 KB)

Source: MQL5 #49474

Verification code Refresh