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

TradeTransaction Class - MetaTrader 5 Library - MT4/MT5 Resources

author EAcpu | 3 reads | 0 comments |

TradeTransaction Class - library for MetaTrader 5

TradeTransaction Class - library for MetaTrader 5

When certain actions are performed on a trading account, its status changes. Such actions include:

A special OnTradeTransaction() handler is provided in MQL5 for applying trade transactions to an account.

 Blank Online Transaction ()
constant MqlTrade transaction & trans, // trade transaction structure constant Mql trade request & request, // request structure constant Mql trade result & result // response structure );

The OnTradeTransaction() function can be used for:

The OrderSendAsync() function is designed for high-frequency trading, and according to the terms of the trading algorithm, wasting time waiting for a response from the server is unacceptable.

However, analyzing transactions using the default OnTradeTransaction() handler provided in MQL5 seems complicated.

The trade transaction class maps the underlying low-level trade transactions to custom handlers corresponding to the trade operation type.

This class has the following methods:

//+------------------------------------------------------------------+
//| CTradeTransaction class.                                        |
//|Purpose: The base class of trade transactions.                      |
//+------------------------------------------------------------------+
Class CTrade Trading { People :
                    CTrade transaction ( blank ) { }
                    ~CTradeTransaction( blank ) { }
//--- event handler blank OnlineTrade ( const MqlTrade transaction & trans,
Constant Mql Transaction Requests & Requirements,
Constant Mql transaction result &result); protected :
//--- Trade Transaction //--- These methods should be overridden in derived classes. Virtual Blank Trade Order Placed ( Oolong Order) { }
Virtual blank transaction order modification ( Oolong command) { }
Virtual blank transaction order has been deleted ( Oolong order) { }
Virtual blank transaction order has expired ( Oolong order) { }
Virtual blank transaction order trigger ( Oolong order) { }

Virtual blank trading position has been opened ( own position, own trade) { }
Virtual blank trading position StopTake ( own position, own transaction) { }
Virtual blank trading position has been closed ( own position, own trade) { }
Virtual blank basis for closing trading positions ( own position, own transaction) { }
Virtual blank trading position modification ( Oolong position) { }
  }; //+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
blank Online Transaction ( constant MqlTrade Transactions & Trans,
                        constant Mql transaction request & requirement,
                        constant Mql trading results & results)
  {
//--- CTradeTransaction ExtTransaction;
//--- External affairs. Online transactions (transmissions, requests, results);
  }
//+----

Finally, this article provides an in-depth discussion about trade transactions in MQL5. MQL5 Manual: Handling of TradeTransaction Events

https://www.mql5.com/en/articles/1111

2019.03.06 - v.1.00: Initial version.

2025.03.05 - v.1.10: Fixed issue with STOP LIMIT orders not being captured. Added 'SetLogging' public method to control printing of details to the 'expert' log.


Attachment download

📎 tradetransaction.mqh (20.43 KB)

📎 trademonitor_ea.mq5 (9.11 KB)

Source: MQL5 #24901

TradeTransaction Class - Important points before using the MetaTrader 5 library

This page has been supplemented with structured instructions, focusing on the purpose of EA source code, MQL4/MQL5 platform compatibility, testing process and risk control. Before downloading or deploying, it is recommended to first determine whether it is consistent with your own variety, cycle and account environment.

Suitable for who to use

  • Users who want to quickly screen EA source code and are willing to do simulation disk verification first.
  • People who need to compare MT4/MT5 EAs, indicators, scripts or source code projects.
  • Traders who wish to record backtests, parameters and risk boundaries before placing a trade.

Testing and risk control suggestions

  • First verify the default parameters in the strategy tester or demo account, and then adjust the symbol, period, spread and trading period one by one.
  • Scalping, grid, martin, and high-frequency strategies should focus on observing maximum drawdowns, consecutive losses, slippage, and trading frequency.
  • It is not recommended to run any document directly on the real disk. At least observe the simulated disk performance for 2-4 weeks first.

FAQ

Can MT4 and MT5 be used interchangeably?
Usually cannot be used directly. EX4/MQ4 corresponds to MT4, EX5/MQ5 corresponds to MT5, and the source code needs to be compiled in the corresponding MetaEditor.

Is this resource guaranteed to be profitable?
cannot. EAs, indicators and scripts can only be used as trading tools, and the results depend on parameters, market environment, spreads, slippage and risk control.

What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase .

English Search Notes

This page is also optimized for English search intent around TradeTransaction class - MetaTrader 5 library . Related search terms include: MQL4 source code, MQL5 source code. Test any Forex EA, Expert Advisor, MT4/MT5 indicator, script or MQL source code with historical data and a demo account before live trading.

Verification code Refresh