Market_HoursM_sw

Download script
Market_HoursM_sw

This script is a specialized visual tool designed for the MetaTrader 4 platform to help traders identify active trading sessions across global financial markets. Instead of forcing you to manually track clock times in different time zones, it automatically maps out when major world markets are open.

Core Functionality

The primary purpose of this tool is to provide a clear, visual timeline of market activity. It monitors the current time and identifies specific "open" windows for several key geographical regions, including London, New York, Sydney, and Tokyo.

Key Features & Logic

  • Time Zone Customization: The script includes a user-adjustable offset. This allows you to sync the indicator with your specific broker's server time or your local time, ensuring that the market sessions align correctly with your live chart.
  • Multi-Session Tracking: It tracks four distinct primary market windows:
    • London: Highlights the European trading period.
    • New York: Highlights the American trading period.
    • Sydney: Highlights the Australian/Oceanian trading period.
    • Tokyo: Tracks the primary Japanese trading window.
  • Extended Tokyo Analysis: Unique to this script is a detailed breakdown of the Tokyo region. Beyond just the main session, it includes four additional "sub-windows" (labeled as 4H). These are designed to capture specific shifts in volatility or liquidity that occur during and around the Asian trading day.
  • Dynamic Visual Mapping: The logic works by scanning every historical bar on your chart. For each bar, the script checks if the time falls within the predefined opening and closing hours of a market. If it does, it marks that section of the chart; if not, it leaves it blank. This creates a clear visual "map" of when liquidity is highest in specific regions.

How it Benefits the User

By providing this visual data, the script helps traders:

  1. Identify Overlaps: Easily see when two markets are open simultaneously (such as the London/New York overlap), which is often a period of high volume and volatility.
  2. Plan Sessions: Quickly identify which regions are active at any given hour to better plan entries and exits.
  3. Simplify Timekeeping: Removes the need for external clocks or mental math regarding GMT offsets, as the script handles the conversion automatically based on your input.
11 Views
0 Downloads
0 Favorites
Market_HoursM_sw
//Market_HoursM_sw.mq4
#property 		indicator_separate_window
#property		indicator_buffers 8

#property		indicator_color1 Lime
#property		indicator_width1 3
#property		indicator_color2 Red
#property		indicator_width2 3
#property		indicator_color3 Blue
#property		indicator_width3 3
#property		indicator_color4 Yellow
#property		indicator_width4 3

#property		indicator_color5 BlueViolet
#property		indicator_color6 DodgerBlue
#property		indicator_color7 BlueViolet
#property		indicator_color8 DodgerBlue

#property		indicator_width5 0
#property		indicator_width6 0
#property		indicator_width7 0
#property		indicator_width8 0



#property 		indicator_maximum 9
#property 		indicator_minimum 0

extern int     GMTOffset      = 0;

// Buffers
double dLondonBuffer[];
double dNewYorkBuffer[];
double dSydneyBuffer[];
double dTokyoBuffer[];

double dTokyoBuffer1[];
double dTokyoBuffer2[];
double dTokyoBuffer3[];
double dTokyoBuffer4[];



int LondonOpen;
int LondonClose;   
int NewYorkOpen;  
int NewYorkClose; 
int SydneyOpen;   
int SydneyClose;  
int TokyoOpen;    
int TokyoClose;   

int TokyoOpen1;    
int TokyoClose1;   
int TokyoOpen2;    
int TokyoClose2;   
int TokyoOpen3;    
int TokyoClose3;   
int TokyoOpen4;    
int TokyoClose4;   




int init() {

	IndicatorShortName("Market Hours ");
	
	SetIndexBuffer(0,dLondonBuffer);
	SetIndexLabel(0,"London");
	SetIndexBuffer(1,dNewYorkBuffer);
	SetIndexLabel(1,"New York");
	SetIndexBuffer(2,dSydneyBuffer);
	SetIndexLabel(2,"");
	SetIndexBuffer(3,dTokyoBuffer);
	SetIndexLabel(3,"");

	SetIndexBuffer(4,dTokyoBuffer1);
	SetIndexLabel(4,"4H");

	SetIndexBuffer(5,dTokyoBuffer2);
	SetIndexLabel(5,"4H");

	SetIndexBuffer(6,dTokyoBuffer3);
	SetIndexLabel(6,"4H");
    
	SetIndexBuffer(7,dTokyoBuffer4);
	SetIndexLabel(7,"4H");




	
	return(0);
}

int start() {

   //set Times 
   LondonOpen     = GMTOffset + 7;
   LondonClose    = GMTOffset + 16;
   NewYorkOpen    = GMTOffset + 12;
   NewYorkClose   = GMTOffset + 21;
   SydneyOpen     = GMTOffset + 0;
   SydneyClose    = GMTOffset + 6;
   TokyoOpen      = GMTOffset + 0;
   TokyoClose     = GMTOffset + 9;

   TokyoOpen1      = GMTOffset + 4;
   TokyoClose1     = GMTOffset + 9;
 
   TokyoOpen2      = GMTOffset + 8;
   TokyoClose2     = GMTOffset + 13;
 
   TokyoOpen3      = GMTOffset + 12;
   TokyoClose3     = GMTOffset + 17;
   
   TokyoOpen4      = GMTOffset + 16;
   TokyoClose4     = GMTOffset + 20;

	// Determine number of bars to iterate over
	int iBarsToCalc = Bars - IndicatorCounted();
	if (iBarsToCalc < Bars) iBarsToCalc++;
	
	// Iterate over bars
	for (int i=iBarsToCalc-1;i>=0;i--) {
		
		// Set London Line
		if (isMarketOpen(LondonOpen, LondonClose, Time[i]))
			dLondonBuffer[i] = 8;
		else
			dLondonBuffer[i] = EMPTY_VALUE;
		
		// Set NewYork Line
		if (isMarketOpen(NewYorkOpen, NewYorkClose, Time[i]))
			dNewYorkBuffer[i] = 6;
		else
			dNewYorkBuffer[i] = EMPTY_VALUE;		
			
		// Set Sydney Line
		if (isMarketOpen(SydneyOpen, SydneyClose, Time[i]))
			dSydneyBuffer[i] = 4;
		else
			dSydneyBuffer[i] = EMPTY_VALUE;	
				
		// Set Tokyo Line
		if (isMarketOpen(TokyoOpen, TokyoClose, Time[i]))
			dTokyoBuffer[i] = 2;
		else
			dTokyoBuffer[i] = EMPTY_VALUE;	


		// Set Tokyo Line1
		if (isMarketOpen(TokyoOpen1, TokyoClose1, Time[i]))
			dTokyoBuffer1[i] = 1;
		else
			dTokyoBuffer1[i] = EMPTY_VALUE;	
		// Set Tokyo Line1
		if (isMarketOpen(TokyoOpen2, TokyoClose2, Time[i]))
			dTokyoBuffer2[i] = 1;
		else
			dTokyoBuffer2[i] = EMPTY_VALUE;	
		// Set Tokyo Line1
		if (isMarketOpen(TokyoOpen3, TokyoClose3, Time[i]))
			dTokyoBuffer3[i] = 1;
		else
			dTokyoBuffer3[i] = EMPTY_VALUE;	

		// Set Tokyo Line1
		if (isMarketOpen(TokyoOpen4, TokyoClose4, Time[i]))
			dTokyoBuffer4[i] = 1;
		else
			dTokyoBuffer4[i] = EMPTY_VALUE;	

	}

}

bool isMarketOpen(int iOpenHour, int iCloseHour, datetime timestamp) {

	int iBarHour = TimeHour(timestamp);
	
	if (iOpenHour < iCloseHour && (iBarHour >= iOpenHour && iBarHour < iCloseHour))
		return(true);
	if (iOpenHour > iCloseHour && (iBarHour >= iOpenHour || iBarHour < iCloseHour))
		return(true);
		
	return(false);
}

Comments