Author: Copyright � 2009, TradeProgrammer
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
ZZ_i
//+------------------------------------------------------------------+
//|                                                         ZZ_i.mq4 |
//|                                Copyright © 2008, TradeProgrammer |
//|                        http://tradeprogrammer.narod.ru/index.htm |
//|                                 mailto:TradeProgrammer@yandex.ru |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2009, TradeProgrammer"
#property link      "www.http://tradeprogrammer.narod.ru/index.htm"
#property link      "mailto:TradeProgrammer@yandex.ru"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Red




#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- input parameters
extern int       ZZPeriod=50;
extern int       ZZReverse=0;
//---- buffers
double ZZ[];
double PEACK[];
double TROUGH[];
double LastHighTime[];
double LastLowTime[];
double LastHighValue[];
double LastLowValue[];
double LastDir[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(8);

   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ZZ);
   SetIndexEmptyValue(0,0.0);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,PEACK);
   SetIndexEmptyValue(1,0.0);
   
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,159);
   SetIndexBuffer(2,TROUGH);
   SetIndexEmptyValue(2,0.0);   
   
   SetIndexBuffer(3,LastHighTime);
   SetIndexEmptyValue(7,0.0);
         
   SetIndexBuffer(4,LastLowTime);
   SetIndexEmptyValue(7,0.0);
         
   SetIndexBuffer(5,LastHighValue);
   SetIndexEmptyValue(7,0.0);
      
   SetIndexBuffer(6,LastLowValue);
   SetIndexEmptyValue(7,0.0);
   
   SetIndexBuffer(7,LastDir);
   SetIndexEmptyValue(7,0.0);
   
   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
   SetIndexLabel(2,"");
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){


         int limit=Bars-IndicatorCounted();

         LastHighValue[Bars-1]=High[Bars-1];
         LastLowValue[Bars-1]=Low[Bars-1];
         LastHighTime[Bars-1]=Time[Bars-1];
         LastLowTime[Bars-1]=Time[Bars-1];

            for(int i=limit-1;i>=0;i--){
               ZZ[i]=0;
               PEACK[i]=0;
               TROUGH[i]=0;
               LastDir[i]=LastDir[i+1];
               LastHighValue[i]=LastHighValue[i+1];
               LastLowValue[i]=LastLowValue[i+1];
               LastHighTime[i]=LastHighTime[i+1];
               LastLowTime[i]=LastLowTime[i+1];
               
               int hb=iHighest(NULL,0,MODE_HIGH,ZZPeriod,i);
               int lb=iLowest(NULL,0,MODE_LOW,ZZPeriod,i);
               
                  if(hb==i){
                     if(lb!=i){
                        switch(LastDir[i]){
                           case 0:
                              if(High[i]>LastHighValue[i]){
                                 LastHighValue[i]=High[i];
                                 LastHighTime[i]=Time[i];
                                 LastDir[i]=1;  
                                 ZZ[i]=High[i];                            
                                 PEACK[i]=High[i];
                              }   
                           break;                            
                           case 1:
                              if(High[i]>LastHighValue[i]){
                                 int lhb=iBarShift(NULL,0,LastHighTime[i],false);
                                 ZZ[lhb]=0;
                                 PEACK[lhb]=0;
                                 LastHighValue[i]=High[i];
                                 LastHighTime[i]=Time[i];
                                 LastDir[i]=1;  
                                 ZZ[i]=High[i];                            
                                 PEACK[i]=High[i];
                              }                           
                           break;
                           case -1:
                              if(High[i]>=LastLowValue[i]+Point*ZZReverse){
                                 LastHighValue[i]=High[i];
                                 LastHighTime[i]=Time[i];
                                 LastDir[i]=1;  
                                 ZZ[i]=High[i]; 
                                 PEACK[i]=High[i];                            
                              }
                        }
                     }
                  }
                  
                  if(lb==i){
                     if(hb!=i){
                        switch(LastDir[i]){
                           case 0:
                              if(Low[i]<LastLowValue[i]){
                                 LastLowValue[i]=Low[i];
                                 LastLowTime[i]=Time[i];
                                 LastDir[i]=-1;     
                                 ZZ[i]=Low[i];
                                 TROUGH[i]=Low[i];
                              }                           
                           break;
                           case -1:
                              if(Low[i]<LastLowValue[i]){
                                 int llb=iBarShift(NULL,0,LastLowTime[i],false);
                                 ZZ[llb]=0;
                                 TROUGH[llb]=0;
                                 LastLowValue[i]=Low[i];
                                 LastLowTime[i]=Time[i];
                                 LastDir[i]=-1;     
                                 ZZ[i]=Low[i];
                                 TROUGH[i]=Low[i];
                              }
                           break;
                           case 1:
                              if(LastHighValue[i]>=Low[i]+Point*ZZReverse){
                                 LastLowValue[i]=Low[i];
                                 LastLowTime[i]=Time[i];
                                 LastDir[i]=-1;  
                                 ZZ[i]=Low[i];
                                 TROUGH[i]=Low[i];
                              }
                        }
                     }
                  }               
            }


   return(0);
}

Comments