Trading Hours_v2
Download scriptThis tool is designed to provide traders with a clear visual representation of specific market trading hours directly on their charts. By identifying when a particular market—such as the US market—is active or closed, it helps users manage their expectations regarding liquidity and volatility throughout the day.
How It Works
The logic relies on comparing three different timeframes to ensure the data displayed accurately reflects the local time of the market you are interested in:
- Data Source Time: The script identifies the base timezone of the data feed provided by the trading platform.
- Market Local Time: You can input the specific timezone for the currency or market you want to monitor.
- Specific Trading Window: The tool is programmed to recognize a set "opening" and "closing" hour for that specific market.
Visual Representation
Instead of simple text, the script uses a color-coded histogram at the bottom of your chart to represent these sessions:
- Blue Bars (Open Market): When the current time falls within the defined trading hours of the selected market, the bars appear in blue. The height of these bars corresponds to the hour of the day, allowing you to see the progression of the active session.
- Red Bars (Closed Market): When the market is outside of its active trading hours, the bars turn red and extend downwards. This provides an immediate visual cue that the market is currently inactive.
Key Benefits for Traders
By using this logic, traders can quickly assess whether a market is "live" without having to manually calculate time zone offsets or check external clocks. It creates a consistent visual history on the chart, making it easy to identify patterns in trading activity and ensuring you are aware of the specific windows where price action is most relevant for your chosen region.
//+-----------------------------------------------------------------------------------------------+
//| by Gilani |
//| currencyTimeZone - adjust to the timezone of the relevant currency. |
//| serverTimeZone - timezone of the source of data source feed (+1 Russian zone for MetaTrader) |
//| blue bars represent open market hours |
//| red bars represent close mrket hours |
//|the bars grows according to the hours of the day |
//+-----------------------------------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
extern int currencyTimeZone=-5;
extern string market="USA";
//----
int serverTimeZone=+1;
int marketOpensAt=8;
int marketClosesAt=16;
//----
double open[];
double close[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,open);
SetIndexLabel(0,"Blue");
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,close);
SetIndexLabel(1,"Red");
//----
IndicatorShortName("Trading Hours: "+market);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int ExtCountedBars=IndicatorCounted();
if(ExtCountedBars<0) return(-1);
if(ExtCountedBars>0) ExtCountedBars--;
limit=Bars-ExtCountedBars;
//----
for(int x=limit;x>=0;x--)
{
int gmt=MathMod (24+TimeHour(Time[x])-serverTimeZone, 24);
int hour=MathMod(24+currencyTimeZone+gmt, 24);
if ((hour>=marketOpensAt) && (hour<=marketClosesAt))
{
if (hour==0) hour=24;
open[x]=hour;
close[x]=0;
}
else
{
if (hour==0) hour=24;
open[x]=0;
close[x]= -hour;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments