GG-TimeBox
Download scriptThis tool is designed to provide traders with a visual representation of historical price action by highlighting specific periods of time on the trading chart. It automatically identifies and draws rectangles over past data, allowing you to see significant price movements at a glance without having to manually calculate timeframe conversions.
How the Logic Works
Timeframe Synchronization The script is built to bridge the gap between different timeframes. When you select a "Custom Timeframe" (such as a Daily or 4-Hour chart), the logic calculates exactly how many smaller bars (like Minutes or Hours) fit into that period. This ensures that regardless of what timeframe you are currently viewing, the tool correctly identifies the boundaries of the historical blocks it is intended to display.
Dynamic Data Processing Instead of showing an infinite amount of data, the script allows you to set a specific number of "units" to process. It looks back through history to gather four key pieces of information for each unit:
- The exact start and end times.
- The highest price reached.
- The lowest price reached.
Smart Color Coding To make the chart easier to read, the script analyzes the "candle" behavior within those historical blocks and assigns a specific color based on the price movement:
- Upward Movement: If the price closed significantly higher than it opened (exceeding a user-defined difference), the rectangle is colored green.
- Downward Movement: If the price closed significantly lower than it opened, the rectangle is colored red.
- Neutral Movement: If the price ended roughly where it started (a "Doji" style movement), the rectangle is assigned a neutral yellow color.
Visual Output
Once the logic completes its calculation, it cleans the previous drawings and renders new, perfectly sized rectangles on your chart. This provides a clean, organized history of market behavior, helping you visualize where price stayed contained or moved aggressively during specific past intervals.
//+------------------------------------------------------------------+
//| GG-TimeBox.mq4 |
//| Copyright © 2009, GGekko |
//| http://www.fx-ggekko.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, GGekko"
#property link "http://www.fx-ggekko.com"
#property indicator_chart_window
extern string __Copyright__ = "www.fx-ggekko.com";
extern string HelpForCustomTF = "D1:1440 - H4:240 - H1:60 - ... - M5:5";
extern int CustomTF = PERIOD_D1;
extern int UnitToProcess = 20;
extern int DojiDiff = 2;
extern color UpColor = C'218,250,218';
extern color DownColor = C'250,211,211';
extern color DojiColor = C'255,245,195';
datetime starttime[],endtime[];
double lowprice[],highprice[];
int bars_in_one_rectangle;
color BarsColor[];
int ChartPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
ChartPeriod=Period();
//D1
if(CustomTF==PERIOD_D1)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=1440-1; break;
case PERIOD_M5 : bars_in_one_rectangle=288-1; break;
case PERIOD_M15: bars_in_one_rectangle=96-1; break;
case PERIOD_M30: bars_in_one_rectangle=48-1; break;
case PERIOD_H1 : bars_in_one_rectangle=24-1; break;
case PERIOD_H4 : bars_in_one_rectangle=6-1; break;
default : ChartPeriod=240;
}
}
//H4
else if(CustomTF==PERIOD_H4)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=240-1; break;
case PERIOD_M5 : bars_in_one_rectangle=48-1; break;
case PERIOD_M15: bars_in_one_rectangle=16-1; break;
case PERIOD_M30: bars_in_one_rectangle=8-1; break;
case PERIOD_H1 : bars_in_one_rectangle=4-1; break;
default : ChartPeriod=60;
}
}
//H1
else if(CustomTF==PERIOD_H1)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=60-1; break;
case PERIOD_M5 : bars_in_one_rectangle=12-1; break;
case PERIOD_M15: bars_in_one_rectangle=4-1; break;
case PERIOD_M30: bars_in_one_rectangle=2-1; break;
default : ChartPeriod=30;
}
}
//M30
else if(CustomTF==PERIOD_M30)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=30-1; break;
case PERIOD_M5 : bars_in_one_rectangle=6-1; break;
case PERIOD_M15: bars_in_one_rectangle=2-1; break;
default : ChartPeriod=15;
}
}
//M15
else if(CustomTF==PERIOD_M15)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=15-1; break;
case PERIOD_M5 : bars_in_one_rectangle=3-1; break;
default : ChartPeriod=5;
}
}
//M5
else if (CustomTF==PERIOD_M5)
{
switch(ChartPeriod)
{
case PERIOD_M1 : bars_in_one_rectangle=5-1; break;
default : ChartPeriod=1;
}
}
ArrayResize(starttime, UnitToProcess);
ArrayResize(endtime, UnitToProcess);
ArrayResize(lowprice, UnitToProcess);
ArrayResize(highprice, UnitToProcess);
ArrayResize(BarsColor, UnitToProcess);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int w=0; w<UnitToProcess; w++)
{
ObjectDelete("CustomTF"+w);
}
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
for(int w=0; w<UnitToProcess; w++)
{
ObjectDelete("CustomTF"+w);
}
for(w=0; w<UnitToProcess; w++)
{
starttime[w]=iTime(NULL,CustomTF,w);
endtime[w]=starttime[w]+bars_in_one_rectangle*Period()*60;
lowprice[w]=iLow(NULL,CustomTF,w);
highprice[w]=iHigh(NULL,CustomTF,w);
if(iOpen(NULL,CustomTF,w)<iClose(NULL,CustomTF,w)-(DojiDiff*Point)) BarsColor[w]=UpColor;
else if(iOpen(NULL,CustomTF,w)>iClose(NULL,CustomTF,w)+(DojiDiff*Point)) BarsColor[w]=DownColor;
else BarsColor[w]=DojiColor;
}
for(w=0; w<UnitToProcess; w++)
{
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],lowprice[w],endtime[w],highprice[w]);
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments