ATeam-3ZigzagLevel
Download scriptThis tool is designed to provide traders with a multi-layered perspective on market price movements by identifying key structural levels across different timeframes simultaneously. Instead of looking at just the immediate price action, it analyzes "ZigZag" patterns—which highlight significant peaks and valleys—on three distinct scales at once.
Core Logic and Functionality
Multi-Timeframe Analysis The script functions by pulling data from three different time horizons (defined as GrossPeriod 1, 2, and 3). By doing this, it allows a user to see the "big picture" trends without losing sight of the smaller, immediate price fluctuations. It automatically adjusts these timeframes based on the chart period you are currently viewing to ensure the data remains relevant and readable.
Structural Peak and Valley Identification The primary mechanism of the script relies on identifying two types of price points for each of the three timeframes:
- Peaks: High points in the price movement where a reversal might be occurring.
- Lows (Valleys): Low points in the price movement where support may be found.
The script scans historical data to find these specific levels and plots them as visual markers (arrows) on your chart. By categorizing them into three distinct sets, the tool helps differentiate between:
- Minor short-term fluctuations.
- Medium-term price structures.
- Major long-term trends.
Dynamic Time Alignment Because market data moves in real-time, the script includes logic to synchronize the different timeframes correctly. It uses a "search and shift" method to ensure that the data pulled from higher timeframes aligns perfectly with the current candle on your screen. This prevents visual errors where markers might appear disconnected from the actual price history.
Visual Filtering To keep the chart clean and readable, the logic includes a filtering process. It checks the current closing price against the identified ZigZag levels; it only displays specific markers (like "Peak 1" or "Lawn 3") when they meet specific criteria relative to the current price action. This helps the user focus on the most relevant structural levels rather than being overwhelmed by every single price tick.
Summary for the User
Essentially, this script acts as a "structural map." It tells you where the major turning points were in the past and across different time scales. By visualizing these peaks and valleys simultaneously, it helps traders identify where major support and resistance zones overlap, providing a clearer view of the market's underlying skeleton.
//+------------------------------------------------------------------+
//| ATeam-3ZigzagLevel.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright @2011, Rockyhoangdn"
#property link "rockyhoangdn@gmail.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_color2 Aqua
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 DarkViolet
#property indicator_color6 Green
//---- input parameters
extern int depth=12;
extern int deviation=5;
extern int backstep=3;
extern int GrossPeriod=0;
extern int GrossPeriod2=60;
extern int GrossPeriod3=240;
extern int Barss=1000;
extern int Shift=1;
int Shift2=1;
int Shift3=1;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
datetime daytimes[];
datetime daytimes2[];
datetime daytimes3[];
int ArrowCode=129;
int ArrowCode2=130;
int ArrowCode3=131;
int ArrowWidth=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexArrow(0,ArrowCode);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexLabel(0,"Peak 1");
SetIndexStyle(1,DRAW_ARROW,0,1);
SetIndexArrow(1,ArrowCode);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
SetIndexLabel(1,"Lawn 1");
SetIndexStyle(2,DRAW_ARROW,0,1);
SetIndexArrow(2,ArrowCode2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexEmptyValue(2,0.0);
SetIndexLabel(2,"Peak 2");
SetIndexStyle(3,DRAW_ARROW,0,1);
SetIndexArrow(3,ArrowCode2);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(3,0.0);
SetIndexLabel(3,"Lawn 2");
SetIndexStyle(4,DRAW_ARROW,0,3);
SetIndexArrow(4,ArrowCode3);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(4,0.0);
SetIndexLabel(4,"Peak 3");
SetIndexStyle(5,DRAW_ARROW,0,3);
SetIndexArrow(5,ArrowCode3);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexEmptyValue(5,0.0);
SetIndexLabel(5,"Lawn 3");
IndicatorShortName("ATeam-3ZigzagLevel-rockyhoangdn");
//----
//----
if (Period()>GrossPeriod) {GrossPeriod=Period();}
if (Period()>GrossPeriod2) {GrossPeriod2=Period();}
if (Period()>GrossPeriod3) {GrossPeriod3=Period();}
if (Period()==240){GrossPeriod=240; GrossPeriod2=1440;GrossPeriod3=10080;}
if (Period()==1440){GrossPeriod=1440; GrossPeriod2=10080;GrossPeriod3=43200;}
if (Period()==10080){GrossPeriod=10080; GrossPeriod2=10080;GrossPeriod3=43200;}
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),GrossPeriod);
ArrayCopySeries(daytimes2,MODE_TIME,Symbol(),GrossPeriod2);
ArrayCopySeries(daytimes3,MODE_TIME,Symbol(),GrossPeriod3);
if(GrossPeriod==Period()) Shift=0;
if(GrossPeriod2==Period()) Shift2=0;
if(GrossPeriod3==Period()) Shift3=0;
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit=300,bigshift,bigshift2,bigshift3;
double zigzag1,zigzag2,zigzag3,zigzag4,zigzag5,zigzag6,zigzag01,zigzag02,zigzag03;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
if (Barss>0) limit=Barss; else limit=Bars;
//----
for (int i=0; i<limit; i++)
{
if(Time[i]>=daytimes[0]) bigshift=0;
else
{
bigshift = ArrayBsearch(daytimes,Time[i-1],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<=GrossPeriod) bigshift++;
}
for (int cnt=bigshift; cnt<(1+bigshift); cnt++)
{
zigzag01=iCustom(NULL,GrossPeriod,"ZigZag2",depth,deviation,backstep,0,cnt+Shift);
zigzag1=iCustom(NULL,GrossPeriod,"ZigZag2",depth,deviation,backstep,1,cnt+Shift);
zigzag2=iCustom(NULL,GrossPeriod,"ZigZag2",depth,deviation,backstep,2,cnt+Shift);
if ( zigzag01!=0 ) break;
}
if ( iClose(NULL,0,i+1)<=zigzag1 ) ExtMapBuffer1[i]=zigzag1; else ExtMapBuffer1[i]=0.0;
if ( iClose(NULL,0,i+1)>=zigzag2 ) ExtMapBuffer2[i]=zigzag2; else ExtMapBuffer2[i]=0.0;
}
//----
//----
for (int i2=0; i2<limit; i2++)
{
if(Time[i2]>=daytimes2[0]) bigshift2=0;
else
{
bigshift2 = ArrayBsearch(daytimes2,Time[i2-1],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<=GrossPeriod2) bigshift2++;
}
for (int cnt2=bigshift2; cnt2<(1+bigshift2); cnt2++)
{
zigzag02=iCustom(NULL,GrossPeriod2,"ZigZag2",depth,deviation,backstep,0,cnt2+Shift2);
zigzag3=iCustom(NULL,GrossPeriod2,"ZigZag2",depth,deviation,backstep,1,cnt2+Shift2);
zigzag4=iCustom(NULL,GrossPeriod2,"ZigZag2",depth,deviation,backstep,2,cnt2+Shift2);
if ( zigzag02!=0 ) break;
}
if ( iClose(NULL,0,i2+1)<=zigzag3 ) ExtMapBuffer3[i2]=zigzag3; else ExtMapBuffer3[i2]=0.0;
if ( iClose(NULL,0,i2+1)>=zigzag4 ) ExtMapBuffer4[i2]=zigzag4; else ExtMapBuffer4[i2]=0.0;
}
//----
//----
for (int i3=0; i3<limit; i3++)
{
if(Time[i3]>=daytimes3[0]) bigshift3=0;
else
{
bigshift3 = ArrayBsearch(daytimes3,Time[i3-1],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<=GrossPeriod3) bigshift3++;
}
for (int cnt3=bigshift3; cnt3<(1+bigshift3); cnt3++)
{
zigzag03=iCustom(NULL,GrossPeriod3,"ZigZag2",depth,deviation,backstep,0,cnt3+Shift3);
zigzag5=iCustom(NULL,GrossPeriod3,"ZigZag2",depth,deviation,backstep,1,cnt3+Shift3);
zigzag6=iCustom(NULL,GrossPeriod3,"ZigZag2",depth,deviation,backstep,2,cnt3+Shift3);
if ( zigzag03!=0 ) break;
}
if ( iClose(NULL,0,i3+1)<=zigzag5 ) ExtMapBuffer5[i3]=zigzag5; else ExtMapBuffer5[i3]=0.0;
if ( iClose(NULL,0,i3+1)>=zigzag6 ) ExtMapBuffer6[i3]=zigzag6; else ExtMapBuffer6[i3]=0.0;
}
//----
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments