Time Management HELP

 

Hi to all…

I’m starting with an idea of a EA…

The trading part is all most done, but now I want to put a TIME MANAGEMENT for it to trade only between 9.30 and 17.30 (broker time).

Does any one have a script for this???

Regards,

Fly

 

datetime Trade_Start_Time,   Trade_End_Time;

Trade_Start_Time = iTime(Null,PERIOD_D1,0) + (60_seconds*60_minutes*9) + (60_seconds*30_minutes);

Trade_End_Time = iTime(Null,PERIOD_D1,0) + (60_seconds*60_minutes*17) + (60_seconds*30_minutes);

if ( TimeCurrent() >=  Trade_Start_Time   &&    TimeCurrent() <= Trade_End_Time)

OrderSend();

 

Yeah something like that just off the top of my head. You can add day of the week b4 the if statements if you dont wanna trade on weekends or exclude days.

 
Day of Week:
extern string   Trade.Days      = "012345";
...
string  DOW = DayOfWeek();      if (StringFind(Trade.Days, DOW)<0) return;
 

StringFind()... that is a neat solution. I would never have come up with that. Thanks for sharing.

V

 
Yeah, thats what i taught too. 2 lines of codes...quick and painless. I like it.
 

Many Tks!

 

The code I posted above seemed to work fine in the tester, but https://www.mql5.com/en/forum/127483 reports DayOfWeek always returns 5 in the tester.

So instead of DayOfWeek() perhaps TimeDayOfWeek(Time[0]) should be used instead.

 
WHRoeder:
Day of Week:
extern string   Trade.Days      = "012345";
...
string  DOW = DayOfWeek();      if (StringFind(Trade.Days, DOW)<0) return;

The problem with the above code is that you can't optimize it with other parameters, (like trading hours.) Therefor I changed it to a bit mask (Sunday=1, Monday=2, Tuesday=4, ..., Friday=32):
extern int      TradeHr.UTC.Start           =   0;
extern int      TradeHr.UTC.End             =   0;
extern int      Trade.Days                  =  63;
extern int      Srvr.To.UTC.Hours           =   0;
datetime TimeGMT(){ // TimeCurrent to GMT
    return(TimeCurrent()+ Srvr.To.UTC.Hours*3600);
}
...
datetime    now = TimeGMT();
    int     DOW = TimeDayOfWeek(now);   /* https://www.mql5.com/en/forum/127483
        // reports DayOfWeek() always returns 5 in the tester. No refresh?*/
    int     mask = 1;   for(int day=DOW; day>0; day--)  mask <<=1;
if ((Trade.Days & mask) == 0){      OK=false;StrApnd(reason,"|Day="+DOW);  }
int hrNow   =  TimeHour(now),
    hrBeg   = (hrNow-TradeHr.UTC.Start  +24)%24,
    hrEnd   = (hrNow-TradeHr.UTC.End    +24)%24;
if (hrBeg > hrEnd){ int T=hrBeg-24; OK=false;StrApnd(reason,"|HR"+T);      }
 

Hi

I need help on how to write MT 4 formula for MS Excel worksheet in multiple time-frames to be able to see what a currency pair has done in the last 12 hours, 24 hours, last week and month in the for of heat-map visually just like it is presented on this website http://finviz.com/forex_performance.ashx so that you know the strength and weakness of different pairs over a period of time, be able to know which one is trending, consolidating and stall.

Thanks.

Reason: