Introduction

This is multi period allowance trade time filter. It’s usable when you only want to trade in Asian Session, and/or London session, and/or New York Session.

Parameters

AutoGMTOffset
Bool: Indicate if you want auto GMT offset turned on or off. Turn off during back testing.

Manual GMT Offset
Double: If AutoGMTOffset is turned off, indicate what your manual GMT offset would be.

How do you determine your manual GMT offset?

Click on the following link to find the GMT. http://www.greenwichmeantime.com.
Find your brokers time by seeing it displayed in your trading platform under Market Watch (the top left hand side of your MetaTrader4 platform). Now do a little math to find out the hourly difference betweem the GMT and your brokers time. That is the offset. If the market watch time is ahead of the GMT then your setting is a positive number. But don’t use a plus sign. Just write as you normally would for a positive number. If your broker’s time is behind the GMT put a negative sign in front of the number. I’m using Primebank, and its market watch info says 2:00 am when the GMT says  23:00 PM, which means that Primebank is ahead by +3 hours, so I would indicate 3 in the manual offset.

UseTradingHours
Bool: Whether or not to use the time filter. It is defaulted as off. 

TradeAsianMarket
Bool: Whether or not to trade Asian session. 

StartTime1
Double: Don’t Trade before this time. Defaulted at 21:00, the start of Asian Session, if you include Australia. Sydney starts at 21.00, and Tokyo starts at 23.00 GMT.  

EndTime1
Double: Don’t Trade after this time. Defaulted at 07.00, the start of the European Session.  Note: The Tokyo session continues on for 1 more hour to end at 08.00, so if you are interested in trading this session in its entirety, you should indicate from 23:00 to 08.00. 

TradeEuropeanMarket
Bool: Whether or not to trade European session.

StartTime2
Double: Don’t Trade before this time. Defaulted at 7.00 GMT, the start of the London Session, though Germany does not open till 08.00.  

EndTime2
Double: Don’t Trade after this time. Defaulted at 12.00 GMT, the start of the New York Session. Note: The European Session continues till 16.00, so if you are interested in trading this session in entirety, you should have your defaults from 7.00 to 16.00. 

TradeNewYorkMarket
Bool: Whether or not to trade the New York session.

StartTime3
Double: Don’t Trade before this time. Defaulted at 12:00, the start of the New York Session in GMT, which is 8:00 EST. Note that the NY stock exchange does not open till 9:30 EST, or 13.30 GMT, and the first hour and half (from 9:30 to 11:00 EST, or 13:30 to 15:00 GMT) is heavy trading, lots of liquidity.  

EndTime3
Double: Don’t Trade after this time. Defaulted at 21.00, the end of the New York session, the closing bell in New York. 

How do you fine tune the session times?

There are two ways. One way is via research and estimation. You look at the time zone charts themselves, looking for their distinct characteristics for the best possible time zones for your system.  For instance, you might want to trade a scalper only during the low liquidity Asian session, or a breakout system in the high liquidity confluence sessions (when the Asian/European sessions overlap, or when the European/New York sessions overlap). You can find these time zone charts in our own time zone page, or at http://www.forexmarkethours.com.

Another, more accurate method, is via optimization. Select a session as true, and the others as false, and optimize the start and end parameters for that session. For instance, if you were wanting to trade only the Asian session, and you wanted to know the best hours to trade with your system, I would keep the StartTime1 at 22.00 and optimize EndTime1 from 22 through 7, and the optimization report will detail which hours work best for my system.

MT4 Code Snippets

Paste this code near top of source file

#import “Kernel32.dll”
void GetSystemTime(int& a0[]);

Paste this code in define variables section

extern string _6 = “— Trading Hours —“;
extern bool AutoGMTOffset = TRUE;
extern double ManualGMTOffset = 0;
extern bool UseTradingHours = true;
extern bool TradeAsianMarket = true;
extern double StartTime1 = 22.00;
extern double EndTime1 = 07.00;
extern bool TradeEuropeanMarket = true;
extern double StartTime2 = 07.00;
extern double EndTime2 = 12.00;
extern bool TradeNewYorkMarket = true;
extern double StartTime3 = 12.00; // 8:00 EST
extern double EndTime3 = 17.00;
int gmtoffset;
string gs_548 = “”;

Paste this code after start() function

if (!IsTesting() && AutoGMTOffset == TRUE) gmtoffset = GMTOffset();
else gmtoffset = ManualGMTOffset;

string ls_52 = “Your Strategy is Running.”;
string ls_60 = “Your Strategy is set up for time zone GMT ” + gmtoffset;
string ls_76 = “Account Balance= ” + DoubleToStr(AccountBalance(), 2);
string ls_84 = ” “;

Comment(“\n”,
“\n”, ” “,
“\n”, ” “,
“\n”, ” “, ls_52,
“\n”, ” “, ls_60,
“\n”, ” “, ls_76,
// “\n”, ” “, ls_77,
“\n”);

Paste this code by itself, at end of source file, outside of start() function

int TradeTime()
{
if (!IsTesting() && AutoGMTOffset == TRUE) gmtoffset = GMTOffset();
else gmtoffset = ManualGMTOffset;

int TradingTime=0;
int CurrentHour=Hour(); // Server time in hours
double CurrentMinute =Minute(); // Server time in minutes
double CurrentTime=CurrentHour + CurrentMinute/100; // Current time
double CurrentTime1 = CurrentTime + gmtoffset;

if (CurrentTime1==0) CurrentTime=00;
if (CurrentTime1<0) CurrentTime1 = CurrentTime1 + 24;
if (CurrentTime1 >= 24) CurrentTime1 = CurrentTime1 – 24;

if (!DaytoTrade()) return(false);
if (UseTradingHours==true)
{
if (TradeAsianMarket==true)
{
if(StartTime1 < endtime1){
if(CurrentTime1 >= StartTime1 && CurrentTime1 <= EndTime1)
TradingTime=1;}

if(StartTime1 > EndTime1){
if(CurrentTime1 >= StartTime1 || CurrentTime1 <= EndTime1)
TradingTime=1;}
}

if (TradeEuropeanMarket==true)
{
if(StartTime2 < endtime2){
if(CurrentTime1 >= StartTime2 && CurrentTime1 <= EndTime2)
TradingTime=1;}

if(StartTime2 > EndTime2){
if(CurrentTime1 >= StartTime2 || CurrentTime1 <= EndTime2)
TradingTime=1;}
}

if (TradeNewYorkMarket==true)
{
if(StartTime3 < endtime3){
if(CurrentTime1 >= StartTime3 && CurrentTime1 <= EndTime3)
TradingTime=1;}

if(StartTime3 > EndTime3){
if(CurrentTime1 >= StartTime3 || CurrentTime1 <= EndTime3)
TradingTime=1;}
}
}

else
TradingTime=1;

return(TradingTime);
}

Lastly, insert function TradeTime() someplace in code as part of entry condition

Example:

if (BuyCondition1 && TradeTime() )
OpenBuy=true;