System Trading 게시글

Mastering MQL4: Implementing onTrade Event Handlers for MetaTrader 4

첨부파일
49474.zip (1.23 KB, 다운로드 0회)

Hey there, fellow traders! Today, we’re diving into a crucial aspect of MQL4 programming: implementing the onTrade event handler. This handy little feature helps us keep tabs on our active orders, making our trading experience much smoother.

To kick things off, we’re using a CArrayInt to track order tickets. By monitoring changes to this list in the onTimer function, we can trigger specific event handlers whenever certain actions take place. Here’s a quick rundown:

//+------------------------------------------------------------------+
//| 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: This implementation doesn’t cover all the bells and whistles of the MQL5 onTradeTransaction handler. Think of it as a solid starting point!

Check out the output log for the EA in the screenshot below:


So there you have it! With these event handlers in your toolkit, you’ll be better equipped to manage your trades effectively. Happy trading!

연관 포스트

댓글 (0)