Diapazon_v1
Download scriptThis script is designed to provide a visual representation of price volatility and market structure by identifying key boundaries on your trading chart. It automatically calculates and plots three distinct data points based on historical price movement, helping traders understand the current "trading range" at a glance.
How the Logic Works
The tool operates by analyzing a specific window of historical data (defined by the period) to establish the following three components:
- Upper Boundary: The script scans the last 24 bars of price action (by default) and identifies the highest point reached. It then draws a solid line representing this ceiling. This helps identify the immediate resistance level where the price has peaked recently.
- Lower Boundary: Simultaneously, the script looks at the same timeframe to find the lowest point reached. It draws a second solid line representing this floor, identifying the immediate support level.
- Median Line: To provide a center point for the market's movement, the script calculates the exact midpoint between the Upper and Lower boundaries. This is displayed as a dotted line, representing the "equilibrium" or fair value of the current range.
Dynamic Real-Time Monitoring
The logic is programmed to cycle through your chart history to ensure the lines move accurately as new price data arrives. Because it constantly re-evaluates the highest highs and lowest lows of the defined period, the boundaries adjust dynamically to the current market conditions.
Automated Data Summary
In addition to the visual lines on the chart, the script performs a real-time calculation to determine the total size of the current trading range in points. This value is displayed as an automated text comment directly on your screen. This allows you to instantly see how wide the "swing" between the high and low is without having to perform any manual calculations.
//+------------------------------------------------------------------+
//| |
//| Copyright © 2000-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru |
//+------------------------------------------------------------------+
// Äèàïàçîí.mq4
// Èíäèêàòîð
#property copyright "mandorr@gmail.com"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 SkyBlue
#property indicator_color2 SkyBlue
#property indicator_color3 SkyBlue
//----
extern int period=24; // Ïåðèîä (êîëè÷åñòâî áàðîâ äèàïàçîíà)
extern int CountBars=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ
//----
double buffer0[];
double buffer1[];
double buffer2[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void init()
{
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,buffer0);
SetIndexLabel(0,"Âåðõíÿÿ ãðàíèöà");
SetIndexDrawBegin(0,0);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(1,buffer1);
SetIndexLabel(1,"Íèæíÿÿ ãðàíèöà");
SetIndexDrawBegin(1,0);
SetIndexStyle(2,DRAW_LINE,STYLE_DOT,1);
SetIndexBuffer(2,buffer2);
SetIndexLabel(2,"Ìåäèàíà");
SetIndexDrawBegin(2,0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void deinit()
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void start()
{
for(int i=0;i<=CountBars-1;i++)
{
buffer0[i]=High[Highest(NULL,0,MODE_HIGH,period,i)];
buffer1[i]=Low [Lowest (NULL,0,MODE_LOW ,period,i)];
buffer2[i]=(buffer0[i]+buffer1[i])/2;
}
double range=(buffer0[0]-buffer1[0])/Point;
Comment("Äèàïàçîí: "+DoubleToStr(range,0)+" ï.");
}
//+------------------------------------------------------------------+
Comments