(m)_Dinap tar. zig zag
Download scriptThis script is designed for the MetaTrader trading platform to identify and visualize significant price movements on a financial chart. By analyzing historical price action, it filters out minor market noise to highlight the core "skeleton" of the price trend—specifically identifying major highs and lows.
How the Logic Works
1. Historical Data Analysis The script looks back at a substantial amount of historical data (defined by the "barn" parameter) to understand the prior price context. It scans these past prices to establish a baseline for what constitutes a normal price fluctuation versus an extraordinary move.
2. Identifying Significant "Swings" The core logic relies on comparing current price points against a specific window of surrounding candles (the "Length" parameter). Instead of reacting to every tiny tick, the script evaluates whether a price point is high or low enough relative to its neighbors to be considered a "Swing."
- It looks for Higher Highs and Lower Lows to determine the direction of the trend.
- If a price moves significantly beyond the previous established boundaries, the script recognizes this as a new structural point in the market.
3. Trend Tracking and Memory The script maintains a running memory of these significant points. As it moves across the chart from left to right, it keeps track of:
- The highest peaks reached during an upward trend.
- The lowest troughs reached during a downward trend.
When the logic detects that the price has shifted its behavior (for example, moving from making new highs to making new lows), it captures the exact coordinates of those turning points.
4. Visual Mapping Once these significant structural points are identified, the script "maps" them back onto your chart. It connects these key peaks and valleys into a continuous line (a ZigZag). This allows traders to see the underlying structure of the market clearly, making it easier to identify support levels, resistance zones, and overall trend reversals without being distracted by minor price fluctuations.
Summary for the User
Essentially, this tool acts as a filter. It ignores the "static" of the daily market and draws a line connecting only the most important high and low points. It helps you see where the price has truly "turned" or "broken out," providing a clearer visual path of the market's journey.
//+------------------------------------------------------------------+
//| Dinapoli ZZ (ZigZag).mq4 |
//| rewritten by CrazyChart |
//| |
//+------------------------------------------------------------------+
#property copyright "rewritten by CrazyChart"
#property link ""
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int barn=300;
extern int Length=6;
//---- buffers
double ExtMapBuffer1[];
//double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexEmptyValue(0,0.0);
//SetIndexDrawBegin(0, barn);
SetIndexStyle(0,DRAW_SECTION);
SetIndexBuffer(0,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int shift,Swing,Swing_n,uzl,i,zu,zd,mv;
double LL,HH,BH,BL,NH,NL;
double Uzel[10000][3];
string text;
// loop from first bar to current bar (with shift=0)
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) {
Uzel[uzl][1]=zd;
Uzel[uzl][2]=BL;
}
if (Swing==-1) {
Uzel[uzl][1]=zu;
Uzel[uzl][2]=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;
}
for (i=1;i<=uzl;i++) {
//text=DoubleToStr(Uzel[i][1],0);
//text=;
mv=StrToInteger(DoubleToStr(Uzel[i][1],0));
ExtMapBuffer1[mv]=Uzel[i][2];
}
return(0);
}
//+------------------------------------------------------------------+
Comments