_iGDR_ZZ





// Indicators Pack - Green Digger Reseach
//+------------------------------------------------------------------+
//|                                            [IP-GDR] ZigZag color |
//|                          Copyright © 2008-2009, GreenDog, Russia |
//|                                                    krot@inbox.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008-2009, GreenDog"
#property link      "krot@inbox.ru"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Gold
#property indicator_color2 DarkGreen
#property indicator_color3 Red
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2

extern double extHL = 4.8; // êîýô äëÿ ñðåäíåãî HL, îïðåäåëÿþùåãî ïóòü â ïóíêòàõ, ïðè êîòîðîì âåðøèíà ñ÷èòàåòñÿ óñòàíîâëåííîé
extern int extFlat = 48;   // êîëè÷åñòâî áàðîâ ôëåòà, êîãäà âåðøèíà ðèñóåòñÿ ïðèíóäèòåëüíî
extern int sBars = 480;    // show bars

double aUP[],aDW[],aMA[];

double lastHL,aLv[3];
bool Go = true, first = true;
int trend,lastLow,lastHigh;

int init(){
   IndicatorBuffers(3);
   SetIndexBuffer(0,aMA);
   SetIndexBuffer(1,aUP);
   SetIndexBuffer(2,aDW);
   SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,250);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexEmptyValue(2,EMPTY_VALUE);
   IndicatorDigits(Digits+1);

   if (sBars!=0 && sBars<2) { Go=false; return(-1); }
   if (sBars==0) sBars=10000;
   return(0);
}

int deinit(){
   Comment("");
}

int start(){
   int lastBars,count;
   
   if (!Go) { Comment("Íåêîððåêòíûå ïàðàìåòðû èíäèêàòîðà!"); return(-1); }
   if (Bars<sBars+extFlat) { Comment("Íåäîñòàòî÷íî áàðîâ íà ãðàôèêå!"); return(0); }  
   else Comment("");
//   if (Bars==lastBars) return(0); // åñëè ìåäëåííûé, ñ÷èòàåì òîêà â íà÷àëå áàðà
   if (Bars-lastBars<=1){
      if (Bars-lastBars==1){ lastHigh++; lastLow++; calcHL(); }
      count=Bars-lastBars;
   }
   else { 
      ArrayInitialize(aMA,EMPTY_VALUE); ArrayInitialize(aUP,EMPTY_VALUE); ArrayInitialize(aDW,EMPTY_VALUE); first=true;
   }
   lastBars=Bars;
   
   if (first){ // ïðè ïåðâîì çàïóñêå îïðåäåëÿåì ñðåäíåå õë
      calcHL();
      // îïðåäåëÿåì ïåðâóþ òî÷êó
      double min=iLowest(NULL,0,MODE_LOW,extFlat,sBars);
      double max=iHighest(NULL,0,MODE_HIGH,extFlat,sBars);
      if (max<min){ // åñëè ïîñëåäíÿÿ âåðøèíà high
         lastLow=min; pushHigh(max); count=max;
      }
      else { // åñëè ïîñëåäíÿÿ âåðøèíà low
         lastHigh=max; pushLow(min); count=min;
      }
      first=false;
   }

   // îñíîâíîé öèêë
   for(int i=count;i>=0;i--){
      if (trend==OP_BUY){ // ëó÷ ââåðõ
         if (High[i]>aLv[1]) pushHigh(i); // åñëè îáíîâëåíèå õàé
         else if (Low[i]<aLv[2] || Low[i]<aLv[0]) pushLow(i); // çàäåëè óðîâíè îòñòàþùåãî èëè ïðåäûäóùåãî ëîó
         else if (lastHigh-i>extFlat) pushLow(iLowest(NULL,0,MODE_LOW,extFlat,i)); // íå ïîðà ëè ñìåíèòü òðåíä
      }
      else { // ëó÷ âíèç
         if (Low[i]<aLv[1]) pushLow(i); // åñëè îáíîâëåíèå low
         else if (High[i]>aLv[2] || High[i]>aLv[0]) pushHigh(i); // çàäåëè óðîâíè îòñòàþùåãî èëè ïðåäûäóùåãî õàé
         else if (lastLow-i>extFlat) pushHigh(iHighest(NULL,0,MODE_HIGH,extFlat,i)); // íå ïîðà ëè ñìåíèòü òðåíä
      }
   }
   
   return(0);
}

void calcHL(){
   double HL=0; 
   for(int i=Bars;i>=0;i--) { HL=HL+High[i]-Low[i]; if (i==sBars) lastHL=HL; }
   lastHL=NormalizeDouble(extHL*(MathSqrt(HL/Bars*(HL-lastHL)/sBars)),Digits);
//      lastHL=NormalizeDouble(extHL*(HL/Bars+(HL-lastHL)/sBars)/2,Digits);
//      lastHL=NormalizeDouble(extHL*HL/Bars,Digits);
   return(0);
}

void pushHigh(int sh){
   lastHigh=sh; trend=OP_BUY; aMA[sh]=High[sh];
   aLv[0]=Low[lastLow]; aLv[1]=High[lastHigh]; aLv[2]=aLv[1]-lastHL;
   int count=lastLow-lastHigh; // ïðîðèñîâêà è çàïîëíåíèå áóôåðîâ
   for(int i=0;i<=count;i++) aUP[lastLow-i]=Low[lastLow]+i*(High[sh]-Low[lastLow])/count;
   return(0);
}

void pushLow(int sh){
   lastLow=sh; trend=OP_SELL; aMA[sh]=Low[sh];
   aLv[0]=High[lastHigh]; aLv[1]=Low[lastLow]; aLv[2]=aLv[1]+lastHL;
   int count=lastHigh-lastLow; // ïðîðèñîâêà è çàïîëíåíèå áóôåðîâ
   for(int i=0;i<=count;i++) aDW[lastHigh-i]=High[lastHigh]-i*(High[lastHigh]-Low[sh])/count;
   return(0);
}






Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Implements a curve of type DRAW_ARROW
Implements a curve of type DRAW_LINE

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: