Setka_v1
Download scriptThis script is designed to automatically organize and visualize the price action on your trading chart by creating a structured grid of horizontal reference lines. Instead of manual plotting, the tool analyzes the current visible price range to determine the most appropriate spacing for these markers based on market volatility.
How the Logic Works:
Dynamic Range Analysis The script begins by scanning the current visible area of your chart to identify the highest and lowest price points reached recently. It calculates the total vertical distance between these two extremes. This allows the tool to understand the "scale" of the market you are currently observing, ensuring that the grid remains relevant whether you are looking at a high-value asset or a low-value one.
Adaptive Grid Spacing One of the core features of this logic is its ability to adjust itself automatically. Rather than using a fixed distance between lines, the script evaluates the intensity of the price movement:
- In highly volatile markets with large price swings, it spaces the lines further apart to avoid cluttering the screen.
- In calmer or tighter markets, it automatically tightens the spacing to provide more frequent reference points.
Automated Grid Generation Once the script determines the ideal spacing (the "Step"), it calculates a minimum and maximum boundary based on your current view. It then systematically draws a series of horizontal lines across the chart. These lines are generated dynamically, ensuring that they cover the entire relevant price area from bottom to top.
Visual Management To keep your workspace clean, the script includes a self-cleaning mechanism. Every time the indicator updates, it identifies and removes any old grid lines created by previous calculations. This prevents "ghost" lines from accumulating on your screen, ensuring that only the current, relevant grid is visible at any given time.
Summary for the Trader Essentially, this tool acts as an automated layout assistant. It looks at how much the price is moving, decides on a logical "step" size to keep the chart readable, and paints a clean, organized grid of horizontal levels that adapt instantly as you scroll through different price zones.
//+------------------------------------------------------------------+
//| _KON12_R01.mq4 |
//| Copyright © 2008, Dante Software |
//| |
//+------------------------------------------------------------------+
#property copyright "kon12"
#property link ""
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
extern int LineMax = 8;
extern color LineColor = Silver;
double S,P,Step,Smin,Smax;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,S);
SetIndexStyle(0,DRAW_LINE,2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
S = 1.05*(High[ArrayMaximum(High,WindowFirstVisibleBar(),0)]
-Low[ArrayMinimum(Low,WindowFirstVisibleBar(),0)])/LineMax/Point/10;
if (S==P) {return(0);}
for(int r=1; r>=0; r--)
{
for (int i=ObjectsTotal()-1; i>=0 ; i--)
{if (StringFind (ObjectName(i), "Setka") >= 0) ObjectDelete (ObjectName(i)) ;}
Step=20000*Point;
if (S>500 && S<=1000) {Step=10000*Point;}
if (S>200 && S<=500) {Step=5000*Point;}
if (S>100 && S<=200) {Step=2000*Point;}
if (S>50 && S<=100) {Step=1000*Point;}
if (S>20 && S<=50) {Step=500*Point;}
if (S>10 && S<=20) {Step=200*Point;}
if (S<=10) {Step=100*Point;}
Smin=MathRound(Low[ArrayMinimum(Low,WindowFirstVisibleBar(),0)]/Step-2)*Step;
Smax=MathRound(High[ArrayMaximum(High,WindowFirstVisibleBar(),0)]/Step+2)*Step;
for (double Sprice = Smin; Sprice <= Smax; Sprice += Step) {
string Sname = "Setka"+DoubleToStr(Sprice,Digits);
ObjectCreate (Sname, OBJ_HLINE, 0, 0, Sprice);
ObjectSet (Sname, OBJPROP_COLOR, LineColor);
ObjectSet (Sname, OBJPROP_STYLE, 2);
ObjectSet (Sname, OBJPROP_BACK, 0);
}}
P=S;
return(0);
}
//+------------------------------------------------------------------+
Comments