
Discover how a news filter reduces volatility in mean reversion strategies by analyzing past news data, exporting news values to a CSV, and testing with an MQL5 expert advisor.
Leverage the Mql5 economic calendar in the MetaTrader platform to receive near-instantaneous forex news updates, query upcoming events, filter by data types, and ensure secure, low-latency EA decision making.
Create a news filter in mql5 by defining a news filter input group, an enum for calendar event importance, and a 15-minute pre-news stop of trading, clearing positions and orders.
Develop a get past news function in mql5, copy rate data from the last ten bars, and parse calendar values to extract news events for a given symbol.
Develop a function to fetch future news for the next 24 hours using the past news framework, storing results in a values array and printing event and country details.
Implement a boolean function to detect incoming news in MQL5 within a window of seconds and return true when news is present, enabling actions like pausing trading and clearing orders.
Create a script in MQL5 that saves historical news to a csv file for backtesting a news expert advisor, using start date and end date inputs and a save_news function.
Write a CSV file by initializing a header, looping through news events with calendar data, and writing structured rows using file seek, file write, and file close operations.
Test the get news script in MetaTrader 5, run it from scripts, and verify it creates a CSV with time, name, sector, and importance for backtesting a news EA.
Declaring global parameters for a news trading expert advisor in MQL5, the lesson covers inputs for magic, slippage, risk, news importance, minutes to news, and trade management.
Change the chart appearance and initialize global variables for the expert advisor, binding the magic number and slippage, and configure min/max lot sizes and step using symbol info.
Create functions to convert string values from a CSV into enum types for sector, calendar, event, and importance, with a default return to handle unmatched cases.
Create a news structure and news object to store csv data using arrays for time, name, sector, importance, actual, forecast, and previous; implement data insertion, resizing, and removal functions.
Open and read a news CSV in the MQL5 tester, validate the file handle, parse seven-column rows into news objects, and output formatted results.
In the MQL5 advanced course, implement a boolean function news_present to check historical news by time and importance, prune outdated entries, and trigger a news-based entry for the expert advisor.
Develop and test MQL5 techniques to manage orders and positions, including expiry of pending orders, and boolean checks for existing positions or orders by symbol, magic number, and type.
Create a function to adjust the lot size after losses, doubling the volume for each loss to recover funds, using history to track last lot and profit in martingale setting.
Create a tuple-type validator to clamp f_lot within lot_max and lot_min, ensuring the result uses the valid lot, and compile to verify correct lot selection.
Fetch tick data with mql tick and symbol info tick, assess news, calculate the trade lot, and place buy stop or sell stop orders with stop loss and take profit.
Test the news ea on the hourly chart from January 2023 to May 2024, fix parameter and formatting errors, and review backtest results including profit, drawdown, hedging, black swan considerations.
Develop a live-trading news expert advisor in mql5 that pulls market data and calendar news, applies risk and trade-management parameters, and manages pending orders.
Conclude with coding the news filter and testing a news-based strategy in MQL5, highlighting the economic calendar's role in trading success and the need for capable, well-informed traders.
News are the daily fuel for fear and greed in our daily lives. News determine how we plan for our future and anticipate our fortunes or peril. The informed are always safe, that’s the law of the jungle.
The forex market is a beast fueled by nothing other than fear and greed. It represents the true nature of human behavior. It’s a competitive jungle where the fittest are poised to survive. It’s a chamber of fortunes and pain, married to one another like yin and Yang.
Because news promotes behaviors of fear and greed, it is news that drives chaos and volatility in the forex market. It is news that causes irrational behavior of the markets and it is news that causes the markets to trend. Without news, there would be no volatility which attracts investors to the forex market, there would be no greed that causes buying and no fear that causes selling. Markets would stagger and stagnate for long periods, losing their appeal as opportunity makers.
News that affects the forex market is collected within the Economic calendar. For algorithmic traders, reliable and timely news is paramount and this is where the MQL5 economic calendar shines. This is mainly because even though economic data websites are everywhere, integrating them correctly into your Expert Advisors (EAs) can be very challenging.
MQL5's calendar resides within the MetaTrader platform itself. This eliminates the need for external data feeds, ensuring seamless integration and minimal latency. Your EA receives economic event updates directly, allowing for near-instantaneous responses to market shifts triggered by data releases.
Also the MQL5’s economic calendar offers a dedicated set of functions specifically designed for EAs. These functions allow you to efficiently query the calendar for upcoming events, filter by specific data types (interest rates, employment figures, etc.),and extract crucial details like release time and forecast values. This streamlined approach saves you the hassle of parsing external website data, ensuring your EA focuses its processing power on analysis and trade execution.
By relying solely on MQL5's internal calendar, you eliminate the potential security risks associated with external data sources. Third-party websites can be susceptible to hacking or manipulation, which could introduce errors or misleading information into your EA's decision-making process. MQL5's secure environment mitigates these risks, ensuring the integrity of the data your EA uses.
In this course, we shall start by creating a news filter which basically reduces the risk of radical volatility caused by news releases in mean reversion strategies which suffer great losses in biased markets. In creating the news filter, we shall focus on how to get past economic data, future economic data and how to access particular elements like news values from the data.
We shall then code a script that collects past news data and stores it into a csv file. We shall then code an expert advisor that takes data from the stored news csv file and enters trades based on it in the strategy tester, allowing us to test our trading ideas and strategies based on news events using the Metatrader strategy tester. We shall finally adapt our tested strategy to live market trading so that it can be implemented for live news events.
For those that are still finding their way with MQL5, as long as you understand the basics of MQL5, this course is for you. We will patiently guide you through every step of the strategy development process and walk you through every line of code we shall craft. Hopefully, by the end of the course, you will have gained the necessary skills to code similar trading strategies and be able to appreciate how manipulating News data can improve your strategies.
So hit hard on that enroll button now and join me in this incredible journey of coding a News trading filter and news associated trading strategies.