Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20
 1 Attachment(s)    

Thread: Time filter

  1. #11

    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
    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

    Default

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

  4. #14
    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

    Default

    awesome! thank you very much!

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

    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,003

    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

    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.

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

    Default

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

Similar Threads

  1. Mandor EA time filter
    By EaLabSpain in forum Ideas for expert advisors
    Replies: 0
    Last Post: 04-10-2012, 20:36
  2. Add a time filter
    By sunyc1982 in forum MQL programming
    Replies: 3
    Last Post: 02-27-2011, 18:53
  3. Time filter code
    By himnoor in forum MQL programming
    Replies: 0
    Last Post: 12-21-2010, 02:55
  4. Req. Trading Time Filter
    By Trint in forum Ideas for expert advisors
    Replies: 0
    Last Post: 01-23-2010, 09:19
  5. Add a time filter
    By funyoo in forum MQL programming
    Replies: 12
    Last Post: 05-28-2009, 22:26

Tags for this Thread

100, add, broker, color, date, dmi, expert, guide, magic, programming, server, stop, test, thank you, time, timefilter, trading

Posting Permissions

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