FFCalMod - Updated news indicator / library with backtesting

sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

FFCalMod - Updated news indicator / library with backtesting

Post by sergiensergien »

Hi to everybody!

First post in this nice trading forum.

As many of you already know, there is a nice news indicator called FFCal, developed initially by DerkWehler at the FF forum (http://www.forexfactory.com/showthread.php?t=19293).

I've observed that in some of the EA's there is talk to implement a news filter, so I have tinkered (a lot) with the original indicator to have something that can easily be incorporated to an EA without problems (probably I'll tinker a little with one of the EAs myself to make some tests).

Here is my modified version of the FFCal indicator, called FFCalMOD. Please be aware that the code has been heavily modified to suit my needs (especially backtesting), so you can consider it almost a "fork" of the original.

Changes introduced are:
  • Related Calencar functions externalized to library. This library is easily usable from an EA.
  • The indicator / funtions have been abstracted from the source used (ForexFactory or DailyFX).
  • Additional graphic capabilities added (future events lines, coloring of vertical lines, ...).
  • Many parts of the code have been rewriten from scratch.
  • Backtesting capabilities added. The indicator can instruct the library to use an External Time reference. This reference can be easily provided by the EA under test adding the following line of code at the beginning of the start() function:

    Code: Select all

    if(IsTesting()) GlobalVariableSet("_TimeReference", TimeCurrent());
    TimeLocal() Returns local computer time as number of seconds elapsed from 00:00 January 1, 1970. But at the testing, local time is modelled and is the same as the modelled last known server time. This means TimeLocal() = TimeCurrent() when testing, but many times TimeLocal() != TimeCurrent in real.
    Additionally, the time is only modeled into the EA context. If you backtest visually, the indicators set at the chart are not called by the EA, but the chart directly. The External Time Reference is my solution to this problem.
  • ForexFactory XML files are kept on a permanent basis with different name on a daily basis. This is done so to have backtesting capabilities for FF XML files.
  • Added daylight saving zone awareness. It's needed to differenciate between the timezone of the broker and our time zone. The original indicator did not have into account that there can be GMT difference between the criminal and us. The library uses a file called daylightsavings.xml to keep track of the lightsaving periods.
  • And many other changes ...
To do:
  • Depurate visual filters to show only selected news.
Please be aware the code can have some bugs, as I'm not a profesional programmer. If you see any bugs or have any suggestions, or better still, code, for improving this indicator, please let me know,

All the needed files are at the attached ZIP file. Just copy the files at the corresponding directory under experts.

UPDATE (13/1/2014)

Changes in v20d2:
  • Corrected libraries directory.
  • Added functions for easiest access from EA (see example below).
In order to use the library with an EA, these are the instructions.

Please be aware that this is only a sample template that does not implement a filter for the current pair. In other words, it sets a time window for any event of the selected criticity.

Something like this ...

At the beginning for configuration:

Code: Select all

#include "LibNEWS_B6a.mqh"
extern string  __MODULE_NEWS_FILTER__           = "____________________________________________________";
extern string  __MODULE_NEWS_FILTER_title__     = "=== NEWS FILTER SECTION ===                         ";
extern bool NEWS_UseNewsFilter               = false;
extern string __events_selection__                  = "--- NEWS EVENTS SELECTION ---";
extern int NEWS_SelectEventsWithCriticity   = 3;       // 0: Everything; 1: Low; 2: Medium; 3: High
extern string __timezones_configuration__        = "--- SOURCE AND TIMEZONES CONFIGURATION ---";
bool NEWS_AutoGMTZones                       = false;   // Set this to FALSE. It does not work ... yet!
extern int NEWS_LocalGMTZone                      = 1;       // GMT+X
extern int NEWS_BrokerGMTZone                    = 2;       // GMT+Y
extern bool NEWS_UseDailyFXAsSource               = true;    // Set this to TRUE when backtesting
extern bool NEWS_UseGlobalTimeReference         = true;    // Set this to TRUE when back
extern string  __events_window__                     = "--- TRADE WINDOW FOR EVENTS ---";
extern int NEWS_MinutesBeforeNews               = 7;      // Set to -1 for no Alert
extern int NEWS_MenutesAfterNews               = 21;          // Set to -1 for no Alert
At the init() function:

Code: Select all

  
// Initialization of the NEWS FILTER LIBRARY
NEWSSetTimeReference (NEWS_UseGlobalTimeReference);
NEWSSetTimeOffset (NEWS_AutoGMTZones, NEWS_LocalGMTZone, NEWS_BrokerGMTZone);
NEWSInitLibrary ();
At the deinit() function:

Code: Select all

// News filtering logic DEINIT
NEWSDeinitLibrary();
// External time reference DEINIT
GlobalVariableDel("_TimeReference");
At the beginning of the start() function:

Code: Select all

// Code for the external Time Reference ...
if(IsTesting()) GlobalVariableSet("_TimeReference", TimeCurrent());
// Perform news checks once per minute
// (Only needed if the NEWSMOD filters has been included.
static int previousMinute;
if (NEWS_UseNewsFilter) {
   if (TimeMinute(AltTimeLocal()) != previousMinute && !IsTesting()) {    
      previousMinute = TimeMinute(AltTimeLocal());
      NEWSRefreshEvents (NEWS_UseDailyFXAsSource);
   }
}
And add this function in order to check if trading is allowed:

Code: Select all

bool DoNewsAllowsTrade() {
   if (NEWS_SelectEventsWithCriticity < 0)
      return (true);
   bool skipThisEvent = false;
   datetime now = TimeLocalToGMT(AltTimeLocal());

   // Get the currency pair, and split it into the two countries
    string pair = Symbol();
    string country1 = StringSubstr(pair, 0, 3);
    string country2 = StringSubstr(pair, 3, 3);

   // string previousEvent[8];
   // int previousEventIndex = NEWSPreviousEvent (3, previousEvent);
   // int previousTime = StrToTime (previousEvent[NEWS_GMT]);
   static datetime previousTime = 0;
   static datetime actualTime = 0;

   string nextEvent[8];
   int nextEventIndex = NEWSNextEvent (NEWS_SelectEventsWithCriticity, nextEvent);
   datetime nextTime = StrToTime (nextEvent[NEWS_GMT]);

   // Test against filters that define whether we want to skip the selected announcement
   if (country1 != nextEvent[NEWS_COUNTRY] && country2 != nextEvent[NEWS_COUNTRY])
      skipThisEvent = true;
      // if (ReportAllForAll)
        //    skipThisEvent = false;
        // if (!SelectSpeaksEvents && (StringFind(eventData[NEWS_TITLE], "speaks") != -1 ||
        //                        StringFind(eventData[NEWS_TITLE], "Speaks") != -1) )
        //    skipThisEvent = true;
    if (nextEvent[NEWS_TIME] == "All Day" ||
        nextEvent[NEWS_TIME] == "Tentative" ||
        nextEvent[NEWS_TIME] == "")
        skipThisEvent = true;
   if (now > actualTime && !skipThisEvent) {
      previousTime = actualTime;
      actualTime = nextTime;
   }

   if (previousTime > 0 && nextTime > 0)
      if ((now - previousTime) < (NEWS_MenutesAfterNews * 60 ) || (nextTime - now) < (NEWS_MinutesBeforeNews * 60))
         return (false);

   return (true);
}
And that's all!

Constructive feedback will be always welcomed!!!

Best & kind regards,
Sergien
You do not have the required permissions to view the files attached to this post.
Last edited by sergiensergien on Fri Mar 07, 2014 9:44 pm, edited 2 times in total.
dudest
Trader
Posts: 1847
Joined: Tue May 08, 2012 2:37 pm

Re: FFCalMod - Updated news indicator / library with backtes

Post by dudest »

Huge & nice effort Sergien!, good show :)
User avatar
monkeh
Trader
Posts: 72
Joined: Fri May 04, 2012 2:40 pm

Re: FFCalMod - Updated news indicator / library with backtes

Post by monkeh »

well done!
:clap:
thank you! :hi:
sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

Re: FFCalMod - Updated news indicator / library with backtes

Post by sergiensergien »

Added some new functions and corrected a directory mistake.

If anybody is using the library, please, constructive feedback will be appreciated!

B&KR,
Sergien
sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

FFCalMod - Updated news indicator / library with backtesting

Post by sergiensergien »

Hi!

Here is an updated version of my "interpretation" of this indicator, as posted previously here.

Main changes from previous versions:
  • Compiled and modified for Build 600.
  • Changed mechanism for getting HTTP pages (see previous point).
  • Changed name of indicator and library to NEWS_B6 to avoid confussion.
  • Location of files follows Build 600 guidelines
To install copy all the files to their correspondent directory.

Have fun!
You do not have the required permissions to view the files attached to this post.
pgr45za
Posts: 1
Joined: Thu Feb 27, 2014 10:09 pm

FFCalMod - Updated news indicator / library with backtesting

Post by pgr45za »

Hi,

I'm having trouble following your instructions to integrate this with an EA (build 610).

1) Is the library you point to in include correct?

2) Why can't I just:

int MinSinceNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,1,0);
int MinToNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,1,1);

int ImpactSinceNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,2,0);
int ImpactToNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,2,1);


Thanks
sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

FFCalMod - Updated news indicator / library with backtesting

Post by sergiensergien »

Hi!

Here is an updated version of my "interpretation" of this indicator, as posted previously here: http://www.forexfactory.com/showthre...37#post7192537

Main changes from previous version v20f:
  • Solved problem with Dashboard not showing some of the lines. The developer of the object funtions in Empty4 decided it was best not to show the data if it was over a maximum length ...
As requested by "ill_be_back" at FF:

What I had in mind was that Lets say we have the next upcoming news GBP construction PMI,

If we had Six months history for reference, we could just go to the inputs of the indicator select GBP true,

& select 6 months( which needs to be added) & GBP construction PMI (key words, which needs to be added) then we could see how the price reacted Before , During & after for the last 6 months
After we have done our preparation we go back to the regular set up of the indi & all the previous lines would be erased


The following EXPERIMENTAL functions have been added:
  • EXPERIMENTAL: Added Keyword filter. If used with one word, i.e. PMI, will filter out all news without that word.
  • EXPERIMENTAL: Added GetLastNWeeksData to get last N weeks past data on screen. This only works if UseDailyFXAsSource is TRUE. I've also added some of the past info used to test this into the Files directory.
To install copy all the files to their correspondent directory.

Have fun!
You do not have the required permissions to view the files attached to this post.
sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

FFCalMod - Updated news indicator / library with backtesting

Post by sergiensergien »

pgr45za » Fri Feb 28, 2014 1:50 am wrote:Hi,

I'm having trouble following your instructions to integrate this with an EA (build 610).

1) Is the library you point to in include correct?

2) Why can't I just:

int MinSinceNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,1,0);
int MinToNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,1,1);

int ImpactSinceNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,2,0);
int ImpactToNews = iCustom(NULL,0,"NEWS_B6_v20f",true,true,false,true,true,2,1);


Thanks

Hi,

As far as I know it is correct as I'm using it in my own EAs ....

Can you provide mi with a "dummy" EA to insert the code into?

Best & kind regards,
Sergien
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

FFCalMod - Updated news indicator / library with backtesting

Post by milanese »

sergiensergien » Thu Mar 06, 2014 2:01 pm wrote:Hi!

Here is an updated version of my "interpretation" of this indicator, as posted previously here:
....
To install copy all the files to their correspondent directory.

Have fun!
Thank you for posting this here :good:

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
sergiensergien
Trader
Posts: 14
Joined: Sat Dec 28, 2013 10:39 am

FFCalMod - Updated news indicator / library with backtesting

Post by sergiensergien »

Hi, pgr45za

I've updated instruction at the first post.

Calling the indicator as you propose is always an option. The buffers are filled as follows:

Code: Select all

double ExtMapBuffer0[]; // Contains (minutes until) each news event
double ExtMapBuffer1[]; // Contains only most recent and next news event ([0] & [1])
double ExtMapBuffer2[]; // Contains impact value for most recent and next news event
Best & kind regards,
Sergien
Post Reply

Return to “Indicators”