Finally, News Filter for MT5 in 1 easy to use Block !!
-
When they decide to allow sharing custom blocks, I will share this block here... a lot of people like it...
-
Thank you.
-
Really looking forward to this!
-
@quantengineer Hello, you can share the code in steps instead of we waiting for custom blocks to be shared...just like this tutorial
https://fxdreema.com/forum/topic/5866/finally-integration-of-news-filter-mt4-only?page=1
-
@quantengineer Maybe this is something that admin will add, for now though you could add the text here and say what part it's added to, then the next section etc.
-
You have done a great job sir. @QuantEngineer
If possible, share a short video of the build process so that others can rewrite it. -
@QuantEngineer Thanks for sharing this great method! can i have the code as well?
-
Hello Developers, I am happy to announce that I have done some improvements to this code and now it also displays the events on the chart, for reference...
Here is how the block looks like

Enjoy the latest main code
/* int minbeforeEvent = 60*24; int minAfterEvent = 60*24; string currency_code = ""; string country_code=NULL; //--- country code (ISO 3166-1 Alpha-2) ENUM_CALENDAR_EVENT_IMPORTANCE min_event_importance = CALENDAR_IMPORTANCE_HIGH; */ int FilteredEventsCount = 0; MqlCalendarValue values[]; //--- set the boundaries of the interval we take the events from datetime date_from=TimeCurrent() - (60*minbeforeEvent); datetime date_to=TimeCurrent() + (60*minAfterEvent); // 0 means all known events, including the ones that have not occurred yet //Print(TimeToString(TimeCurrent(), TIME_DATE|TIME_SECONDS), " -> Searching from ", TimeToString(date_from, TIME_DATE|TIME_SECONDS), " to ", TimeToString(date_to,TIME_DATE|TIME_SECONDS)); //--- request event history since the beginning to future time //if(verbose) Print("Begin Searching for events from " + TimeToString(date_from,TIME_DATE|TIME_SECONDS) + " to " + TimeToString(date_to,TIME_DATE|TIME_SECONDS) + " For Country " + country_code + ", currency " + currency_code ); if(!CalendarValueHistory(values, date_from, 0, country_code, currency_code)) { PrintFormat("Error! Failed to get events for country_code=(%s), currency=(%s)", country_code, currency_code); PrintFormat("Error code: %d", GetLastError()); } else { //if(verbose) Print("Found some events"); //PrintFormat("Received event values for country_code=(%s), currency=(%s) is (%d)", country_code, currency_code, ArraySize(values)); int total=ArraySize(values); string commentString = ""; for(int i=0; i<total; i++) { //if(values[i].impact_type < ) MqlCalendarEvent event; ulong event_id=values[i].event_id; if(CalendarEventById(event_id,event)) { if(((ENUM_CALENDAR_EVENT_IMPORTANCE)event.importance >= min_event_importance ) && (values[i].time <= date_to) ) { FilteredEventsCount++; commentString = commentString + TimeToString(values[i].time,TIME_DATE|TIME_SECONDS) + " " + event.name + " " + EnumToString((ENUM_CALENDAR_EVENT_IMPORTANCE)event.importance ) + "\n"; } } } commentString = "MQL5 returned " + FilteredEventsCount + " events from " + TimeToString(date_from,TIME_DATE|TIME_SECONDS) + " to " + TimeToString(date_to,TIME_DATE|TIME_SECONDS) + " For Country " + country_code + ", currency " + currency_code + "\n" + commentString; if(verbose) Comment(commentString); } if( FilteredEventsCount > 0 ) {~next~} else {~inext~} -
And here is how the chart will look like, in case the verbose mode is set to true

-
@QuantEngineer Thanks alot for the update!!
-
Impressive work. Thank you very much!
-
Thank you for the kind words of cheering, I appreciate your comments.
-
Thank you for providing this, @QuantEngineer
I pasted your latest code into the Studio, and created the parameters from the "out-commented" beginning of your code.
When I add the block to my project, however, it is empty. Am I missing something?


-
Hello @nk0815 , the issue that you are describing is related to how you are creating the "Parameters used in Block"... Look for some tutorials about this area of FXDreema Studio or learn about TYPES and you should be able to resolve that. I wish you a good week.
-
@QuantEngineer said in Finally, News Filter for MT5 in 1 easy to use Block !!:
/*
int minbeforeEvent = 6024;
int minAfterEvent = 6024;
string currency_code = "";
string country_code=NULL; //--- country code (ISO 3166-1 Alpha-2)
ENUM_CALENDAR_EVENT_IMPORTANCE min_event_importance = CALENDAR_IMPORTANCE_HIGH;
*/int FilteredEventsCount = 0;
MqlCalendarValue values[];
//--- set the boundaries of the interval we take the events from
datetime date_from=TimeCurrent() - (60minbeforeEvent);
datetime date_to=TimeCurrent() + (60minAfterEvent); // 0 means all known events, including the ones that have not occurred yet
//Print(TimeToString(TimeCurrent(), TIME_DATE|TIME_SECONDS), " -> Searching from ", TimeToString(date_from, TIME_DATE|TIME_SECONDS), " to ", TimeToString(date_to,TIME_DATE|TIME_SECONDS));
//--- request event history since the beginning to future time//if(verbose) Print("Begin Searching for events from " + TimeToString(date_from,TIME_DATE|TIME_SECONDS) + " to " + TimeToString(date_to,TIME_DATE|TIME_SECONDS) + " For Country " + country_code + ", currency " + currency_code );
if(!CalendarValueHistory(values, date_from, 0, country_code, currency_code))
{
PrintFormat("Error! Failed to get events for country_code=(%s), currency=(%s)", country_code, currency_code);
PrintFormat("Error code: %d", GetLastError());} else {
//if(verbose) Print("Found some events");
//PrintFormat("Received event values for country_code=(%s), currency=(%s) is (%d)", country_code, currency_code, ArraySize(values));
int total=ArraySize(values);
string commentString = "";
for(int i=0; i<total; i++)
{
//if(values[i].impact_type < )
MqlCalendarEvent event;
ulong event_id=values[i].event_id;
if(CalendarEventById(event_id,event))
{
if(((ENUM_CALENDAR_EVENT_IMPORTANCE)event.importance >= min_event_importance )
&& (values[i].time <= date_to)
)
{
FilteredEventsCount++;commentString = commentString + TimeToString(values[i].time,TIME_DATE|TIME_SECONDS) + " " + event.name + " " + EnumToString((ENUM_CALENDAR_EVENT_IMPORTANCE)event.importance ) + "\n"; } } }commentString = "MQL5 returned " + FilteredEventsCount + " events from " + TimeToString(date_from,TIME_DATE|TIME_SECONDS) + " to " + TimeToString(date_to,TIME_DATE|TIME_SECONDS) + " For Country " + country_code + ", currency " + currency_code + "\n" + commentString;
if(verbose) Comment(commentString);
}
if( FilteredEventsCount > 0 )
{~next~}
else
{~inext~} -
@QuantEngineer First I would like to thank you for sharing this wonderful code.
Secondly, I wanted to ask you, is there any way to implement this code so that it is possible to backtest the news data from the past? -
About the Backtester, aka Strategy Tester, it doesn't display the events because MQL5 inhibits the usage of the Functions and Methods used by the CALENDAR EVENTS group. On MQL official documentation, they say that they do it to speed up the tester.
One possible workaround would be to create a database or CSV File, run the algorithm in live data ahead of the test to fill in the database, then during the test, read the events from the database rather than reading from the source of the events. But because this seems very troublesome to have to run the algo live prior to the test, I didn't implement this solution... If anyone else has any other suggestions on how to overcome this limitation, please feel free to share and use the existing code to implement the solution on top of it.
-
Hi all,
Thanks for sharing the great work @QuantEngineer
Should this work as a simple test?

It's not working for me currently as trades are still taken 2 minutes before and after economic calendar events.
Any advice?
-
Has anybody been able to get this to work?
-
@QuantEngineer said in Finally, News Filter for MT5 in 1 easy to use Block !!:
System