i-BigBarsFromH1_v1

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

This script is designed to enhance the visual clarity of a trading chart by identifying and highlighting specific historical "big bars" from a higher timeframe, specifically the 1-hour (H1) timeframe. It serves as a visual bridge, allowing traders who are looking at smaller time intervals to see the significant price action that occurred over larger blocks of time without switching views.

Core Functionality

The primary purpose of this tool is to project historical hourly candles onto your current chart. Instead of just showing every single minute or small candle, it filters through historical data to locate and draw representative "large bars." This helps in identifying major price movements, significant highs, and lows that occurred in the past.

How the Logic Works

  • Timeframe Compatibility: The script is specifically tailored for the 1-hour (H1) timeframe. If you attempt to run it on other intervals, it will notify you that it is only optimized for H1 data.
  • Data Scanning: The script automatically scans backward through historical price data. It looks for specific price points—specifically high, low, open, and close prices—across a set number of previous candles (customizable by the user).
  • Visual Construction: For every significant historical period it identifies, the script draws two distinct components on your screen:
    • The Body: This represents the main movement of the price. It is drawn as a solid rectangle between the opening and closing prices.
    • The Shadow: This represents the "wick" or the extreme reach of the price during that period (the highest and lowest points reached). It is drawn as a vertical line to show the full range of volatility.
  • Dynamic Coloring: To make the chart easy to read at a glance, the script automatically assigns colors based on the direction of the price movement. If the price closed higher than it opened, the bar is colored one way (e.g., Aqua); if it closed lower, it is colored another (e.g., Pink).
  • Customization Options: Users can define several parameters to tailor the display:
    • Period: Choose how many historical bars to look back at.
    • Quantity: Control exactly how many of these "big bars" are displayed on the screen.
    • Time Offset: Adjust the timing to align with specific global sessions or time zones.
    • Colors: Customize the colors for upward and downward movements to match your personal chart theme.

User Benefit

By using this logic, a trader can quickly see "the big picture" of past price action. It removes the clutter of many small candles and replaces it with clearly defined blocks that show where significant money moved, how far the price stretched, and the general trend of previous hours in a single, easy-to-read visual format.

6 Views
0 Downloads
0 Favorites
i-BigBarsFromH1_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                              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   = Aqua;   // Öâåò âîñõîäÿùåé ñâå÷è
extern color ColorDown = Pink;   // Öâåò íèñõîäÿùåé ñâå÷è

//------- Ãëîáàëüíûå ïåðåìåííûå --------------------------------------

//+------------------------------------------------------------------+
//| 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