+ Reply to Thread
Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Date range exclusion filter

  1. #1
    Member
    Join Date
    May 2009
    Posts
    30

    Default Date range exclusion filter

    Hi All,

    I'm looking for a simple way to program not trading a given date range. For instance, skip the week of Thanksgiving or skip the last two weeks of the year. It seems individual dates would be easy to program, but I'm having a block thinking how to exclude a date range and then multiple date ranges for what I would call a holiday filter.

    Thanks for your help.

    SN
    Last edited by sumnone; 01-09-2012 at 07:55.

  2. #2
    Member
    Join Date
    May 2009
    Posts
    30

    Default

    Here's what I came up with, but don't like the loop:

    extern bool useholidayfilter=true;

    I then mimicked the usetimefilter array except couldn't come up with a clever way to do the array indexes. So, I put this below the usetimefilter array.

    //Holiday Filter Dates
    if(useholidayfilter){
    hstop[0]=D'2012.01.13';hstart[0]=D'2012.01.17'; //Martin Luther King, Jr.'s Birthday
    hstop[1]=D'2012.02.17';hstart[1]=D'2012.02.21'; //Washington's Birthday
    hstop[2]=D'2012.05.25';hstart[2]=D'2012.05.29'; //Memorial Day
    hstop[3]=D'2012.07.01';hstart[3]=D'2012.07.07'; //Independence Day
    hstop[4]=D'2012.08.31';hstart[4]=D'2012.09.04'; //Labor Day
    hstop[5]=D'2012.10.05';hstart[5]=D'2012.10.09'; //Columbus Day
    hstop[6]=D'2012.11.09';hstart[6]=D'2012.11.13'; //Veterans Day
    hstop[7]=D'2012.11.16';hstart[7]=D'2012.11.27'; //Thanksgiving Day
    hstop[8]=D'2012.12.14';hstart[8]=D'2013.12.31 23:59:59'; //Christmas
    hstop[9]=D'2013.01.01';hstart[9]=D'2013.01.15'; //New Years
    }

    Then the following, I added to the checktime function after the gmtshift IF statement. Since I couldn't find a clever way to do the array indexes, I have to loop through each array value to see if we have a match. Therefore, the more dates you add, the slower this section becomes:

    if(useholidayfilter){
    int count=ArraySize(hstop);
    for(int i=0; i<count; i++){
    if(TimeCurrent()>hstop[i] && TimeCurrent()<hstart[i])return(true);
    }
    }

    This seems to work ok, but maybe someone can come up with something more clean to eliminate the loop.

+ Reply to Thread

Similar Threads

  1. MA Range EA
    By funyoo in forum Expert advisors backtesting
    Replies: 0
    Last Post: 02-24-2011, 18:12
  2. There is market time, but what about market date???
    By dennerle in forum MQL programming
    Replies: 2
    Last Post: 09-20-2010, 03:27
  3. XMA filter - new trend filter, check it out
    By Metatrader7 in forum Ideas for expert advisors
    Replies: 13
    Last Post: 05-09-2010, 08:06

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts