Session Open V-Line Indi
Download scriptThis script is designed to provide a clear visual roadmap of the global financial markets directly on your trading chart. By identifying the specific windows when major global sessions occur, it helps traders understand market behavior based on different time zones.
Core Functionality
The primary purpose of this tool is to automatically draw historical and current session boundaries on your chart. Instead of you having to manually calculate when the Asian, European (London/EuroZone), or American markets open and close, the script handles these calculations and highlights them visually.
Key Features and Logic
- Session Customization: You can choose which global sessions you want to see on your chart. The script provides independent toggles for the Asia, London/EuroZone, and USA sessions. If you prefer a cleaner chart, you can easily hide specific regions.
- Visual Styling: Each session can be assigned its own unique color (e.g., Green for Asia, Magenta for the USA) and line style. This allows for quick visual identification of market shifts at a glance.
- Historical Depth: The script doesn't just show you today's sessions; it looks back into history. You can define how many historical days you want to display, allowing you to analyze past price movements during specific high-volatility windows.
- Precise Time Mapping: The logic is built to recognize the specific opening times for each region. It automatically calculates the corresponding dates and times to draw vertical markers or boxes (depending on your chart settings) that represent these sessions.
- Smart Date Handling: To ensure accuracy, the script includes internal logic to navigate through calendar dates correctly. This includes handling complex transitions like month-ends, leap years, and skipping weekends to ensure the session lines remain perfectly aligned with the correct trading days.
How It Benefits Your Trading
By using this script, you can more effectively identify:
- Volatility Shifts: Notice when liquidity increases as a new session opens.
- Trend Reversals: Observe how price action often changes when one global market closes and another takes over.
- Session Overlaps: Easily see the "power hours" where two major markets are active simultaneously, typically resulting in higher trading volume.
//+------------------------------------------------------------------+
//| i-Sessions.mq4 |
//| Êèì Èãîðü Â. aka KimIV |
//| http://www.kimiv.ru |
//| |
//| 16.11.2005 Èíäèêàòîð òîðãîâûõ ñåññèé |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link "http://www.kimiv.ru"
#property indicator_chart_window
//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà -------------------------------
extern int Line_Width_1_2_3_4_or_5 = 1;
extern int Line_Style = 0;
extern int Historical_Days = 360; // Êîëè÷åñòâî äíåé
extern bool Hide_London_EuroZone = false;
extern color London_EuroZone_Color = DodgerBlue; // Öâåò åâðîïåéñêîé ñåññèè
extern string London_EuroZone_Open = "09:00"; // Îòêðûòèå åâðîïåéñêîé ñåññèè
extern bool Hide_USA = false;
extern color USA_Color = Magenta; // Öâåò àìåðèêàíñêîé ñåññèè
extern string USA_Open = "15:30"; // Îòêðûòèå àìåðèêàíñêîé ñåññèè
extern bool Hide_Asia = false;
extern color Asia_Color = Green; // Öâåò àçèàòñêîé ñåññèè
extern string Asia_Open = "20:00"; // Îòêðûòèå àçèàòñêîé ñåññèè
string AsiaEnd = "Asia_Open"; // Çàêðûòèå àçèàòñêîé ñåññèè
string EurEnd = "London_EuroZone_Open"; // Îòêðûòèå åâðîïåéñêîé ñåññèè
string USAEnd = "USA_Open"; // Çàêðûòèå àìåðèêàíñêîé ñåññèè
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init() {
DeleteObjects();
for (int i=0; i<Historical_Days; i++) {
CreateObjects("AS"+i, Asia_Color);
CreateObjects("EU"+i,London_EuroZone_Color);
CreateObjects("US"+i, USA_Color);
}
Comment("");
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
void deinit() {
DeleteObjects();
Comment("");
}
//+------------------------------------------------------------------+
//| Ñîçäàíèå îáúåêòîâ èíäèêàòîðà |
//| Ïàðàìåòðû: |
//| no - íàèìåíîâàíèå îáúåêòà |
//| cl - öâåò îáúåêòà |
//+------------------------------------------------------------------+
void CreateObjects(string no, color cl){
ObjectCreate(no, OBJ_VLINE, 0, 0,0, 0,0);
ObjectSet(no, OBJPROP_WIDTH, Line_Width_1_2_3_4_or_5);
ObjectSet(no, OBJPROP_STYLE, Line_Style);
ObjectSet(no, OBJPROP_COLOR, cl);
ObjectSet(no, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
//| Óäàëåíèå îáúåêòîâ èíäèêàòîðà |
//+------------------------------------------------------------------+
void DeleteObjects() {
for (int i=0; i<Historical_Days; i++) {
ObjectDelete("AS"+i);
ObjectDelete("EU"+i);
ObjectDelete("US"+i);
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start() {
datetime dt=CurTime();
for (int i=0; i<Historical_Days; i++) {
if(Hide_Asia==false){
DrawObjects(dt, "AS"+i, Asia_Open,AsiaEnd);}
if(Hide_London_EuroZone==false){
DrawObjects(dt, "EU"+i, London_EuroZone_Open, EurEnd);}
if(Hide_USA==false){
DrawObjects(dt, "US"+i, USA_Open, USAEnd);}
dt=decDateTradeDay(dt);
while (TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
}
}
//+------------------------------------------------------------------+
//| Ïðîðèñîâêà îáúåêòîâ íà ãðàôèêå |
//| Ïàðàìåòðû: |
//| dt - äàòà òîðãîâîãî äíÿ |
//| no - íàèìåíîâàíèå îáúåêòà |
//| tb - âðåìÿ íà÷àëà ñåññèè |
//| te - âðåìÿ îêîí÷àíèÿ ñåññèè |
//+------------------------------------------------------------------+
void DrawObjects(datetime dt, string no, string tb, string te) {
datetime t1, t2;
double p1, p2;
int b1, b2;
t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
ObjectSet(no, OBJPROP_TIME1 , t1);
ObjectSet(no, OBJPROP_PRICE1, p1);
ObjectSet(no, OBJPROP_TIME2 , t2);
ObjectSet(no, OBJPROP_PRICE2, p2);
}
//+------------------------------------------------------------------+
//| Óìåíüøåíèå äàòû íà îäèí òîðãîâûé äåíü |
//| Ïàðàìåòðû: |
//| dt - äàòà òîðãîâîãî äíÿ |
//+------------------------------------------------------------------+
datetime decDateTradeDay (datetime dt) {
int ty=TimeYear(dt);
int tm=TimeMonth(dt);
int td=TimeDay(dt);
int th=TimeHour(dt);
int ti=TimeMinute(dt);
td--;
if (td==0) {
tm--;
if (tm==0) {
ty--;
tm=12;
}
if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
}
return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}
//+------------------------------------------------------------------+
Comments