i-BigBarsFromH1
Download scriptThis script is designed for traders who need to visualize high-level price movements while viewing a lower timeframe chart. Specifically, it allows you to see the "Big Bars" (the price action) of the 1-Hour (H1) timeframe projected onto your current screen.
How It Works
The primary goal of this tool is to provide context. Often, when looking at small timeframes, it is difficult to see the larger trends occurring on the hourly scale. This script solves that by drawing visual representations of these older, larger candles directly over your current chart.
Core Logic and Features
- Timeframe Synchronization: The script is specifically engineered to work with the 1-Hour (H1) timeframe. It scans back through history to identify historical hourly bars based on a specific number of periods you define in the settings.
- Visual Representation: Instead of just showing text or numbers, the script draws two distinct visual elements for every historical bar:
- The Body: A rectangle representing the main movement (the difference between the opening and closing price).
- The Shadow: A vertical line representing the full range (the highest and lowest points reached) during that hour.
- Dynamic Coloring: The script automatically distinguishes between "Up" bars and "Down" bars. It assigns a specific color to bullish movements (where the price closed higher than it opened) and a different color to bearish movements (where the price closed lower), allowing for an immediate visual understanding of past momentum.
- Customizable Parameters: Users can adjust several key settings without needing to touch the code:
- Period/Number of Bars: You can choose how many historical "Big Bars" you want to see at once.
- Offset: You can shift the display forward or backward in time using an hour offset.
- Color Selection: You can personalize the colors for ascending and descending candles to match your specific trading style or chart theme.
- Automatic Cleanup: The script is designed to be "clean." It includes built-in instructions to remove the drawn objects automatically when you remove the indicator from your chart, ensuring your workspace remains organized.
Summary for Traders
Think of this tool as a "historical overlay." It paints the story of the previous hours onto your current view, helping you identify where the market has been and how much volatility those large price movements actually contained, all while you continue to trade on your preferred smaller timeframe.
//+------------------------------------------------------------------+
//| 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