ArrZZx2 v3.9

Download script
Author: Copyright � 2008 Kirill, 2007 Bookkeeper
ArrZZx2 v3.9

This script is a sophisticated technical analysis tool designed to identify complex price trends and potential turning points in financial markets. Rather than relying on simple price movements, it uses a multi-layered calculation system to filter out "noise" and highlight significant structural shifts.

Here is a breakdown of the logic used by the tool:

Multi-Layered Data Processing

The script does not look at the raw price alone. It processes data through several stages to create a smoother, more reliable picture of the market:

  • Dynamic Price Smoothing: The tool starts by taking a specific type of price (such as the Closing price or the Median price) and applies a weighted moving average. This helps stabilize the data so that minor, insignificant fluctuations do not trigger false signals.
  • Adaptive Trend Identification: It then takes this smoothed data and performs further calculations to identify "peaks" and "valleys." By looking for local maximums and minimums over specific windows of time, it establishes the core structure of the current trend.

Trend Analysis and Logic

Once the underlying trend is established, the script focuses on two primary behaviors:

  1. Momentum and Direction: It identifies whether the price is moving upward or downward by comparing current highs and lows against the previously established peaks.
  2. Breakout and Reversal Detection: The core logic looks for specific "breakthrough" moments. It tracks when the price successfully moves beyond a previous structural point and holds that position. When these conditions are met, it marks potential areas of interest.

Visual Indicators

The script translates all this complex math into visual cues on your chart:

  • Trend Confirmation: It provides specific signals (represented as histograms or arrows) when the market transitions from one state to another—for example, confirming a move from a downward trend to an upward one.
  • Potential Reversals: One of the script's primary roles is to highlight "limit" points. These are areas where the logic suggests that a current move might be exhausted and a reversal could occur.
  • Multi-Timeframe Capability: A unique feature of this script is its ability to analyze higher timeframes while you are looking at a lower one. It can "reach out" to grab data from larger charts (like a Daily chart) to inform the signals on your current view, ensuring that you aren't trading against a larger market trend.

Summary for the User

In essence, this tool acts as a trend filter. It ignores the "jitter" of the market and instead tries to find the "skeleton" of the price movement. By calculating weighted averages, identifying historical peaks/valleys, and monitoring for specific structural breakouts, it aims to show you where the trend is strong and where it might be reaching a point of exhaustion.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
9 Views
1 Downloads
0 Favorites
ArrZZx2 v3.9
//+------------------------------------------------------------------+
//|                                                      ArrZZx2.mq4 |
//|                          Copyright © 2008 Kirill, 2007 Bookkeeper|
//|                    StockProgrammer@mail.ru, yuzefovich@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008 Kirill, 2007 Bookkeeper"
#property link      "StockProgrammer@mail.ru, yuzefovich@gmail.com"

//----
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 8
#property indicator_color1  MediumBlue
#property indicator_color2  RoyalBlue
#property indicator_color3  Blue
#property indicator_color4  Blue
#property indicator_color5  DarkGreen
#property indicator_color6  Red
#property indicator_color7  DarkGreen
#property indicator_color8  Red
//--------------------------------------------------------------------
extern int    period       =  0;       //ïåðèîä äëÿ ðàñ÷¸òà. Íå ìîæåò áûòü ìåíüøå ïåðèîäà ãðàôèêà.
extern int    SR           =  3;       // =3..4
extern int    SRZZ         =  12;      // =4..12..20
extern int    MainRZZ      =  20;      // =12..20..54...
extern int    FP           =  21;
extern int    SMF          =  3;       // =1..5
extern bool   DrawZZ       =  false;
extern int    PriceConst   =  0;       // 0 - Close
                                       // 1 - Open
                                       // 2 - High
                                       // 3 - Low
                                       // 4 - (H+L)/2
                                       // 5 - (H+L+C)/3
                                       // 6 - (H+L+2*C)/4
//extern string Prefix="ArrZZx2"; 
//--------------------------------------------------------------------
double        Lmt[];
double        LZZ[];
double        SA[];
double        SM[];
double        Up[];
double        Dn[];
double        pUp[];
double        pDn[];

string name;
//---------------------------------------------------------------------
int LTF[6]={0,0,0,0,0,0},STF[5]={0,0,0,0,0}; 
int MaxBar, nSBZZ, nLBZZ, SBZZ, LBZZ;
bool First=true;
int prevBars=0;
//---------------------------------------------------------------------
void MainCalculation(int Pos) {
if((Bars-Pos)>(SR+1)) SACalc(Pos); else SA[Pos]=0; 
if((Bars-Pos)>(FP+SR+2)) SMCalc(Pos); else SM[Pos]=0; return; }
//---------------------------------------------------------------------
void SACalc(int Pos) { int sw, i, w, ww, Shift; double sum; 
switch(PriceConst) {
case  0: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_CLOSE,Pos);
  break;
case  1: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_OPEN,Pos);
  break;
/*case  2: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_HIGH,Pos);
  break;
case  3: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_LOW,Pos);
  break;*/
case  4: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_MEDIAN,Pos);
  break;
case  5: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_TYPICAL,Pos);
  break;
case  6: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_WEIGHTED,Pos);
  break;
default: 
  SA[Pos]=iMA(NULL,0,SR+1,0,MODE_LWMA,PRICE_OPEN,Pos);
  break; }
for(Shift=Pos+SR+2;Shift>Pos;Shift--) { sum=0.0; sw=0; i=0; w=Shift+SR;
ww=Shift-SR; if(ww<Pos) ww=Pos;
while(w>=Shift) {i++; sum=sum+i*SnakePrice(w); sw=sw+i; w--; }
while(w>=ww) { i--; sum=sum+i*SnakePrice(w); sw=sw+i; w--; }
SA[Shift]=sum/sw; } return; }
//----
double SnakePrice(int Shift) {
switch(PriceConst) {
   case  0: return(Close[Shift]);
   case  1: return(Open[Shift]);
   /*case  2: return(High[Shift]);
   case  3: return(Low[Shift]);*/
   case  4: return((High[Shift]+Low[Shift])/2);
   case  5: return((Close[Shift]+High[Shift]+Low[Shift])/3);
   case  6: return((2*Close[Shift]+High[Shift]+Low[Shift])/4);
   default: return(Open[Shift]); } }
//---------------------------------------------------------------------
void SMCalc(int i) { double t, b;
for(int Shift=i+SR+2;Shift>=i;Shift--) {
t=SA[ArrayMaximum(SA,FP,Shift)]; b=SA[ArrayMinimum(SA,FP,Shift)];
SM[Shift]=(2*(2+SMF)*SA[Shift]-(t+b))/2/(1+SMF); } return; }
//---------------------------------------------------------------------
void LZZCalc(int Pos) { 
int i,RBar,LBar,ZZ,NZZ,NZig,NZag; 
i=Pos-1; NZig=0; NZag=0;
while(i<MaxBar && ZZ==0) { i++; LZZ[i]=0; RBar=i-MainRZZ; 
if(RBar<Pos) RBar=Pos; LBar=i+MainRZZ;
if(i==ArrayMinimum(SM,LBar-RBar+1,RBar)) { ZZ=-1; NZig=i; }
if(i==ArrayMaximum(SM,LBar-RBar+1,RBar)) { ZZ=1;NZag=i; } }
if(ZZ==0) return; NZZ=0;
if(i>Pos) { if(SM[i]>SM[Pos]) { if(ZZ==1) {
if(i>=Pos+MainRZZ && NZZ<5) { NZZ++; LTF[NZZ]=i; } NZag=i; 
LZZ[i]=SM[i]; } }
else { if(ZZ==-1) { if(i>=Pos+MainRZZ && NZZ<5) { NZZ++; LTF[NZZ]=i; }
NZig=i; LZZ[i]=SM[i]; } } }
while(i<LBZZ || NZZ<5) {  LZZ[i]=0; RBar=i-MainRZZ; 
if(RBar<Pos) RBar=Pos; LBar=i+MainRZZ;
if(i==ArrayMinimum(SM,LBar-RBar+1,RBar)) {
if(ZZ==-1 && SM[i]<SM[NZig]) { 
if(i>=Pos+MainRZZ && NZZ<5) LTF[NZZ]=i; LZZ[NZig]=0; LZZ[i]=SM[i]; 
NZig=i; }
if(ZZ==1) { if(i>=Pos+MainRZZ && NZZ<5) { NZZ++; LTF[NZZ]=i; } 
LZZ[i]=SM[i]; ZZ=-1; NZig=i; } }
if(i==ArrayMaximum(SM,LBar-RBar+1,RBar)) {
if(ZZ==1 && SM[i]>SM[NZag]) { 
if(i>=Pos+MainRZZ && NZZ<5) LTF[NZZ]=i; LZZ[NZag]=0; LZZ[i]=SM[i]; 
NZag=i; }
if(ZZ==-1) { if(i>=Pos+MainRZZ && NZZ<5) { NZZ++; LTF[NZZ]=i; } 
LZZ[i]=SM[i]; ZZ=1; NZag=i; } } i++; if(i>MaxBar) return; } 
nLBZZ=Bars-LTF[5]; LZZ[Pos]=SM[Pos]; return; }
//----
void SZZCalc(int Pos) { 
int i,RBar,LBar,ZZ,NZZ,NZig,NZag; 
i=Pos-1; NZig=0; NZag=0;
while(i<=LBZZ && ZZ==0) { i++; pDn[i]=0; pUp[i]=0; Dn[i]=0; Up[i]=0; 
Lmt[i]=0; RBar=i-SRZZ; if(RBar<Pos) RBar=Pos; LBar=i+SRZZ;
if(i==ArrayMinimum(SM,LBar-RBar+1,RBar)) { ZZ=-1; NZig=i; }
if(i==ArrayMaximum(SM,LBar-RBar+1,RBar)) { ZZ=1; NZag=i; } }
if(ZZ==0) return; NZZ=0;
if(i>Pos) { if(SM[i]>SM[Pos]) { if(ZZ==1) {
if(i>=Pos+SRZZ && NZZ<4) { NZZ++; STF[NZZ]=i; } NZag=i; 
Dn[i-1]=1; } }
else { if(ZZ==-1) { if(i>=Pos+SRZZ && NZZ<4) { NZZ++; STF[NZZ]=i; }
NZig=i; Up[i-1]=1; } } }
while(i<=LBZZ || NZZ<4) { pDn[i]=0; pUp[i]=0; Dn[i]=0; Up[i]=0; 
Lmt[i]=0; RBar=i-SRZZ; if(RBar<Pos) RBar=Pos; LBar=i+SRZZ;
if(i==ArrayMinimum(SM,LBar-RBar+1,RBar)) {
if(ZZ==-1 && SM[i]<SM[NZig]) { 
if(i>=Pos+SRZZ && NZZ<4) STF[NZZ]=i; Up[NZig-1]=0; Up[i-1]=1; 
NZig=i; } if(ZZ==1) { if(i>=Pos+SRZZ && NZZ<4) { NZZ++; STF[NZZ]=i; } 
Up[i-1]=1; ZZ=-1; NZig=i;  } }
if(i==ArrayMaximum(SM,LBar-RBar+1,RBar)) {
if(ZZ==1 && SM[i]>SM[NZag]) { 
if(i>=Pos+SRZZ && NZZ<4) STF[NZZ]=i; Dn[NZag-1]=0; Dn[i-1]=1; 
NZag=i; } if(ZZ==-1) { if(i>=Pos+SRZZ && NZZ<4) { NZZ++; STF[NZZ]=i; } 
Dn[i-1]=1; ZZ=1; NZag=i; } } i++; if(i>LBZZ) return; } 
nSBZZ=Bars-STF[4]; return; }
//---------------------------------------------------------------------
void ArrCalc() { int i,j,k,n,z=0; double p, b;
i=LBZZ; while(LZZ[i]==0) i--; j=i; p=LZZ[i]; i--; while(LZZ[i]==0) i--; 
if(LZZ[i]>p) z=1; if(LZZ[i]>0 && LZZ[i]<p) z=-1; p=LZZ[j]; i=j-1;  
while(i>0) { if(LZZ[i]>p) { z=-1; p=LZZ[i]; }
if(LZZ[i]>0 && LZZ[i]<p) { z=1;  p=LZZ[i]; }
if(z>0 && Dn[i]>0) { Lmt[i]=1; Dn[i]=0; }
if(z<0 && Up[i]>0) { Lmt[i]=1; Up[i]=0; }
if(z>0 && Up[i]>0) { if(i>1) { j=i-1; k=j-SRZZ+1; if(k<0) k=0; 
n=j; while(n>=k && Dn[n]==0) { pUp[n]=Up[i]; pDn[n]=0; n--; } } 
if(i==1) pUp[0]=Up[i]; } 
if(z<0 && Dn[i]>0) { if(i>1) { j=i-1; k=j-SRZZ+1; if(k<0) k=0; 
n=j; while(n>=k && Up[n]==0) { pDn[n]=Dn[i]; pUp[n]=0; n--; } } 
if(i==1) pDn[0]=Dn[i]; } 
i--; } return; }
//---------------------------------------------------------------------
void deinit() { 
return; }
//---------------------------------------------------------------------
int init() { 
   name = WindowExpertName();

IndicatorBuffers(8);
SetIndexBuffer(0,Lmt);
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2); 
SetIndexEmptyValue(0,0.0);
SetIndexBuffer(1,LZZ);
if(DrawZZ) {
SetIndexStyle(1,DRAW_SECTION,EMPTY,2);
SetIndexEmptyValue(1,0.0); }
else SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(2,SA); SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(3,SM); SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(4,Up); SetIndexStyle(4,DRAW_HISTOGRAM,EMPTY,1);
SetIndexArrow(4,233); SetIndexEmptyValue(4,0.0);
SetIndexBuffer(5,Dn); SetIndexStyle(5,DRAW_HISTOGRAM,EMPTY,1);
SetIndexArrow(5,234); SetIndexEmptyValue(5,0.0);
SetIndexBuffer(6,pUp); SetIndexStyle(6,DRAW_HISTOGRAM);
SetIndexArrow(6,217); SetIndexEmptyValue(6,0.0);
SetIndexBuffer(7,pDn); SetIndexStyle(7,DRAW_HISTOGRAM);
SetIndexArrow(7,218); SetIndexEmptyValue(7,0.0); return(0); }
//---------------------------------------------------------------------
bool alertflag = 0;
int start() 
{ 
int counted_bars;
int limit,i,j,n;

IndicatorShortName("ArrZZx2 period: "+DoubleToStr(period, 0));

if(period == Period() || period == 0)
{
   alertflag = 0;
   
   counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1); 
   if(counted_bars>0) counted_bars--;
   if(First==true) 
   { 
      if(SR<2) SR=2; 
      if(Bars<=2*(MainRZZ+FP+SR+2)) return(-1); 
      if(SRZZ<=SR) SRZZ=SR+1; 
      MaxBar=Bars-(MainRZZ+FP+SR+2);
      LBZZ=MaxBar; 
      SBZZ=LBZZ; 
      prevBars=Bars; 
      First=false; 
   }
   limit=Bars-counted_bars; 
   for(i=limit;i>=0;i--) 
   { 
      MainCalculation(i); 
   }
   if(prevBars!=Bars) 
   { 
      SBZZ=Bars-nSBZZ; 
      LBZZ=Bars-nLBZZ; 
      prevBars=Bars; 
   }
    
   SZZCalc(0); 
   LZZCalc(0); 
   ArrCalc(); 
   
   return(0); 
}
else if(period < Period() && period != 0)
{
   if(alertflag == 0) {Alert("Parameter \"period\" is less than period of current graph. Please enter different period"); alertflag = 1;}
   return(0);
}
else     //òóò íà÷èíàåòñÿ ÌÎÇà !
{
   alertflag = 0;
   
   double pos; int Pos;
   
   double tab = period /Period(); //ñêîëüêî áàðîâ ìëàäøåãî ÒÔ ñîäåðæàòñÿ â îäíîì áàðå ñòàðøåãî ÒÔ.
   
   int popr_coeff = 0;
   int error = 0;
   datetime period_time_0;
   static datetime recount = 0;
   static bool recount_flag = 0;

   period_time_0 = iTime(NULL, period, 0);
   error=GetLastError();
   if(recount==0 && error==4066)
   {
      Alert("Error 4066: Data for period = ", period, " not loaded. Loading data... Indicator will be totally recounted in 1 minute.");
      recount = TimeCurrent() + 60;
   }
   else if(recount>0 && TimeCurrent()>recount)
   {
      Alert("Processing total recalculation of indicator.");
      recount = 0;
      recount_flag = 1;
   }
   else if(recount_flag == 2)
   {
      recount_flag = 0;
      Alert("Data for period = ", period, " loaded. Indicator recalculated totally.");
   }
      
   
   
   datetime diff  = Time[0] - iTime(NULL, period, 0);  //ðàñ÷èòûâàåì ñìåùåíèå 0-áàðà òåê. òô îòí. 0-áàðà òô period
   double   delta = MathRound((diff/60)/Period()) + 1; //ñêîëüêî áàðîâ òåê. òô óæå åñòü (âêëþ÷àÿ òåê. áàð) â 0-áàðå òô period
       
      
   counted_bars=IndicatorCounted();
   
   if(recount_flag == 1)
   {
      counted_bars = 1;
      recount_flag = 2;
   }
   
//---- check for possible errors
   if(counted_bars<0) return(-1); 
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   pos=0;
   while(pos<=Bars-counted_bars-1)
   {
 	   int m = MathFloor((pos + popr_coeff - delta)/tab) + 1;
 	   Pos = MathRound(pos); //ôîðìàëüíîñòü
 	   
 	   	   
 	   if(Time[Pos] <  iTime(NULL, period, m)) {popr_coeff++; continue;}      //íà ñëó÷. ñóáá. è âîñêð. (òàì ïðîïàäàåò îäèí áàð H1) [êîíòðîëü ñëåâà]
 	   if(m>=1 && Time[Pos] >= iTime(NULL, period, m-1)) {popr_coeff--; continue;}      //íà ñëó÷. ñóáá. è âîñêð. (òàì ïðîïàäàåò îäèí áàð H1) [êîíòðîëü ñïðàâà]
 	    
 	   Lmt[Pos] = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 0, m);
 	   LZZ[Pos] = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 1, m);
      SA[Pos]  = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 2, m);
      SM[Pos]  = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 3, m);
      Up[Pos]  = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 4, m);
      Dn[Pos]  = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 5, m);
      pUp[Pos] = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 6, m);
      pDn[Pos] = iCustom(NULL, period, name, period, SR, SRZZ, MainRZZ, FP, SMF, DrawZZ, PriceConst, 7, m);
 	   
 
      pos++;
   }
}   
   
}


//---------------------------------------------------------------------

Comments