Join our fan page
- Views:
- 1739
- Rating:
- Published:
- 2025.02.06 07:46
- Updated:
- 2025.02.09 10:16
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
The code is full of comments for better understanding. This Description explains the main idea, and the ways to use/reuse the code.
This framework consists of three key components:
1. CalendarRetriever.mq5 (Script) – This script fetches past economic news events and saves them to files in the "Common" folder of your terminal. These files will later be read by the expert advisor during backtesting. The script requires two input parameters: - Start Date – The date from which past news events should be retrieved.
- End Date – The last date for which news events should be stored
After running this script, it will generate a "Calendar" folder in the "Common" directory of the terminal the following text files will be then created: - Countries.txt – Contains information about each MQLCalendarCountry
- Events.txt – Stores event details such as name, impact and countryid.
- News.bin – Holds historical news event values, including timestamps.
2. CalendarFile.mq (Include File) – This file provides a structured way to handle news data in the expert advisor. It contains two main classes: - CalendarFileWriter – Used internally by the script to store news data.
- CalendarFileReader – Used in the expert advisor to read and process news data. It includes functions to load event data and track upcoming news in the OnTick function.
3. NewsBacktest.mq5 (Expert Advisor) – This EA uses the stored data to simulate real-time news conditions in the strategy tester. It reads the saved news data using the Load functions and executes trades accordingly.
How to Use the Framework:
-
Run the CalendarRetriever Script: Select the Symbol you'd like to backtest and run the CalendarRetriever.mq5 script, with the specified start and end date.
-
The Expert Advisor
- The EA uses the CalendarFileReader class to load the data using these functions:
- LoadEvents() – Loads event details.
- LoadCountries() – Loads country information.
- LoadValues() – Loads historical news values.
- It then processes the news events in the OnTick function to determine when a news event is happening. Use Propagate() to predict, Track() to react.
- The CalendarFileReader.Propagate() function will set the next index to the next upcoming event, this should be called on each tick.
- The CalendarFileReader.Track() function returns true when a news event has passed and sets the last index to that particular event. Also called in the OnTick() function, but the result should be checked.
- The EA uses the CalendarFileReader class to load the data using these functions:
-
Backtest the Strategy Open the Strategy Tester in MetaTrader 5, Select NewsBacktest.mq5 and Run the Backtest in Visual Mode
How to Adapt It to Your Own News-Based Strategies:
This framework is designed to be flexible, allowing traders to develop their own strategies around economic news events. Here are some ways you can modify it:
- Adjust the event filtering logic in OnTick() to react to specific news types (e.g., only trade after NFP or CPI releases).
- Modify the order execution logic to implement different strategies, such as fading the initial move instead of breakout trading.
- Use additional indicators alongside news events to refine entry signals.
- Change the expiration time of pending orders based on event impact level.
This solution makes backtesting news-based strategies as realistic as possible within the limitations of MetaTrader 5. By first retrieving historical news data and then simulating its impact on the market, traders can gain valuable insights into how their strategies would perform in live conditions.
For easier and better understanding make sure to check out my video about it:

This EA is designed to automatically follow market trends using signals from the Moving Average and Stochastic Oscillator indicators. The EA detects buy and sell signals by utilizing MA crossovers and confirms the trend with Stochastic. Additionally, the EA includes automatic position management, such as setting Take Profit, Stop Loss, and lot size doubling to enhance trading effectiveness in trending markets.

Trade Assistant MetaTrader indicator — a multi-timeframe indicator that is based on three standard indicators: Stochastic oscillator, RSI (Relative Strength Index), and CCI (Commodity Channel Index). It displays current trend directions for M1, M5, M15, M30, H1, H4, D1, W1, and MN1 timeframes. When you follow such an indicator you have a clear picture of the trends across all important timeframes. It doesn't matter which timeframe you attach this indicator to. The indicator can be downloaded for MT4 and MT5.

An indicator which visualizes how volume changes over time within each bar. It shows tick volume in a rolling histogram format.

A script which when dragged onto the chart will print out in the experts window the number of bars that are on that chart - like magic.