+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 20 of 20
 1 Attachment(s)    

Thread: Time filter

  1. #11
    Member
    Join Date
    Jan 2009
    Posts
    126

    Default

    i am putting in the times in this format: HHMM (like 2100 to 0600). Its not working in back test. Am i doing something wrong?

  2. #12
    Ale
    Ale is offline
    Junior Member
    Join Date
    Aug 2009
    Posts
    14

    Default

    No overnight periods, must be endTime > startTime

    I've updated attachment in previous post - try new one

  3. #13
    Member
    Join Date
    Jan 2009
    Posts
    126

    Default

    ok..so its not possible to trade asian session? sorry for being so dumb...

  4. #14
    Ale
    Ale is offline
    Junior Member
    Join Date
    Aug 2009
    Posts
    14

    Default

    Quote Originally Posted by Viv108 View Post
    so its not possible to trade asian session?
    Try your time-settings with updated version - i've changed rules. But i can't test them here

    Sorry, I am not english-speaking, I'm english-reading man

  5. #15
    Member
    Join Date
    Jan 2009
    Posts
    126

    Default

    awesome! thank you very much!

  6. #16
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,455

    Default

    Here is another guide for the time filter,

    In the extern parameters, add :

    Code:
    extern int gmtshift=2;
    extern bool filter=false;
    extern int start=7;
    extern int end=21;
    extern bool tradesunday=true;
    extern bool fridayfilter=false;
    extern int fridayend=24;
    After the extern parameters, add :

    Code:
    int istart,iend;
    Before the ordersend functions, add :

    Code:
    istart=start+(gmtshift);if(istart>23)istart=istart-24;
    iend=end+(gmtshift);if(iend>23)iend=iend-24;
       
    if((tradesunday==false&&DayOfWeek()==0)
    ||(filter&&DayOfWeek()>0&&
    (
    (istart<iend && !(Hour()>=(istart)&&Hour()<=(iend)))||
    (istart>iend && !((Hour()>=(istart)&&Hour()<=23)||(Hour()>=0&&Hour()<=(iend))))))
    ||(fridayfilter&&DayOfWeek()==5&&!(Hour()<(fridayend+(gmtshift))))){
       return(0);
    }

  7. #17
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,455

    Default

    A new time filter :

    Extern parameters :

    Code:
    extern string timefilter="Time Filter";
    
    extern int gmtshift=1;                   // gmt offset of the broker
    extern bool generalfilter=false;         // enable time filter
    extern int starthour=7;                  // start hour to trade after this hour
    extern int startminutes=0;               // minutes of the start hour
    extern int endhour=21;                   // stop to trade after this hour
    extern int endminutes=0;                 // minutes of the start hour
    extern bool tradesunday=true;            // trade on sunday
    extern bool fridayfilter=false;          // enable special time filter on friday
    extern int fridayhour=21;                // stop to trade after this hour
    extern int fridayminutes=0;              // minutes of the friday hour
    Before start :

    Code:
    int nstarthour,nendhour,nfridayhour;
    string istarthour,istartminutes,iendhour,iendminutes,ifridayhour,ifridayminutes;
    datetime tstart,tend,tfriday;
    Before the ordersend functions :

    Code:
       if(generalfilter){
          nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;
          if(nstarthour<10)istarthour="0"+nstarthour;
          if(nstarthour>9)istarthour=nstarthour;
          if(startminutes<10)istartminutes="0"+startminutes;
          if(startminutes>9)istartminutes=startminutes;
          tstart=StrToTime(istarthour+":"+istartminutes);
    
          nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;
          if(endhour<10)iendhour="0"+nendhour;
          if(endhour>9)iendhour=nendhour;
          if(endminutes<10)iendminutes="0"+endminutes;
          if(endminutes>9)iendminutes=endminutes;
          tend=StrToTime(iendhour+":"+iendminutes);
       }
       if(fridayfilter){
          nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;
          if(nfridayhour<10)ifridayhour="0"+nfridayhour;
          if(nfridayhour>9)ifridayhour=nfridayhour;
          if(fridayminutes<10)ifridayminutes="0"+fridayminutes;
          if(fridayminutes>9)ifridayminutes=fridayminutes;
          tfriday=StrToTime(ifridayhour+":"+ifridayminutes);
       }
       if((generalfilter && (nstarthour<nendhour && TimeCurrent()<tstart || TimeCurrent()>tend) || (nstarthour>nendhour && TimeCurrent()<tstart && TimeCurrent()>tend))
       || (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))return(0);

  8. #18
    Junior Member
    Join Date
    Aug 2009
    Posts
    1

    Default

    Hy
    can help me please somebody
    i need to put in my ea the code to start trading at monday 15 gmt and end trading at friday at 15gmt
    thank you

  9. #19
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Quote Originally Posted by bagyi2002 View Post
    Hy
    can help me please somebody
    i need to put in my ea the code to start trading at monday 15 gmt and end trading at friday at 15gmt
    thank you
    You do this by including some code towards the top of the start() function which will get your EA to return without doing anything. Something like this:

    PHP Code:
    int start()   {

    if(
    DayOfWeek() == 0)  return;//this is Sunday
    if(DayOfWeek() == && Hour() <15 )  return;//this is Monday
    if(DayOfWeek() == && Hour() >= 15)  return;//this is Friday
    if(DayOfWeek() > 5)  return;//this is Saturday

    //the rest of your code goes here

    In addition to that you will need to do something about your broker's server time offset, as not every broker will be aligned to GMT. The easy way is to include an external parameter for this in global scope and add it to the 15.

    You will also need to think carefully about where you position this block of code within the start() function, as you may want to manage the SL of any open orders outside of these times.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  10. #20
    Junior Member
    Join Date
    Jan 2010
    Posts
    21

    Default

    How can i add different gmt settings for summer and wintertime?

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. 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
  2. Add a time filter
    By funyoo in forum MQL programming
    Replies: 12
    Last Post: 05-28-2009, 21:26
  3. Mesir Time EA
    By ahlan042000 in forum Expert advisors backtesting
    Replies: 14
    Last Post: 03-13-2009, 13:18
  4. 2 time frame stochs filter
    By automatic in forum Ideas for expert advisors
    Replies: 1
    Last Post: 12-19-2008, 18:11

Posting Permissions

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