trading hours and trading days

 

Dear all,

These lines below shows you an issue I am experiencing



I started my EA just a bit before 11 pm GMT on a sunday. There was a signal (according to my EA) but the EA did not take any trade until the midnight.

Now, I am not so familiar with the TimeDayOfweek function but apparently it codes integers a days of the week starting from zero which is sunday. I thought that the line << if(GetHour > StartTime && GetHour < EndTime && GetWeekday <6) >> would have made the EA trade starting from sunday night, but maybe I am not seeing something obvious. I m reasoning that if <6 this should mean to trade all days but not saturday.

Please find below my EA attached

 
killerkitten:

Dear all,

starting from zero which is sunday.


It's Monday you have to have it start at int 1.

There are no Sat or Sun times since TimeCurrent() servertime is frozen in weekend it will return 5 (Friday) all Saturday and All Sunday.

However, maybe you can filter Datetime daily bar and if it != Differs you can tell Monday has started.

 
killerkitten:

Hello,

 

I used that EA in the version as attached above, and yesterday it took at trade at 2AM (server time) which was just midnight (starting of monday).

 


 So you are suggesting I should put something like  if(GetHour > StartTime && GetHour < EndTime && 0< GetWeekday <6) 

 

I tried the back testing but it doesnt make any difference if I use 0< GetWeekday <6 or 1< GetWeekday <6 just to see which days are going to be excluded.

 

Sorry I am just learning mt4 what is  !=? not equal?

 

 

Dankje!

 Max 

No i dont suggest that && && &&

Also time is modeled in the back tester.

So you can compare bar open times if the daily candle open time has changed, you know a new day has started, but still not which day,

You can also simply switch the day of the week.

      switch(TimeDayOfWeek(TimeCurrent()))
        {
         case 0:// Sunday

            break;

         case 1:// Monday

            break;

         case 2:// Tuesday

            break;

         case 3:// Wednesday

            break;

         case 4:// Thursday

            break;

         case 5:// Friday

            break;

         case 6:// Saturday

            break;
        }

Which can be handy for future development if any...

 
Marco vd Heijden:

No i dont suggest that && && &&

Also time is modeled in the back tester.

So you can compare bar open times if the daily candle open time has changed, you know a new day has started, but still not which day,

You can also simply switch the day of the week.

Which can be handy for future development.

Hi,

 

I just want to add a bit more,

 

what confuses me is that yesterday the market opened at 11PM and the EA did not do anything. My mt4 charts started yesteday at 1:00AM the 18th since they are 2hours ahead ( I mean the charting on the server) so my confusion is how coudnt it not take any trade if the server time was already on monday?

 

thanks

Max 

 
killerkitten:

Hi,

 

I just want to add a bit more,

 

what confuses me is that yesterday the market opened at 11PM and the EA did not do anything. My mt4 charts started yesteday at 1:00AM the 18th since they are 2hours ahead ( I mean the charting on the server) so my confusion is how coudnt it not take any trade if the server time was already on monday?

 

thanks

Max 

if(CurrentTime>StrToTime(TradeStartTime) && CurrentTime<StrToTime(TradeStopTime) && GetWeekday <6)

Please use

datetime


In time comparisons.

Even better, it would be a lot simpler if you just use the daily integer 0-6.

Or the bar time.

datetime bar=iTime(Symbol(),PERIOD_D1,0);

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- compare
   if(bar!=iTime(Symbol(),PERIOD_D1,0))
    {
     Print(" NEW BAR!");
     bar=iTime(Symbol(),PERIOD_D1,0);
    }
  }
 
Marco vd Heijden:

Please use


In time comparisons.

Even better, it would be a lot simpler if you just use the daily integer 0-6.

Or the bar time.

Hi again

 

I appreciate your effort to help me! thanks!

 

however my knowldge of mt4 is very limited and I fail to see where I m supposed to embded those lines of code in my EA.

 

Sorry 

 
killerkitten:

Hi again

 

I appreciate your effort to help me! thanks!

 

however my knowldge of mt4 is very limited and I fail to see where I m supposed to embded those lines of code in my EA.

 

Sorry 

Wherever it's needed.

You can look in codebase for examples.

https://www.mql5.com/en/code

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
MQL5 Source Code Library for MetaTrader 5
 
Marco vd Heijden:

Wherever it's needed.

You can look in codebase for examples.

https://www.mql5.com/en/code

Sorry maybe it is stupid, but cant I just use localtime of my PC to avoid the issue? I mean the EA will follow that time to open a trade if conditions are met regardless of the fact that the server time is frozen? no?

 

I m not sure though

 

Max 

 

but maybe I am not seeing something obvious.

 extern string TradeStartTime = "1:05";

extern string TradeStopTime = "22:50";

What time has (sunday)candle with signal? 

 

Hi,

 in Mt4 the time is 2 hrs ahead so it was 1:10am. but it was actually 2 hrs ealier on my PC local time.

 

I think marco is right and the servers is updated at 0:01 on monday since the EA took a trade at 2AM sharp (0:00 GMT). However I fail to see how the EA would not take a trade if it had been receiving prices for the last hour on sunday. I put <6  in if(GetHour > StartTime && GetHour < EndTime && GetWeekday <6)  so zero (sunday) should be included.

 

 

 

Thanks 

 Max

 

What time has (sunday)candle with signal? 

Can you make screenshot of m1 candle with vertical line where was signal?