Order Triggering and Execution in MT5 Strategy Tester
The MetaTrader 5 Strategy Tester simulates order execution based on distinct price types depending on the instrument classification. For non-exchange instruments, triggering of all pending orders and stop-loss/take-profit levels is performed using Bid and Ask prices. Execution occurs at the current Bid and Ask market prices at the moment of triggering. In contrast, for exchange instruments, charts are plotted and stop orders are triggered by the price of the last performed deal, referred to as Last. Limit orders on exchange instruments are triggered by Bid and Ask prices, but unlike other order types, they are executed exactly at the price specified in the order, without slippage.
All other order types on exchange instruments are executed at the current Bid and Ask market prices, which introduces the possibility of slippage. The documentation provides a concrete example using the exchange instrument Si-6.16. With initial prices of Bid=72570, Ask=72572, and Last=72552, a Buy Stop order is placed with an execution price of 72580. When new prices arrive showing Bid=72588, Ask=72590, and Last=72580, the occurrence of Last=72580 triggers the Buy Stop order. The order is then executed as a market buy operation at the current Ask price of 72590, demonstrating how Last prices drive stop order activation on exchange instruments.
Sources: MetaTrader 5 documentation: features MetaTrader 5 documentation: testing
Tick Generation Modes and Execution Accuracy
The Strategy Tester offers several tick generation modes that significantly influence how orders are triggered and executed. The 'Every tick' mode is the most accurate but also the slowest, as it simulates every single tick in the historical data. The 'Every tick based on real ticks' mode provides conditions close to real trading by utilizing actual tick data accumulated by brokers, avoiding any simulation. In contrast, the '1 minute OHLC' mode only emulates four prices—Open, High, Low, and Close—for each minute bar. The 'Open prices only' mode similarly models OHLC prices but restricts testing and optimization to use only the open price for triggering and execution events.
The algorithm for executing orders at market prices, which is standard in accurate modes like 'Every tick' and 'Real ticks', is not suitable for less accurate modes such as 'Open prices only' and '1 minute OHLC'. In these reduced modes, intermediate ticks are not generated, which can result in a significant difference between the requested order price and the current Open or OHLC price. To address this limitation and provide more accurate testing results, the Strategy Tester executes pending orders, as well as Stop Loss and Take Profit levels, at the prices specified in the orders when using the 'Open prices only' and '1 minute OHLC' modes. This ensures that execution occurs at the requested price rather than simulating a potentially unrealistic market price.
Sources: MetaTrader 5 documentation: features MetaTrader 5 documentation: testing
Exchange vs Non-Exchange Instrument Execution Differences
The distinction between exchange and non-exchange instruments is fundamental to understanding order execution within the Strategy Tester. For non-exchange instruments, the triggering mechanism for all types of pending orders and SL/TP levels relies entirely on Bid and Ask prices. The execution of these triggered orders is then performed by the current Bid and Ask market prices at the specific moment of triggering. This model aligns with typical forex trading dynamics where trades are executed against a broker's liquidity pool.
For exchange instruments, the mechanism diverges significantly. Chart plotting and the triggering of stop orders are driven by the Last price, which represents the price of the last performed deal. However, limit orders on exchange instruments continue to be triggered by Bid and Ask prices. Once triggered, limit orders are executed at the price specified in the order, guaranteeing no slippage for these specific order types. Conversely, orders of other types, such as market orders triggered by stop conditions, are executed at the current Bid and Ask market prices, making slippage a distinct possibility during volatile market conditions.
Sources: MetaTrader 5 documentation: features MetaTrader 5 documentation: testing
Bar Creation and Tick Simulation Constraints
The creation of bars within the Strategy Tester for exchange symbols is strictly governed by the presence of ticks with non-zero Last prices. While Bid and Ask prices may arrive and indicators may be calculated based on these inputs, bars are not formed unless a tick with a non-zero Last price is received. In the 'Every tick' mode, there are no zero Last prices; consequently, each incoming tick modifies the current bar. This behavior ensures that bar progression is directly tied to actual traded prices rather than just bid/ask quotes.
This constraint highlights the importance of data quality and the specific simulation mode selected for testing. For strategies relying heavily on exchange instruments, the absence of Last prices in certain data sets or modes can prevent bar formation, potentially leading to incomplete or inaccurate backtesting results. Therefore, understanding how ticks influence bar creation is essential for interpreting the behavior of Expert Advisors during the testing phase, especially when transitioning between different tick generation modes.
Sources: MetaTrader 5 documentation: features MetaTrader 5 documentation: testing
Practical Implications for Strategy Testing
Selecting the appropriate tick generation mode is a critical step in configuring a realistic backtest for an Expert Advisor. The choice directly impacts how order triggers are evaluated and how executions are filled. For instance, using 'Open prices only' or '1 minute OHLC' modes simplifies the simulation process and speeds up testing by reducing the computational load, but it requires the tester to execute orders at requested prices to maintain accuracy. This prevents the artificial slippage that would occur if the tester attempted to use open or OHLC prices as market execution points in the absence of intermediate ticks.
Conversely, modes like 'Every tick' or 'Real ticks' offer the highest level of realism by simulating the full price flow, including the potential for requotes and network delays. These modes allow for a comprehensive evaluation of how an Expert Advisor responds to rapid price changes and execution slippage. However, they require substantial historical tick data and significantly more processing time. Traders must balance the need for detailed, high-fidelity simulation against the practical constraints of data availability and computational resources when setting up their testing environment.
Sources: MetaTrader 5 documentation: features MetaTrader 5 documentation: testing
AI-assisted educational article. Automated checks reviewed source support and quality; they do not guarantee accuracy. This is not investment advice. Leveraged and automated trading involves substantial risk of loss.
Sources & further reading
MetaTrader 5 documentation: testingMetaTrader 5 documentation: featuresEducational content only. This article is not investment advice. Automated and leveraged trading involves substantial risk of loss.