ZigZag_Fibo_NoAlert
Download scriptThis script is designed to analyze price movements on a trading chart by identifying and highlighting significant structural turning points. It simplifies complex market data into a visual "path" of highs and lows, making it easier for traders to see the overall direction of the market.
Core Functionality
The primary purpose of this tool is to filter out minor price fluctuations (market noise) and pinpoint major peaks and valleys. By doing this, it allows you to see the "skeleton" of the price action—the major swings that define where the trend is moving.
How the Logic Works
The script operates through a multi-step filtering process:
1. Identifying Significant Peaks and Valleys Instead of looking at every single price tick, the script scans a specific window of recent data (defined by the "Depth" setting). It looks for points that are significantly higher or lower than their immediate surroundings. If a price movement is too small, the script ignores it; if it meets your specific criteria for distance, it marks it as a potential turning point.
2. Refining the Path Once the initial peaks and valleys are found, the script performs a "cleaning" pass. It compares these points against each other to ensure they are logical. For example, if a new high is discovered that is higher than a previous one nearby, it will prioritize the newer, more significant high. This ensures that the resulting line on your chart doesn't jump around erratically but follows a smooth, logical progression of market structure.
3. Structural Mapping The tool creates two distinct sets of data points: one for local "floors" (lows) and one for local "ceilings" (highs). It organizes these points in chronological order so that you can clearly see the sequence of market reactions.
Automatic Fibonacci Tooling
A unique feature of this script is its final step. Once it has identified the most recent major peak and the one preceding it, it automatically draws a Fibonacci Retracement object on your chart.
By automatically placing this tool between the two most recent significant turning points, the script helps you instantly see potential support and resistance levels without having to manually click on the chart to draw them.
Summary for the User
Think of this script as an automated "trend map." It scans the history of the candles, throws out the tiny movements that don't matter, identifies the major mountains and valleys of the price action, and then automatically places a Fibonacci tool over the most recent significant move to help you plan your next trade.
// fukinagashi
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
//---- indicator buffers
double ExtMapBuffer[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
//---- drawing settings
SetIndexStyle(0,DRAW_SECTION);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(0,0.0);
ArraySetAsSeries(ExtMapBuffer,true);
ArraySetAsSeries(ExtMapBuffer2,true);
//---- indicator short name
IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
return(0);
}
int deinit() {
ObjectDelete("Fibo");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int shift, back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;
for(shift=Bars-ExtDepth; shift>=0; shift--)
{
val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer[shift+back];
if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;
}
}
}
ExtMapBuffer[shift]=val;
//--- high
val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer2[shift+back];
if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;
}
}
}
ExtMapBuffer2[shift]=val;
}
// final cutting
lasthigh=-1; lasthighpos=-1;
lastlow=-1; lastlowpos=-1;
for(shift=Bars-ExtDepth; shift>=0; shift--)
{
curlow=ExtMapBuffer[shift];
curhigh=ExtMapBuffer2[shift];
if((curlow==0)&&(curhigh==0)) continue;
//---
if(curhigh!=0)
{
if(lasthigh>0)
{
if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
else ExtMapBuffer2[shift]=0;
}
//---
if(lasthigh<curhigh || lasthigh<0)
{
lasthigh=curhigh;
lasthighpos=shift;
}
lastlow=-1;
}
//----
if(curlow!=0)
{
if(lastlow>0)
{
if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
else ExtMapBuffer[shift]=0;
}
//---
if((curlow<lastlow)||(lastlow<0))
{
lastlow=curlow;
lastlowpos=shift;
}
lasthigh=-1;
}
}
for(shift=Bars-1; shift>=0; shift--)
{
if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0;
else
{
res=ExtMapBuffer2[shift];
if(res!=0.0) ExtMapBuffer[shift]=res;
}
}
int i=0;
int LastZigZag, PreviousZigZag;
/*
for(int h=0; h<Bars && i<=2; h++)
{
if (ExtMapBuffer[h]!=0) {
i++;
if (i==1) { LastZigZag=h;
} else { PreviousZigZag=h; }
} else if (ExtMapBuffer2[h]!=0) {
i++;
if (i==1) { LastZigZag=h;
} else { PreviousZigZag=h; }
}
}
*/
int h=0;
while ( ExtMapBuffer[h]==0 && ExtMapBuffer2[h]==0) {
h++;
}
LastZigZag=h;
h++;
while(ExtMapBuffer[h]==0 && ExtMapBuffer2[h]==0) {
h++;
}
PreviousZigZag=h;
ObjectCreate("Fibo", OBJ_FIBO, 0, Time[PreviousZigZag], ExtMapBuffer[PreviousZigZag], Time[LastZigZag], ExtMapBuffer[LastZigZag]);
}
Comments