NewsRForestExpert
- Utilità
- Vitaliy Davydov
- Versione: 4.2
- Aggiornato: 17 settembre 2025
Trading assistant NewsRForestExpert v4.01
-
Purpose and principle of operation
NewsRForestExpert is a trading assistant for MetaTrader 5, using the built-in economic calendar
and the machine learning model "Random Forest" of the ALGLIB library (hereinafter simply "model").
The assistant:
-
in this version works only on the EURUSD currency pair timeframes M1 – M5;
-
loads news history for the selected period and forms training and test samples;
-
trains on the obtained data or loads an already trained model;
-
tests the quality of model training;
-
draws news on the chart, shows a control panel. On an additional chart shows quality metrics of training/testing;
-
in the Strategy Tester checks on history the quality of trading of the trained model, or conducts training of a new model with the possibility of optimizing model parameters and checking trading quality on history;
-
in real time receives new events, the trained model forms signals: SELL / OUT OF DEAL / BUY;
-
can work in auto-trading mode or with manual confirmation.
-
is not intended for intensive trading and scalping
-
Requirements
MetaTrader 5 terminal (current version).
Internet connection.
Availability of the built-in economic calendar in the terminal.
Quality price history M1/M5 for correct synchronization and calculations.
Allowed autotrading, if ExpertAutoTrade = true is planned.
Currency pair EURUSD, timeframes M1 – M5.
-
Installation and launch
Copy the files to the MT5 terminal directory. The assistant (*.ex5) should be located in MQL5/Experts.
Launch MT5 and drag the assistant onto a regular trading chart of the required instrument (EURUSD, period M1 - M5). Do not install on "service" charts.
Allow Algo Trading.
Press OK. When launched, the assistant:
-
will prepare "train" and "test" samples (train - for the specified period, test - the day of the end date of the train sample until the current time);
-
will train the model or load a saved one, depending on user settings;
-
will create a subwindow with a control panel, draw news on the chart;
-
will output to the log recommended dates for Strategy Tester;
Further the expert advisor will update news and forecasts by timer and new M1 bar. In non-auto-trading mode, a confirmation window will appear before opening a position.
-
Control panel on the chart
Elements:
-
four date pickers: start and end of the TRAIN period (for training) and start and end of the TEST period (for verification);
Buttons:
-
TRAIN - retrain the model on the selected TRAIN period. After training, "train" metrics/charts are built;
-
TEST - test the model on the selected TEST period. "Test" metrics/charts are built and recommended testing dates for Strategy Tester are printed to the log;
-
SAVE - save the current trained model (will overwrite the previous one);
Behavior:
-
subwindow and panel are restored if accidentally closed;
-
panel color adapts to the chart background (dark/light);
-
when incorrect dates are entered (start >= end − 1 day) a warning is issued.
-
Work in Strategy Tester
Before starting the tester, prepare the data:
Launch the expert advisor on a real chart, this will load historical economic calendar data and form training and test samples, according to the dates set in the user settings.
The log of the expert advisor will output recommended dates "Testing start date" and "Test completion date".
In Tester (Ctrl+R):
Set the expert advisor, symbol, mode "Every tick" or "1 Minute OHLC".
Set the recommended dates.
Parameter SavedModelUse:
true - load a previously saved model (StateRandomForest).
false - train anew on train. Option SaveStateModel = true will save the model trained in the Strategy Tester with the Tester suffix.
Inside the tester, the expert advisor synchronizes with event timestamps and executes trades at the "minute of release" of the news. News clusters are processed collectively as in real trading.
-
Input parameters
PARAMETERS OF PREPARATION OF INPUT FEATURES
**Begin date for loading economic calendar events (datetime) - start date of train.
**End date for loading economic calendar events (datetime) - end date of train.
**Minimum news importance (lov_level, medium_level, high_level) - minimum importance of events.
*Normalization of input features (without_normalization, MinMax_method, RobustScaler_method) - normalization of features (basic).
RANDOM FOREST PARAMETERS
Use a previously saved Random Forest (bool) - use a previously trained and saved model.
Selecting Random Forest Model Variants ( stationary model_1, random model_2) - forest implementation variant (for Free by default model_1).
Number of trees in a Random Forest (int) - number of trees in the model.
Share of data used to train the tree (double) - share of sample for training each tree "bootstrap" (0.2 - 0.95).
Number of features for each split (int) - number of features for each split (0 - 48; if -1 then auto)
Auto selection of the best Forest parameters (bool) - auto-selection of the best Forest parameters (beta option).
Minimum value of forecast probability (double) - threshold of model confidence in its forecast (0.2 - 0.95).
TRADE TRANSACTION PARAMETERS
*Expert Auto Trade (bool) - enable autotrading.
*Magic number (int) - magic number.
Lot size (double) - lot size.
Stop loss in points / Take profit in points (int, points) - SL/TP levels.
Slippage in points (int, points) - slippage.
TESTING PARAMETERS IN STRATEGY TESTER
*Save the state of the model trained in the strategy tester (bool) - save the model trained in the tester.
PARAMETERS OF VISUALIZATION OF ECONOMIC CALENDAR EVENTS
*Low importance – LowImpactColor.
*Medium importance – MediumImpactColor.
*High importance - HighImpactColor.
*Line width – line width.
*Line style – line style.
Footnote:
Parameters marked "*" in the source code do not affect optimization in the tester.
Parameters marked "**" must match in the tester and real settings,
otherwise work and optimization in the Strategy Tester will be incorrect.
-
Signal logic and trade execution
The model issues a forecast for each event: class and confidence (probability).
The final signal is built on the sum of "weighted votes" at the minute of the event release:
Weight = forecast confidence × news importance.
Sums are calculated for BUY and SELL for all events in the minute.
If BUY weights > SELL weights - BUY signal, if SELL weights > BUY weights - SELL signal, otherwise NEUTRAL.
The ProbabilityOfPrediction threshold cuts off forecasts with low confidence.
When a signal is given:
In non-autotrading mode, a confirmation window is displayed; if there is already a position in the same direction - notification, the trade is not repeated.
Before opening a new position, the expert advisor closes opposite positions of this MagicNumber.
Positions are opened by trade_signal with specified Lot/SL/TP/Slippage.
-
Generated files and names
Prefix: account number + currency pair + timeframe, for example "34764EURUSD_5_".
Main files created by the assistant:
StateRandomForestC.bin - saved trained model (real).
StateRandomForestTesterC.bin – saved trained model (tester).
FilteredCalendarData_train.bin / _test.bin - binary datasets (used by the Strategy Tester).
Additional files created by the assistant (control):
FilteredCalendarData_train.csv – dataset prepared for model training (real).
FilteredCalendarData_test.csv – dataset prepared for testing model quality (real).
DatasetDataForTester_train.csv – dataset prepared for model training (tester).
DatasetDataForTester_test.csv – dataset prepared for checking model operation in trading on history (tester).
ControlDatasetTester_test.csv — control dataset – for checking the correctness of data feed during testing in the Strategy Tester.
File location: C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\Common\Files
-
Verification and testing procedure
On a real chart:
Train the model (TRAIN) on the training period - get metrics and a heat map.
Check (TEST) on another, test period - get metrics and a heat map.
If the training results are satisfactory, save the model with the Save button
In the strategy tester:
Use the recommended dates from the log.
Run in the strategy tester, evaluate the trading results of the model.
Out-of-sample:
Move the period windows to avoid overfitting.
Periodically retrain the model to account for fresh data.
IMPORTANT!
Since quotes provided by one broker may differ from quotes of other brokers, it is recommended before using the NewsRForestExpert assistant in real trading to train the model using optimization.
The parameter Use a previously saved Random Forest must be set to false.
List of optimizable model parameters:
-
Number of trees in a Random Forest (10 – 4000);
-
Share of data used to train the tree (0.2 - 0.95);
-
Number of features for each split (0 - 48);
-
Minimum value of forecast probability (0.2 - 0.95).
Also at the user's discretion, parameters from the section "TRADE TRANSACTION PARAMETERS" can be optimized.
After optimization, reload the assistant setting the parameters of the best result.
-
Frequent problems and solutions
No data/signals:
Make sure the calendar is available (View → Calendar), internet is available.
Check the Begin/EndDateForLoad range, lower NewsImportance.
Low quality:
Increase TreeCount/TrainRatio, adjust ProbabilityOfPrediction.
Check the integrity of price history, broker time shifts.
Times do not match in the tester:
Use the recommended dates from the log after pressing TEST in real.
-
Limitations and features
Events with undefined time ("during the day") are excluded.
For reliable testing, use exactly the dates that the expert advisor outputs in the logs after data preparation on a real chart.
-
Checklist before enabling autotrading
Tested in Strategy Tester with prepared files and correct dates.
Checked metrics on TRAIN and TEST in the panel.
Optimized model parameters in the Strategy tester (if necessary).
Set a unique MagicNumber on each symbol/timeframe.
Selected SL/TP and lots according to volatility and risks.
ProbabilityOfPrediction optimized for the desired signal selectivity.
-
Notes on normalization
Basic normalization methods are available (Without/MinMax/RobustScaler).
Default parameters in this build are focused on stable operation; increase power (TreeCount, etc.) gradually.
-
Security and risk management
Start with demo and manual confirmation (ExpertAutoTrade = false).
Consider spread widening and slippage on news.
Regularly retrain the model and monitor out-of-sample results.
Automated trading carries significant risks of loss of funds. The NewsRForestExpert assistant uses news analysis and machine learning, but does not guarantee profit. Test the strategy on a demo account before real trading. You use the assistant at your own risk.
