Market_Hours
Download scriptThis tool is designed to provide a visual overview of global market activity by identifying specific trading sessions on your price chart. It acts as a session tracker, allowing traders to see at a glance when major financial hubs—specifically London, New York, Sydney, and Tokyo—are open for business.
How the Logic Works
The script operates by scanning the historical and real-time data of your currency pairs to identify the specific hours of each trading day. It processes these times based on four distinct regional windows that can be customized:
- Session Identification: The tool looks at the current time on the chart and compares it against a predefined set of opening and closing hours for the four major global markets.
- Visual Mapping: When the script detects that a specific market (e.g., the London session) is currently active, it highlights that period on a separate window in your trading platform. Each market is assigned a unique visual level or "buffer," making it easy to distinguish between overlapping sessions.
- Handling Overnight Markets: The logic is built to be intelligent regarding time transitions. Because some markets (like New York or Sydney) may open at night and close the following morning, the script includes a specific check to ensure these "overnight" sessions are calculated correctly across the midnight boundary.
- Dynamic Updating: The indicator continuously updates as new price bars form. It automatically recalculates every time a new candle appears, ensuring that the visual markers stay perfectly aligned with the current market clock.
Key Benefits for the User
Instead of having to manually calculate which markets are active or switch between different clocks, this tool automates the process. It provides a clear, structured layout of the trading day, helping you identify high-liquidity periods where price action is typically most active. By observing where these session lines overlap, you can better understand the "heartbeat" of the global financial markets.
#property indicator_separate_window
#property indicator_buffers 4
#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_maximum 9
#property indicator_minimum 0
extern int LondonOpen = 10;
extern int LondonClose = 18;
extern int NewYorkOpen = 15;
extern int NewYorkClose = 0;
extern int SydneyOpen = 0;
extern int SydneyClose = 8;
extern int TokyoOpen = 2;
extern int TokyoClose = 10;
// Buffers
double dLondonBuffer[];
double dNewYorkBuffer[];
double dSydneyBuffer[];
double dTokyoBuffer[];
int init() {
IndicatorShortName("");
SetIndexBuffer(0,dLondonBuffer);
SetIndexLabel(0,"London");
SetIndexBuffer(1,dNewYorkBuffer);
SetIndexLabel(1,"New York");
SetIndexBuffer(2,dSydneyBuffer);
SetIndexLabel(2,"Sydney");
SetIndexBuffer(3,dTokyoBuffer);
SetIndexLabel(3,"Tokyo");
return(0);
}
int start() {
// 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;
}
}
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