i-BigBarsFromH1_v2

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

This script is a specialized visual tool for MetaTrader 4 designed to simplify how traders view historical price action. Its primary purpose is to group smaller timeframes into larger, "consolidated" blocks on your chart, making it easier to identify major price movements at a glance.

How the Logic Works

1. Timeframe Filtering and Requirements The indicator is specifically engineered to work with the 1-hour (H1) timeframe. If you attempt to run it on any other timeframe, the script will display a notification informing you that it requires the H1 setting to function correctly.

2. Data Consolidation (Grouping) Rather than showing every single price tick or minor fluctuation, the script looks at historical data and groups it based on a user-defined period (the "TFBar" parameter). For example, if you set the period to 3, the script will look back through the history and bundle several hours of data into a single visual representation.

3. Visual Representation (Bodies and Shadows) The script draws two distinct types of shapes on your chart for each grouped period:

  • The Body: It identifies the opening and closing prices of the historical period and draws a rectangular box to represent the "meat" of the price movement. This helps you quickly see if the price moved up or down significantly during that timeframe.
  • The Shadow: It calculates the highest and lowest price points reached during that same period and draws a vertical line (a "shadow"). This shows the total volatility or range of the price movement, even if it didn't end where it started.

4. Dynamic Coloring To make the chart intuitive to read, the script automatically assigns colors based on price action:

  • If the price closed higher than it opened during a period, the box and shadow are colored one way (e.g., Red).
  • If the price closed lower than it opened, they are colored another way (e.g., Green).

5. Customization Options The script provides several "knobs" for you to turn to suit your specific trading style:

  • Period: How many hours should be grouped together?
  • Number of Bars: How many of these historical groups do you want to see visible on the chart?
  • Offset: Allows for a slight time adjustment (shift) if your data feed requires it.
  • Colors: You can choose the specific colors for upward and downward movements to match your personal chart aesthetics.

Summary for the User

Essentially, this tool acts like a "magnifying glass" for history. It takes raw, messy hourly data and cleans it up into a series of large, color-coded blocks. This allows you to see the "big picture" of where price has been moving without getting distracted by every tiny minor movement between hours.

8 Views
0 Downloads
0 Favorites
i-BigBarsFromH1_v2
//+------------------------------------------------------------------+
//|                                              i-BigBarsFromH1.mq4 |
//|                                           Êèì Èãîðü Â. aka KimIV |
//|                                              http://www.kimiv.ru |
//| Íà ÷àñîâîì ãðàôèêå ïîêàçûâàåò ñâå÷è ñòàðøèõ ÒÔ                   |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link      "http://www.kimiv.ru"
//----
#property indicator_chart_window
//---- Âíåøíèå ïàðàìåòðû ---------------------------------------------
extern int TFBar      =3;       // Ïåðèîä ñòàðøèõ ñâå÷åê
extern int NumberOfBar=50;      // Êîëè÷åñòâî ñòàðøèõ ñâå÷åê
extern int offsetHour =-2;      // Ñìåùåíèå ÷àñîâ
extern color ColorUp  =Red;     // Öâåò âîñõîäÿùåé ñâå÷è
extern color ColorDown=Green;   // Öâåò íèñõîäÿùåé ñâå÷è
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  void init() 
  {
   int i;
     for(i=0; i<NumberOfBar; i++) 
     {
      ObjectDelete("BodyH"+TFBar+"Bar" + i);
      ObjectDelete("ShadowH"+TFBar+"Bar" + i);
     }
     for(i=0; i<NumberOfBar; i++) 
     {
      ObjectCreate("BodyH"+TFBar+"Bar" + i, OBJ_RECTANGLE, 0, 0,0, 0,0);
      ObjectCreate("ShadowH"+TFBar+"Bar" + i, OBJ_TREND, 0, 0,0, 0,0);
     }
   Comment("");
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
  void deinit() 
  {
   // Óäàëåíèå îáúåêòîâ
     for(int i=0; i<NumberOfBar; i++) 
     {
      ObjectDelete("BodyH"+TFBar+"Bar" + i);
      ObjectDelete("ShadowH"+TFBar+"Bar" + i);
     }
   Comment("");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  void start() 
  {
   int shb=0, sh1=1, d;
   double   po, pc;       // Öåíû îòêðûòèÿ è çàêðûòèÿ ñòàðøèõ ñâå÷åê
   double   ph=0, pl=500; // Öåíû õàé è ëîó ñòàðøèõ ñâå÷åê
   datetime to, tc, ts;   // Âðåìÿ îòêðûòèÿ, çàêðûòèÿ è òåíåé ñòàðøèõ ñâå÷åê
//----
   if (Period()!=60) Comment("Èíäèêàòîð i-BigBarsFromH1 ïîääåðæèâàåò ÒÔ òîëüêî Í1!");
     else 
     {
      if (MathMod(TFBar,2)==0) d=TFBar/2; else d=TFBar/2+1;
      pc=Close[0];
      tc=Time[0];
      // Áåæèì ïî ñòàðøèì ñâå÷êàì
        while(shb<NumberOfBar) 
        {
         // Áåæèì ïî ÷àñîâûì ñâå÷êàì
         ph=MathMax(ph, High[sh1-1]);
         pl=MathMin(pl, Low[sh1-1]);
         ts=StrToTime(TimeToStr(Time[sh1-d], TIME_DATE)+" "+TimeHour(Time[sh1-d])+":30");
      if (MathMod(TimeHour(Time[sh1])+1+offsetHour, TFBar)==0/* || TimeDay(Time[sh1])!=TimeDay(Time[sh1-1])*/) 
      {
            po=Open[sh1-1];
            to=Time[sh1-1];
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_TIME1, to);
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_PRICE1, po);
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_TIME2, tc);
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_PRICE2, pc);
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_BACK, True);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_TIME1, ts);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_PRICE1, ph);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_TIME2, ts);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_PRICE2, pl);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_STYLE, STYLE_SOLID);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_WIDTH, 3);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_BACK, True);
            ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_RAY, False);
              if (po<pc) 
              {
               ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_COLOR, ColorUp);
               ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_COLOR, ColorUp);
               }
                else 
               {
               ObjectSet("BodyH"+TFBar+"Bar"+shb, OBJPROP_COLOR, ColorDown);
               ObjectSet("ShadowH"+TFBar+"Bar"+shb, OBJPROP_COLOR, ColorDown);
              }
            pc=Close[sh1];
            tc=Time[sh1];
            ph=0;
            pl=500;
            ph=MathMax(ph, High[sh1]);
            pl=MathMin(pl, Low[sh1]);
            shb++;
           }
         sh1++;
        }
     }
  }
//+------------------------------------------------------------------+

Comments