i-Sessions-02_v2

Download script
Author: ��� ����� �. aka KimIV
i-Sessions-02_v2

This tool is designed to provide a visual roadmap of the trading day by automatically plotting specific time zones directly onto your price charts. Instead of forcing you to manually track what time a specific market session starts or ends, the script overlays clearly defined blocks that highlight these periods based on your preferences.

How the Logic Works

1. Customizable Time Segments The core logic revolves around dividing a 24-hour day into eight distinct segments (labeled S1 through S8). You can define the exact start and end times for each of these segments, allowing you to map out different market sessions—such as the London Open, New York Session, or Asian markets—all in one view.

2. Dynamic Range Detection One of the key features of this script is how it handles price height. Rather than just drawing a flat line, the logic scans the historical price data for every specific time block you define. It identifies the highest and lowest prices reached during that specific window and stretches the visual box to fit those boundaries. This gives you an immediate sense of the volatility and price action that occurred during that specific timeframe.

3. Historical Backfilling The script doesn't just show you what is happening right now; it looks backward in time. You can set how many days of history you wish to visualize, and the logic will automatically calculate the correct dates and times to draw those blocks across the preceding trading days.

4. Intelligent Calendar Awareness To ensure accuracy, the script includes a specialized date-handling routine. It understands the complexities of the calendar—such as varying month lengths and leap years—and specifically skips over weekends. This ensures that when the script calculates "the previous day," it correctly lands on a valid trading day rather than a Saturday or Sunday, keeping your visual blocks consistent and aligned with actual market activity.

5. Visual Organization Each segment can be assigned its own unique color. By using different colors for different sessions, the chart becomes a multi-layered map where you can easily distinguish between high-activity periods and quieter overnight markets at a single glance.

12 Views
0 Downloads
0 Favorites
i-Sessions-02_v2
//+------------------------------------------------------------------+
//|                                                   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    NumberOfDays=50;
extern string S1Begin   ="00:55";
extern string S1End     ="03:55";
extern color  S1Color   =DarkSlateGray;
extern string S2Begin   ="03:55";
extern string S2End     ="06:55";
extern color  S2Color   =DarkSlateGray;
extern string S3Begin   ="06:55";
extern string S3End     ="09:55";
extern color  S3Color   =DarkSlateGray;
extern string S4Begin   ="09:55";
extern string S4End     ="12:55";
extern color  S4Color   =DarkSlateGray;
extern string S5Begin   ="12:55";
extern string S5End     ="15:55";
extern color  S5Color   =DarkSlateGray;
extern string S6Begin   ="15:55";
extern string S6End     ="18:55";
extern color  S6Color   =DarkSlateGray;
extern string S7Begin   ="18:55";
extern string S7End     ="21:55";
extern color  S7Color   =DarkSlateGray;
extern string S8Begin   ="21:55";
extern string S8End     ="23:55";
extern color  S8Color   =DarkSlateGray;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  void init() 
  {
   DeleteObjects();
     for(int i=0; i<NumberOfDays; i++) 
     {
      CreateObjects("S1"+i, S1Color);
      CreateObjects("S2"+i, S2Color);
      CreateObjects("S3"+i, S3Color);
      CreateObjects("S4"+i, S4Color);
      CreateObjects("S5"+i, S5Color);
      CreateObjects("S6"+i, S6Color);
      CreateObjects("S7"+i, S7Color);
      CreateObjects("S8"+i, S8Color);
     }
   Comment("");
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
  void deinit() 
  {
   DeleteObjects();
   Comment("");
  }
//+------------------------------------------------------------------+
//| Ñîçäàíèå îáúåêòîâ èíäèêàòîðà                                     |
//| Ïàðàìåòðû:                                                       |
//|   no - íàèìåíîâàíèå îáúåêòà                                      |
//|   cl - öâåò îáúåêòà                                              |
//+------------------------------------------------------------------+
  void CreateObjects(string no, color cl) 
  {
   ObjectCreate(no, OBJ_RECTANGLE, 0, 0,0, 0,0);
   ObjectSet(no, OBJPROP_STYLE, 2);
   ObjectSet(no, OBJPROP_COLOR, cl);
   ObjectSet(no, OBJPROP_BACK, True);
  }
//+------------------------------------------------------------------+
//| Óäàëåíèå îáúåêòîâ èíäèêàòîðà                                     |
//+------------------------------------------------------------------+
  void DeleteObjects() 
  {
     for(int i=0; i<NumberOfDays; i++) 
     {
      ObjectDelete("S1"+i);
      ObjectDelete("S2"+i);
      ObjectDelete("S3"+i);
      ObjectDelete("S4"+i);
      ObjectDelete("S5"+i);
      ObjectDelete("S6"+i);
      ObjectDelete("S7"+i);
      ObjectDelete("S8"+i);
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  void start() 
  {
   datetime dt=CurTime();
     for(int i=0; i<NumberOfDays; i++) 
     {
      DrawObjects(dt, "S1"+i, S1Begin, S1End);
      DrawObjects(dt, "S2"+i, S2Begin, S2End);
      DrawObjects(dt, "S3"+i, S3Begin, S3End);
      DrawObjects(dt, "S4"+i, S4Begin, S4End);
      DrawObjects(dt, "S5"+i, S5Begin, S5End);
      DrawObjects(dt, "S6"+i, S6Begin, S6End);
      DrawObjects(dt, "S7"+i, S7Begin, S7End);
      DrawObjects(dt, "S8"+i, S8Begin, S8End);
      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