gooly: Is that correct - it makes things a lot easier :)
- Correct for NY, don't know about all the others. Easier, hardly!
- Mt5 has TimeGMT (a post says it doesn't work.) Mt4 doesn't have that (docs.) See my code for my implementation.
- My code handles NY DST both current and pre 2006 (for back testing.)
- You now have to do the same thing with each other country. Every country handles DST differently. (When I did mine, there was no MS DLL call available, IIRC Win8 might but then you've got a limitation.)
Sure its quite easy as this can be used for NY, London, Sidney and Tokyo (no DST!):
datetime tNY = TimeGMT() + NYShift + DST_USD; if ( TimeDayOfWeek(tNY)>0 && TimeDayOfWeek(tNY)<6 && TimeHour(tNY) >=8 && TimeHour(tNY) < 16 ) return(true);
I think from GMT based on my pc which has the advantage that I get valid results even if the market is closed!
Thank you, I know your code but Do you have hist. data before 2007? If so would they be meaningful for today too or haven't the markete changed too much?
I have developed s.th. different derived from what I have found somewhere else.
You can check if you want. Four NY only one solution post 2006:
void timeshift(string zone, datetime t) // no coloring ??? ... datetime spr, aut, int d, y = TimeYear(t); if ( zone == "EUR" ) { d = 31 - MathMod((4 + MathFloor(5*y/4)), 7); // The equation (in code) for March is: spr = StrToTime(""+y+".03."+d+" 03:00"); if ( t < spr ) { DST_EUR = 3600; nxtSwitch_EUR = spr; return; } d = 31 - MathMod((1 + MathFloor(5*y/4)), 7);//The equation (in code) for October is: aut = StrToTime(""+y+".10."+d+" 03:00"); if ( t < aut ) { DST_EUR = 0;// 0 sec nxtSwitch_EUR = aut; return; } y++; d = 31 - MathMod((4 + MathFloor(5*y/4)), 7); // The equation (in code) for March is: spr = StrToTime(""+y+".03."+d+" 03:00"); if ( t < spr ) { DST_EUR = 3600; nxtSwitch_EUR = spr; return; } Print("ERROR for ",zone," @ ",TimeToStr(t)," DST: ",DST_EUR," nxtSwitch: ",TimeToStr(nxtSwitch_EUR)," winter: ",TimeToStr(aut)," spring: ",TimeToStr(spr)); return; } if ( zone == "USD" ) { d = 14 - MathMod((1 + MathFloor(5*y/4)), 7); // The equation (in code) for March is: spr = StrToTime(""+y+".03."+d+" 03:00"); if ( t < spr ) { DST_USD = 3600; nxtSwitch_USD = spr; return; } d = 7 - MathMod((1 + MathFloor(5*y/4)), 7);//The equation (in code) for Nov. is: aut = StrToTime(""+y+".11."+d+" 03:00"); if ( t < aut ) { DST_USD = 0;// 0 sec nxtSwitch_USD = aut; return; } y++; d = 14 - MathMod((1 + MathFloor(5*y/4)), 7); // The equation (in code) for March is: spr = StrToTime(""+y+".03."+d+" 03:00"); if ( t < spr ) { DST_USD = 3600; nxtSwitch_USD = spr; return; } Print("ERROR for ",zone," @ ",TimeToStr(t)," DST: ",DST_USD," nxtSwitch: ",TimeToStr(nxtSwitch_USD)," winter: ",TimeToStr(aut)," spring: ",TimeToStr(spr)); return; } if ( zone == "AUD" ) { d = 7 - MathMod((4 + MathFloor(5*y/4)), 7); // The equation (in code) for Apr. is: spr = StrToTime(""+y+".04."+d+" 03:00"); if ( t < spr ) { DST_AUD = 0; // DST in Winter nxtSwitch_AUD = spr; if(debug!=0)Print(zone,"-DST for ",TimeToStr(t)," DST: ",DST_AUD," nxtSwitch: ",TimeToStr(nxtSwitch_AUD)); return; } d = 7 - MathMod((5 + MathFloor(5*y/4)), 7);//The equation (in code) for October is: aut = StrToTime(""+y+".10."+d+" 03:00"); if ( t < aut ) { DST_AUD = 3600;// 0 sec nxtSwitch_AUD = aut; if(debug!=0)Print(zone,"-DST for ",TimeToStr(t)," DST: ",DST_AUD," nxtSwitch: ",TimeToStr(nxtSwitch_AUD)); return; } y++; d = 7 - MathMod((4 + MathFloor(5*y/4)), 7); // The equation (in code) for Apr. is: spr = StrToTime(""+y+".04."+d+" 03:00"); if ( t < spr ) { DST_AUD = 0; // DST in Winter nxtSwitch_AUD = spr; if(debug!=0)Print(zone,"-DST for ",TimeToStr(t)," DST: ",DST_AUD," nxtSwitch: ",TimeToStr(nxtSwitch_AUD)); return; } Print("ERROR for ",zone," @ ",TimeToStr(t)," DST: ",DST_AUD," nxtSwitch: ",TimeToStr(nxtSwitch_AUD)," winter: ",TimeToStr(aut)," spring: ",TimeToStr(spr)); return; }
Gooly
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I was working to set up the various time-shifts when I realize that - and it's my question - all the market sessions start at 8h and end at 16h local time:
Tokyo 8 (GMT 23h +9h-TimeShift) .. 16 (GMT 7 +9h TimeShift)
New York 8h (GMT 13 -5h-TimeShift) .. 16 (GMT 16 -5h TimeShift)
Sidney 8h (GMT 21 +11h-TimeShift) .. 16 (GMT 05 +11h TimeShift)
London 8h (GMT 8 +0h-TimeShift) .. 16 (GMT 16 +0 TimeShift)
Is that correct - it makes things a lot easier :)
Gooly