i-MorningRange_v1

Download script
Author: ��� ����� �. aka KimIV
i-MorningRange_v1

This script is designed to help traders identify the price range established during a specific window of time each day. By highlighting these boundaries, it allows you to visualize historical price extremes and see how the market behaves within a set timeframe.

Core Functionality

The primary purpose of this tool is to automatically detect and plot two specific price levels:

  1. The Highest Price: The peak reached during your chosen time window.
  2. The Lowest Price: The bottom point reached during your chosen time window.

How it Works

The script operates based on the following logic:

  • Time Window Detection: You can define a specific time (e.g., 08:00) that the script uses as its reference point. It calculates the price action starting from the very beginning of the trading day (midnight) up until that designated time.
  • Price Level Mapping: Once the script identifies the highest and lowest prices within that morning window, it places horizontal lines on your chart. This allows you to see exactly where the "ceiling" and "floor" were for that period.
  • Historical Data Visualization: Beyond just showing today's data, the script can look backward into history. It will automatically go back a specific number of days (which you can customize) and plot the ranges for those previous days as well.
  • Dynamic Updates: The tool is designed to update in real-time. As the current day progresses toward your chosen time, the lines will adjust to reflect the most recent high and low prices discovered so far.

Visual Elements

  • Current Day Lines: These are displayed as horizontal markers to show where the price currently sits relative to today's morning extremes.
  • Historical Ranges: For previous days, the script draws specific segments that span from the start of the day to your chosen time, helping you visualize the "growth" or "contraction" of the market range over time.
  • On-Screen Information: The script can also display a text comment on your chart to confirm which specific time is being used for the calculation.

Practical Use for Traders

This tool is particularly useful for traders who want to identify "Breakout" or "Breakdown" opportunities. By seeing where the price traded during the early morning session, you can better understand whether the current price action is staying within a previous range or pushing into new territory.

8 Views
0 Downloads
0 Favorites
i-MorningRange_v1
//+------------------------------------------------------------------+
//|                                               i-MorningRange.mq4 |
//|                                           Êèì Èãîðü Â. aka KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//|  08.02.2006  Èíäèêàòîð óòðåííåãî äèàïàçîíà.                      |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link      "http://www.kimiv.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Orange
//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà -------------------------------
extern string CheckTime   ="08:00";  // Âðåìÿ ïðîâåðêè äèàïàçîíà
extern bool   ShowHistory =True;     // Ïîêàçûâàòü èñòîðè÷åñêèå óðîâíè
extern int    NumberOfDays=5;        // Êîëè÷åñòâî äíåé èñòîðèè
extern bool   ShowComment =True;     // Ïîêàçûâàòü êîììåíòàðèè
//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double dBuf0[], dBuf1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  void init() 
  {
   SetIndexArrow (0, 217);
   SetIndexBuffer(0, dBuf0);
   SetIndexStyle (0, DRAW_ARROW, 1, 1);
   SetIndexArrow (1, 218);
   SetIndexBuffer(1, dBuf1);
   SetIndexStyle (1, DRAW_ARROW, 1, 1);
   DeleteLines();
     for(int i=0; i<2; i++) 
     {
      ObjectCreate("HLine"+i, OBJ_HLINE, 0, 0,0);
     }
     for(i=0; i<NumberOfDays; i++) 
     {
      CreateLines("upLine"+i, indicator_color1);
      CreateLines("dnLine"+i, indicator_color2);
     }
  }
//+------------------------------------------------------------------+
//| Ñîçäàíèå îáúåêòîâ Ëèíèÿ ïðîøëûõ äíåé                             |
//| Ïàðàìåòðû:                                                       |
//|   no - íàèìåíîâàíèå ëèíèè                                        |
//|   cl - öâåò ëèíèè                                                |
//+------------------------------------------------------------------+
  void CreateLines(string no, color cl) 
  {
   ObjectCreate(no, OBJ_TREND, 0, 0,0, 0,0);
   ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(no, OBJPROP_WIDTH, 1);
   ObjectSet(no, OBJPROP_COLOR, cl);
   ObjectSet(no, OBJPROP_RAY, False);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
  void deinit() 
  {
   DeleteLines();
   Comment("");
  }
//+------------------------------------------------------------------+
//| Óäàëåíèå ãîðèçîíòàëüíûõ ëèíèé.                                   |
//+------------------------------------------------------------------+
  void DeleteLines() 
  {
     for(int i=0; i<2; i++) 
     {
      ObjectDelete("HLine"+i);
     }
     for(i=0; i<NumberOfDays; i++) 
     {
      ObjectDelete("upLine"+i);
      ObjectDelete("dnLine"+i);
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  void start() 
  {
   datetime t1, t2, dt;
   double   p1, p2;
   int      b1, b2, sd=0;
//----
   t1=StrToTime(TimeToStr(CurTime(), TIME_DATE)+" 00:00");
   t2=StrToTime(TimeToStr(CurTime(), TIME_DATE)+" "+CheckTime);
   b1=iBarShift(NULL, 0, t1);
   b2=iBarShift(NULL, 0, t2);
   p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];
   p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2+1, b2)];
   SetHLine(0, p1);
   SetHLine(1, p2);
     if (ShowHistory) 
     {
      dt=decDateTradeDay(CurTime());
        for(int i=0; i<NumberOfDays; i++) 
        {
         DrawLines(dt, i);
         dt=decDateTradeDay(dt);
         while(TimeDayOfWeek(dt)<1 || TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
        }
     }
   if (ShowComment) Comment("CheckTime="+CheckTime);
  }
//+------------------------------------------------------------------+
//| Óñòàíàâëèâàåò ðåêâèçèòû ãîðèçîíòàëüíîé ëèíèè òåêóùåãî äíÿ.       |
//+------------------------------------------------------------------+
  void SetHLine(int nl, double pp) 
  {
   color cl;
     if (pp!=EMPTY_VALUE) 
     {
        switch(nl) 
        {
            case 0: cl=indicator_color1; break;
            case 1: cl=indicator_color2; break;
           }
         ObjectSet("HLine"+nl, OBJPROP_PRICE1, pp);
         ObjectSet("HLine"+nl, OBJPROP_COLOR , cl);
        }
           }
//+------------------------------------------------------------------+
//| Ïðîðèñîâêà ëèíèé íà ãðàôèêå                                      |
//| Ïàðàìåòðû:                                                       |
//|   dt - äàòà òîðãîâîãî äíÿ                                        |
//|   nd - íîìåð äíÿ (äëÿ íóìåðàöèè îáúåêòîâ)                        |
//+------------------------------------------------------------------+
  void DrawLines(datetime dt, int nd) 
   {
                  datetime t1, t2;
                  double   p1, p2;
                  int      b1, b2;

                  t1=StrToTime(TimeToStr(dt, TIME_DATE)+" 00:00");
                  t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+CheckTime);
                  b1=iBarShift(NULL, 0, t1);
                  b2=iBarShift(NULL, 0, t2);
                  p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];
                  p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2+1, b2)];

                  ObjectSet("upLine"+nd, OBJPROP_TIME1 , t1);
                  ObjectSet("upLine"+nd, OBJPROP_PRICE1, p1);
                  ObjectSet("upLine"+nd, OBJPROP_TIME2 , t2);
                  ObjectSet("upLine"+nd, OBJPROP_PRICE2, p1);

                  ObjectSet("dnLine"+nd, OBJPROP_TIME1 , t1);
                  ObjectSet("dnLine"+nd, OBJPROP_PRICE1, p2);
                  ObjectSet("dnLine"+nd, OBJPROP_TIME2 , t2);
                  ObjectSet("dnLine"+nd, 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