i_Model_ZZ
Download scriptThis tool is designed to analyze market trends by visualizing price movements across three different timeframes simultaneously. Instead of looking at just one chart view, it gathers data from multiple perspectives to provide a more comprehensive picture of the market's structural "zig-zags."
Core Logic Overview
The script functions by identifying significant price peaks and valleys (turning points) on three distinct time horizons: Large, Middle, and Small. By processing these three layers, the tool helps users see how short-term price action fits into broader long-term trends.
How it Works:
- Multi-Timeframe Analysis: The script automatically looks at three different time periods (defined by user settings). It calculates the structural "zig-zags" for each of these periods independently.
- Data Synchronization: Because different timeframes have different price points, the script performs a translation process. It identifies a turning point on a higher timeframe and then "maps" it back onto your current viewing chart. This ensures that even though the data comes from a different timeframe, it aligns correctly with the bars you see on your screen.
- Peak and Valley Detection: For every identified turning point on the larger timeframes, the script looks for the highest high or the lowest low within a specific range. It then marks these precise levels on your chart as distinct lines.
- Stability Feature: A key characteristic of this logic is its "non-repainting" approach for completed data. Once a turning point is finalized on a past bar, the script ensures that the data remains fixed. This provides a more reliable historical view of price structure, as finished points won't shift or disappear as new price action occurs.
Visual Output:
The result is three distinct sets of lines displayed on your chart:
- Large Scale: Represents the broadest market trends (the "big picture").
- Middle Scale: Represents intermediate price movements.
- Small Scale: Represents more immediate, short-term fluctuations.
By observing these three layers together, traders can better understand whether a current price move is part of a minor fluctuation or a significant shift in the overarching market direction.
//--------------------------------------------------------------------
// ind_Model_ZZ.mq4
// Âûáîð çèã-çàãà Êîñèöèíà îáóñëîâëåí òåì, ÷òî ïîñëå ïîÿâëåíèÿ
// êîí÷èêà, ïðåäûäóùèé óçåë óæå íå ïåðåðèñîâûâàåòñÿ
//--------------------------------------------------------------------
#property copyright "Copyright © 2008, BiViSi Corp."
#property link "riderfin@bk.ru"
#property link "ICQ 499494112"
#property indicator_chart_window
#property indicator_buffers 3
//---- ñòèëü èíäèêàòîðíîé ëèíèè
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_style1 0
#property indicator_style2 0
#property indicator_style3 1
#property indicator_width1 3
#property indicator_width2 2
#property indicator_width3 1
//---- ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ
extern int Depth=12;
extern int Deviation=5;
extern int Backstep=3;
extern int TFLarge=1440;
extern int TFMidle=240;
extern int TFSmall=60;
double ZZ_Large[],ZZ_Midle[], ZZ_Small[]; // Îáúÿâëåíèå ìàññèâîâ (ïîä áóôåðû èíäèêàòîðà)
double CurExt[5],TimeBars[5],CtrlTimes[]; //,CurMidle[5][1],CurSmall[5][1];
static datetime PrevTimeZigZagCalc;
static int CurPeriod;
//--------------------------------------------------------------------
int init()
{
SetIndexBuffer(0,ZZ_Large); SetIndexStyle(0,DRAW_SECTION); SetIndexEmptyValue(0,0.0); // ìîæåò áóôåðû òîæå ?????
SetIndexBuffer(1,ZZ_Midle); SetIndexStyle(1,DRAW_SECTION); SetIndexEmptyValue(1,0.0); // â ôóíêöèè ?????
SetIndexBuffer(2,ZZ_Small); SetIndexStyle(2,DRAW_SECTION); SetIndexEmptyValue(2,0.0); // èíèöèàëèçèðîâàòü ?????
PrevTimeZigZagCalc=0; CurPeriod=Period();
return;
}
//--------------------------------------------------------------------
int start()
{
// êîíòðîëü ÒÔ è ââåäåííûõ ïàðàìåòðîâ
if (CurPeriod > TFSmall) {Alert ("Ïåðèîä ãðàôèêà äîëæåí áûòü ìåíüøå èëè ðàâåí ", TFSmall, " ìèí.");return;}
if (TFSmall >= TFMidle || TFMidle >= TFLarge) {Alert ("Íåêîððêòíûé âûáîð òàéìôðåéìîâ äëÿ ðàñ÷åòà");return;}
ZigZagCalc();
return;
}
//======================================================================
// âû÷èñëåíèå óçëîâ çèãçàãà íà ñòàðøèõ ÒÔ è îòîáðàæåíèå íà òåêóùåì
//======================================================================
void ZigZagCalc ()
{
// âû÷èñëåíèå îäèí ðàç òîëüêî íà ïîëíîñòüþ ñôîðìèðîâàâøåìñÿ áàðå
if (PrevTimeZigZagCalc == Time[0]) return;
// âû÷èñëåíèå "VolExt" ïîñëåäíèõ ýêñòðåìóìîâ íà ñòàðøèõ ÒÔ
int i, x, y, k, VolExt=5, NumberExt, Per;
int sh, limit, dn, up;
double zz_Dn, zz_Up;
for (y=1; y<=3; y++)
{
if (y==1) Per=TFLarge; else if (y==2) Per=TFMidle; else Per=TFSmall;
// Âû÷èñëÿåì èçëîìû òîëüêî ñ îêîí÷àíèåì ôîðìèðîâàíèÿ áàðà ñòàðøåãî ÒÔ
int t=MathCeil(Time[0]/Per/60-1)*Per*60;
k=iBarShift(NULL,Per,t,true); if (k < 0) continue;
i=iBars(NULL,Per);
if (y==1) ArrayInitialize(TFLarge,0.0); else if (y==2) ArrayInitialize(TFMidle,0.0); else ArrayInitialize(TFSmall,0.0);
NumberExt=0;
for (x=k; x<i; x++)
{
zz_Dn=iCustom( NULL, Per,"i_ZigZag_NK",Depth,Deviation,Backstep,0, x );
if (zz_Dn !=0)
{
NumberExt++;
sh=iBarShift(NULL,CurPeriod,iTime(NULL,Per,x),false);
limit=sh+Per/CurPeriod-1;
dn=iLowest(NULL,0,MODE_LOW,Per/CurPeriod,limit);
if (y==1)ZZ_Large[dn]=Low[dn]; else if (y==2)ZZ_Midle[dn]=Low[dn]; else ZZ_Small[dn]=Low[dn];
}
zz_Up=iCustom( NULL, Per,"i_ZigZag_NK",Depth,Deviation,Backstep,1, x );
if (zz_Up !=0)
{
NumberExt++;
sh=iBarShift(NULL,CurPeriod,iTime(NULL,Per,x),false);
limit=sh+Per/CurPeriod-1;
up=iHighest(NULL,0,MODE_HIGH,Per/CurPeriod,limit);
if (y==1)ZZ_Large[up]=High[up]; else if (y==2)ZZ_Midle[up]=High[up]; else ZZ_Small[up]=High[up];
}
//if (NumberExt>VolExt-1) break;
}
}
PrevTimeZigZagCalc=Time[0]; // âû÷èñëèëè
return;
}
//--------------------------------------------------------------------
Comments