Bar-Based Signal Generation and Trade Execution in an MQL5 Tester
Summary
This MQL5 tutorial builds on a position-properties Expert Advisor to demonstrate basic Strategy Tester mechanics. It shows how to detect a new bar by comparing its opening time with a stored timestamp, retrieve open and close prices into series-indexed arrays, and evaluate a completed bar rather than the still-forming current bar. The sample signal labels an up bar as a buy and a down bar as a sell, with a separate return value when neither condition applies.
The article also introduces the Standard Library trade class for opening or reversing positions and discusses organizing signal and execution logic into functions. The examples are deliberately simple and illustrate implementation rather than a tested trading edge. The excerpt does not provide strategy performance statistics or a detailed assessment of execution costs, and the bar-direction rule alone is not evidence of profitability.
Key ideas
- A stored bar timestamp can be compared with the latest bar time to detect a new bar.
- Series-indexed price arrays make the latest bar available at index zero and the previous completed bar at index one.
- The sample signal uses the previous bar’s open and close to distinguish bullish and bearish bars.
- The tutorial organizes signal generation and trade operations into separate functions using the standard trade class.
- The example teaches tester mechanics and does not provide evidence of trading profitability.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.