ZZZ_002
Download scriptThis script is designed to identify and map significant structural points in price movement by analyzing historical price data. It functions as a visual guide that helps traders distinguish between major highs and lows based on the "swing" of the market rather than just individual candle movements.
Core Logic Overview
The tool operates by scanning back through historical price bars (specifically starting from 300 bars ago) to establish a baseline for market structure. It uses a user-defined "Length" parameter to determine how much surrounding data it should look at when identifying a turning point. Instead of reacting instantly to every small fluctuation, it looks for specific patterns where the price creates a distinct peak or valley relative to its neighbors.
How it Identifies Market Movements
The logic follows a systematic process to categorize market behavior:
- Trend Identification: The script continuously monitors whether the current price movement is trending upward, downward, or moving sideways (neutral).
- Swing Detection: It looks for "Swings"—moments where the price shifts direction.
- If a new high is formed that exceeds the previous local high, it registers an upward movement.
- If a new low is formed that drops below the previous local low, it registers a downward movement.
- If a candle manages to cover both a new high and a new low within the specified length (a "breakout" candle), the script treats this as a neutral zone and resets its tracking to find the next clear direction.
- Peak and Valley Mapping: Once a trend is confirmed, the script "locks in" the highest point of an upward swing or the lowest point of a downward swing. It stores these specific values so they can be plotted on your chart.
Visual Output
The result of this logic is a series of plotted points (represented in Aqua) that mark the significant structural boundaries of the market.
- When the market is moving up, it captures the highest points to define the "ceiling."
- When the market is moving down, it captures the lowest points to define the "floor."
By filtering out minor market noise and only highlighting these primary structural points, the tool helps provide a clearer picture of the underlying market geometry.
//+------------------------------------------------------------------+
//| ZZZ.mq4 |
//+------------------------------------------------------------------+
#property copyright "Istoniz"
#property link "http://www.kg/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Aqua
//---- input parameters
extern int Length=6;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_SECTION);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int barn=300;
/*
//--------------------------
int counted_bars=IndicatorCounted();
limit,barn=Bars-Length;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars+4*Length;
//Comment(" limit = ",limit, " Bars = ",Bars);
//--------------------------
*/
//--------------------------
int shift,Swing,Swing_n,i,zu,zd,uzl;
double LL,HH,BH,BL,NH,NL;
Swing_n=0; Swing=0; uzl=0;
BH =High[barn]; BL=Low[barn];
zu=barn; zd=barn;
for ( shift=barn; shift>0 ; shift--)
{
LL=10000000; HH=-100000000;
for ( i=shift+Length; i>shift+1 ; i--)
{
if ( Low[i]<LL ) LL=Low[i];
if ( High[i]>HH ) HH=High[i];
}
if ( Low[shift]<LL && High[shift]>HH )
{
Swing=2;
if ( Swing_n==1 ) zu=shift+1;
if ( Swing_n==-1 ) zd=shift+1;
} else
{
if ( Low[shift]<LL ) Swing=-1;
if ( High[shift]>HH ) Swing=1;
}
if ( Swing!=Swing_n && Swing_n!=0 )
{
if ( Swing==2 )
{
Swing=-Swing_n;
BH=High[shift];
BL=Low[shift];
}
uzl=uzl+1;
if ( Swing==1 )
{
ExtMapBuffer1[zd]=BL;
}
if ( Swing==-1 )
{
ExtMapBuffer1[zu]=BH;
}
BH=High[shift];
BL=Low[shift];
}
if ( Swing==1 )
{
if ( High[shift]>=BH )
{
BH=High[shift];
zu=shift;
}
}
if ( Swing==-1 )
{
if ( Low[shift]<=BL )
{
BL=Low[shift];
zd=shift;
}
}
Swing_n=Swing;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments