Backtest newsfilter MT4 (Tutorial) (CSV)
-
Hello, I was really missing newsfilter for backtesting EA.
So I figured out how to make a newsfilter for backtesting, the newsfilter is reading a csv file and plots the news in the backtester chart.Link for the project: https://fxdreema.com/shared/iz0WMIVJd
Source code of the project: 0_1620495687291_Backtest newsfilter.mq4A screenshot of how it looks like in backtester:

If you use the project share link and not import the source code, here's the Constants and variables to add in pictures below:


Now you will need to download the news from FXStreet
First you choose the period for news, it looks like max period at time is 3 months. So if you want more than 3 months historical data then you will need to download all periods and merge it to a csv file.

After you choose period for news you will need to download the list, like in picture below:

After the newslist is downloaded, you will need to edit the list. I am using EmEditor for that.
Open your csv file in EmEditor (Ctrl-O)File open in editor:

First thing to do is to delete the first column, right click on the top of the first column and select delete column

Column deleted:

Now we need to split the date and time column, rightclick on the Date time column and select "Split column"

In the Split column window, make one space(spacrebar) in Seperator entry and click Ok button

The Date and Time(hours) is now splitted into 2 columns

Next step is to convert the Date format so MT4 can use it, open replace window (Ctrl-H)
In the "Find" you write exactly this string: ([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})
In the "Replace with" you enter exactly this string: \3.\1.\2
Choose regular Expressions and click on "replace all" button.
The list now looks like this:

Now select all columns in the first row, then rightclick and select "Delete" from the dropdown menu.

Ok!
The list is now finnished, you can now save it.
You need to put the list(csv file) in your terminal ./tester/files/ folder

In MT4 backtesting Expert properties remember to write in the file name for the file you just putted in the tester/files folder.

That's it, I hope you enjoy my newsfilter for backtesting

-
I forgot to delete the "Chart symbol for news" it's not in use, it reads the value from the chart. You can delete it.
-
@padletut Absolutely impressive!
Thank you very much for sharing. -
@l-andorrà Thank you
Sharing is caring 
-
thank you for sharing the script. pls note that your script will be failed for broker with several symbol like Gold, Silver. can modify your base_currency & quote_currency like this (in block "read news"):
filehandle = FileOpen(filename,FILE_READ|FILE_CSV,',');
base_currency = StringSubstr(Symbol(),0,3);
quote_currency = StringSubstr(Symbol(),3,3);
if(StringSubstr(Symbol(),0,4) == "GOLD"){
base_currency = "XAU";
quote_currency = "USD";
}
if(StringSubstr(Symbol(),0,6) == "SILVER"){
base_currency = "XAG";
quote_currency = "USD";
}
//base_currency = Symbol();
Print("base_currency: ", base_currency, ", quote_currency: ", quote_currency, ", Symbol: ", Symbol() ); -
@skytrader Thank you for sharing.
-
I am using icefxnews indicator in live trading with my EA but I would like to be able to backtest in mt4 with a news filter being considered.. would this fix you mention above make this possible?
-
@padletut The backtesting process very slow because you check csv file on every tick. Is it posible to check csv file on every candle? let say i am using h1 chart, so it check csv file every 1 hour, in this case backtest speed will be faster alot.
-
where can I put my block order ?