Grid Builder_v2
Download scriptVisual Grid Generation Logic
This script is designed to automatically generate a structured visual grid on your trading charts. It helps traders by providing a consistent reference system of horizontal lines, allowing for easier identification of price levels across the current market environment.
How it Works:
The tool functions by analyzing the most recent market activity to determine the appropriate area for the grid. Here is the step-by-step logic:
- Dynamic Range Detection: The script looks back at the most recent price action (the "Highs" and "Lows") on the chart. It identifies the highest and lowest points reached within a specific recent timeframe to establish the boundaries of where the grid should appear.
- Automatic Scaling: To ensure the grid remains relevant regardless of which asset you are trading (e.g., Forex, Gold, or Indices), the script calculates a mathematical divisor. This allows it to translate raw price numbers into a standardized spacing that feels consistent to the human eye.
- Precision Placement: Once the high and low boundaries are set, the script populates the space between them with horizontal lines. It uses a specific "Grid Space" setting to determine how many lines to draw, ensuring they are evenly spaced rather than cluttered.
- Visual Consistency: Every line generated is styled as a solid gray horizontal line. This provides a neutral background that helps you visualize price movement without distracting from the primary candlesticks or moving averages.
- Automatic Cleanup: The script includes a "deinitialization" process. When you remove the indicator from your chart, it automatically clears the lines it created. This keeps your workspace clean and prevents old grid lines from remaining on the screen once they are no longer needed.
Key Purpose:
The primary goal of this script is to provide a "map" of the price action. By creating a steady grid based on recent peaks and valleys, it helps traders maintain a sense of scale and perspective when analyzing market trends.
//+------------------------------------------------------------------+
//| 2Extreme4U Grid Builder.mq4 |
//| Copyright © 2005, Siddiqi, Alejandro Galindo |
//| http://elCactus.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Siddiqi, Alejandro Galindo"
#property link "http://elCactus.com"
#property indicator_chart_window
extern int GridSpace=50;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
double shift=0;
double HighPrice=0;
double LowPrice=0;
double Divisor = 0.1/Point;
HighPrice = MathRound(High[Highest(NULL,0,2, Bars - 2, 2)] * Divisor);
//SL = High[Highest(MODE_HIGH, SLLookback, SLLookback)];
LowPrice = MathRound(Low[Lowest(NULL,0,1, Bars - 1, 2)] * Divisor);
for(shift=LowPrice;shift<=HighPrice;shift++)
{
ObjectDelete("Grid"+shift);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double I=0;
double HighPrice=0;
double LowPrice=0;
int GridS=0;
int SL=0;
//----
double Divisor = 0.1/Point;
HighPrice = MathRound(High[Highest(NULL,0,MODE_HIGH, Bars - 2, 2)] * Divisor);
//SL = High[Highest(MODE_HIGH, SLLookback, SLLookback)];
LowPrice = MathRound(Low[Lowest(NULL,0,MODE_LOW, Bars - 1, 2)] * Divisor);
GridS = GridSpace / 10;
for(I=LowPrice;I<=HighPrice;I++)
{
//Print("mod(I, GridSpace): " + MathMod(I, GridS) + " I= " + I);
//Print(LowPrice + " " + HighPrice);
if (MathMod(I, GridS) == 0)
{
if (ObjectFind("Grid"+I) != 0)
{
ObjectCreate("Grid"+I, OBJ_HLINE, 0, Time[1], I/Divisor);
ObjectSet("Grid"+I, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("Grid"+I, OBJPROP_COLOR, Gray);
}
//MoveObject(I + "Grid", OBJ_HLINE, Time[Bars - 2], I/1000, Time[1], I/1000, MediumSeaGreen, 1, STYLE_SOLID);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments