How to extract only the bottoms turnaround points extracted by the zigzag indicator? - page 2

 
jackprobe:

Hi deVries,

Thank you. Yes, it's like the picture you sent. But i want to know how to code it. It must calculate each previous Zigzag leg, and then draw the Fibonacci level, so we know how far is the current / last zigzag goes.

edit: i sent the code on the previous post. It would not draw the fibo line ...

Thanks



Can you show me how you get with this indicator the values 0.0 and 100.0 ??
 
deVries:

Can you show me how you get with this indicator the values 0.0 and 100.0 ??

I made it manually using MT4 fibo retracement tools ..... :) I want actually like that picture, but still don't know how to code.

About iCustom, should i call it like this below (calling your TopBottomZigzag.ex4 file) ?

double top[i] = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,2,i);
double bottom[i] = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,1,i);

Thanks

 
jackprobe:

I made it manually using MT4 fibo retracement tools ..... :) I want actually like that picture, but still don't know how to code.

About iCustom, should i call it like this below (calling your TopBottomZigzag.ex4 file) ?

Thanks


no that are the wrong buffers and you have to find value of i at what bar the top or bottom will be

if i compare it to the version i posted in CodeBase see Zigzag with line at lows and line at highs

//+------------------------------------------------------------------+
//|                                              ZigZag practise.mq4 |
//|                                Copyright © 2012, Tjipke de Vries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Tjipke de Vries"
#property link      ""

//---- input parameters  ZigZag
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;

double P0,P1,P2,P3,P4,P5;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

   call_zigzag();


   subPrintDetails();
//----
   return(0); 

  }
//+------------------------------------------------------------------+

//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
   string sComment   = "";
   string sp         = "----------------------------------------\n";
   string NL         = "\n";


       
   sComment = "ZigZag practise           Copyright © 2012, Tjipke" + NL;
   sComment = sComment + NL;
   sComment = sComment + "P0 " + DoubleToStr(P0,Digits) + NL;
   sComment = sComment + "P1 " + DoubleToStr(P1,Digits) + NL;
   sComment = sComment + "P2 " + DoubleToStr(P2,Digits) + NL;
   sComment = sComment + "P3 " + DoubleToStr(P3,Digits) + NL;
   sComment = sComment + "P4 " + DoubleToStr(P4,Digits) + NL;
   sComment = sComment + "P5 " + DoubleToStr(P5,Digits) + NL;            
   sComment = sComment + "Buffervalue 0  ZigZag " + NL;


   Comment(sComment);
}
//+------------------------------------------------------------------+

void call_zigzag ()
{
//This function calls the custom indicator zigzag and returns it´s values. THE INDICATOR ZIGZAG MUST BE IN THE FOLDER C:\...\MetaTrader 4\experts\indicators AND MUST BE NAMED "zigzag"!!!!
   int n, i = 0;
      while(n<6)
      {
      if(P0>0) {P5=P4; P4=P3; P3=P2; P2=P1; P1=P0; }
      P0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if(P0>0) {n+=1; }
      i++;
      }
}

this is how i did it with normal zigzag before i created the indicator of this topic

see if you find the logic

.

(edit the post for giving the link correct version you find in CodeBase)

 
deVries:


no that are the wrong buffers and you have to find value of i at what bar the top or bottom will be

if i compare it to the version i posted in CodeBase see Zigzag with line at lows and line at highs

this is how i did it with normal zigzag before i created the indicator of this topic

see if you find the logic

.

(edit the post for giving the link correct version you find in CodeBase)


Hi deVries,

Thanks for the link. I just tried using iCustom to call your indicator that i named it "TopBottomZigzag.ex4" . The result is great. This time the Fibo line is created by the code ... :)

Just i still can not make the Fibo of previous ZZ leg .... :( It just always draw the last ZZ leg only. And also still can't define the length of the Fibo level line ...

Thanks for your nice code ....

- jackprobe

//+------------------------------------------------------------------+
//|                                                       zzFibo.mq4 |
//|                        based on "TopBottomZigzag.mq4" by deVries |
//|                                            edited by : Jackprobe |
//+------------------------------------------------------------------+

#property copyright "deVries & Jackprobe"
#property link      "https://forum.mql4.com/54660"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 2
#property indicator_color2 DeepPink
#property indicator_width2 2

//---- indicator parameters
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
 
//---- indicator buffers
double UpBuffer[];
double DnBuffer[];
int    jmlTitik=0;
double prevPrc=0;
int    topCandle=0, bottomCandle=0;
string myObjName = "myZZFibo";
double objWidth = 1.0;
double objStyle = 2.0;
color  objLevelColor = Aqua;
color  objColor = Gold;

//+------------------------------------------------------------------+
//| INIT() Function                                                  |
//+------------------------------------------------------------------+
int init()  {
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,indicator_color1); 
   SetIndexBuffer(0,UpBuffer);
   SetIndexArrow(0,221);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1,indicator_color2); 
   SetIndexBuffer(1,DnBuffer);
   SetIndexArrow(1,222);
   string short_name;
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   short_name="TopBottomZZFibo";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Up");
   SetIndexLabel(1,"Dn");
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);   
   return(0);
}

//+------------------------------------------------------------------+
//| DEINIT() Function                                                |
//+------------------------------------------------------------------+
int deinit() {
   ObjectDelete(myObjName);
}

//+------------------------------------------------------------------+
//| START() Function                                                 |
//+------------------------------------------------------------------+
int start() {
   int  shift, counted_bars=IndicatorCounted(),limit;
   double topPrc=0, bottomPrc=0;      
   if ( counted_bars > 0 )  limit=Bars-counted_bars;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Bars-1; 
   if ( counted_bars < 1 ) 
   
   for(shift=limit;shift>=0;shift--)  { 
      topPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,2,shift);
      bottomPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,1,shift);
      
      if ((topPrc>0)&&(topPrc!=EMPTY_VALUE)) {
         DnBuffer[shift]= topPrc + 0.0003;
         jmlTitik++;
         ObjectDelete(myObjName);
           ObjectCreate(myObjName, OBJ_FIBO, 0, Time[bottomCandle], prevPrc, Time[shift], topPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = topPrc;
         topCandle = shift;
      }
      else if ((bottomPrc>0)&&(bottomPrc!=EMPTY_VALUE)) {
         UpBuffer[shift]= bottomPrc - 0.0003;         
         jmlTitik++;
         ObjectDelete(myObjName);
         ObjectCreate(myObjName, OBJ_FIBO, 0, Time[topCandle], prevPrc, Time[shift], bottomPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = bottomPrc;
         bottomCandle = shift;
      }
   }       
   //----
        return(0);      
}
 

tomorrow i go on

this part

   for(shift=limit;shift>=0;shift--)  { 
      topPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,2,shift);
      bottomPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,1,shift);

has to be changed

 

if you look to your picture you see fibonnacci is only draw at levels of last 2 Zigzag points

your problem is "can not make the Fibo of previous ZZ leg .... :( It just always draw the last ZZ leg only. And also still can't define the length of the Fibo level line ..."

So you have to check what your code is doing and how does it come to the result you have now

.

we want to know what your coding is doing in this part

  for(shift=limit;shift>=0;shift--)  { 
      topPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,2,shift);
      bottomPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,1,shift);
      
      if ((topPrc>0)&&(topPrc!=EMPTY_VALUE)) {
         DnBuffer[shift]= topPrc + 0.0003;
         jmlTitik++;
         ObjectDelete(myObjName);
           ObjectCreate(myObjName, OBJ_FIBO, 0, Time[bottomCandle], prevPrc, Time[shift], topPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = topPrc;
         topCandle = shift;
      }
      else if ((bottomPrc>0)&&(bottomPrc!=EMPTY_VALUE)) {
         UpBuffer[shift]= bottomPrc - 0.0003;         
         jmlTitik++;
         ObjectDelete(myObjName);
         ObjectCreate(myObjName, OBJ_FIBO, 0, Time[topCandle], prevPrc, Time[shift], bottomPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = bottomPrc;
         bottomCandle = shift;
      }
   }       

beginning with some printstatements we have to find out what's going on

for(shift=limit;shift>=0;shift--)  
      { 
      topPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,2,shift);
      bottomPrc = iCustom(Symbol(),0,"TopBottomZigzag",ExtDepth,ExtDeviation,ExtBackstep,1,shift);
//..
      Print("topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc);
//.....
      }

what do you see happening ???

 

Hi deVries,

I use Alert instead of Print. If the candle inside the leg (not at the end or beginning of the leg), we can not catch the price. But at the end of the leg, we can see the price (please see the red and green arrow on the chart). So, I think iCustom can be used, but there is wrong coding, and i still do not know where it is ...

edit: may be i must use Array / Buffer to hold all information end zigzag point (price of end Zz point & candle number of end Zz point & number of end zz point accurance). May be i must use 3x1 array of type = double, or just use 1x1 array of type string (but first must do "concatenate" all end zigzag point information) ????


for(shift=limit;shift>=0;shift--)  {    
      topPrc = iCustom(Symbol(),0,"topBottomZZ-2",ExtDepth,ExtDeviation,ExtBackstep,2,shift);
      bottomPrc = iCustom(Symbol(),0,"topBottomZZ-2",ExtDepth,ExtDeviation,ExtBackstep,1,shift);
      
      Alert("topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc, " candle=", shift);
      
      if ((topPrc>0)&&(topPrc!=EMPTY_VALUE)) {
         Alert("Inside first If: topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc, " candle=", shift);
         DnBuffer[shift]= topPrc + 0.0003;
         jmlTitik++;
         ObjectDelete(myObjName);
         ObjectCreate(myObjName, OBJ_FIBO, 0, Time[bottomCandle], prevPrc, Time[shift], topPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = topPrc;
         topCandle = shift;
      }
      else if ((bottomPrc>0)&&(bottomPrc!=EMPTY_VALUE)) {
         Alert("Inside second If: topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc, " candle=", shift);
         UpBuffer[shift]= bottomPrc - 0.0003;         
         jmlTitik++;
         ObjectDelete(myObjName);
         ObjectCreate(myObjName, OBJ_FIBO, 0, Time[topCandle], prevPrc, Time[shift], bottomPrc);
         ObjectSet(myObjName, OBJPROP_LEVELWIDTH, objWidth);
         ObjectSet(myObjName, OBJPROP_LEVELSTYLE, objStyle); 
         ObjectSet(myObjName, OBJPROP_LEVELCOLOR, objLevelColor); 
         ObjectSet(myObjName, OBJPROP_COLOR, objColor);
         //-- ganz unten
         prevPrc = bottomPrc;
         bottomCandle = shift;
      }
   }       
 

Hi deVries,

Yes, you're right. If i try to catch the value, and put it into Array, the result is always 0 (zero) ....
I still do not understand, why it can display the arrow (represent the end of ZZ), but as i try to put it into array, the result is zero ...??

Thanks


     if ((topPrc>0)&&(topPrc!=EMPTY_VALUE)) {
         /// Alert("Inside first If: topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc, " candle=", shift);
         DnBuffer[shift]= topPrc + 0.0003;        
         resPrice[jmlTitik] = topPrc;
         resCandle[jmlTitik] = shift;
         resPos[jmlTitik] = 1;
         Alert("1 LastPrice =", resPrice[jmlTitik]);
         Alert("1 LastCandle =", resCandle[jmlTitik]);
         Alert("1 LastPos =", resPos[jmlTitik]);
         //-- ganz unten
         jmlTitik++;
         prevPrc = topPrc;
         topCandle = shift;
      }
 

use the indicator of codebase then the code has to be

//   if ( counted_bars < 1 ) 
   
   for(shift=limit;shift>=0;shift--)  { 
      topPrc = iCustom(Symbol(),0,"Zigzag_with_line_at_lows_and_line_at_highs",ExtDepth,ExtDeviation,ExtBackstep,3,shift);
      bottomPrc = iCustom(Symbol(),0,"Zigzag_with_line_at_lows_and_line_at_highs",ExtDepth,ExtDeviation,ExtBackstep,4,shift);
      
      
       Print("topPrc  =  ",topPrc,"  bottomPrc  =  ",bottomPrc);
      
     }/* 

testing this on chart you will see printed (with allert useless)

2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  1.0298  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  1.0286
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  1.0297  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
2013.10.20 20:48:00     zzFibo USDCAD,M5: topPrc  =  0  bottomPrc  =  0
//....  this is not all

every tick you calculate it again remove several times the objects and place new objects again until you come to the last calculation != 0

what is the code doing i gave

//+------------------------------------------------------------------+
//|                                              ZigZag practise.mq4 |
//|                                Copyright © 2012, Tjipke de Vries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Tjipke de Vries"
#property link      ""

//---- input parameters  ZigZag
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;

double P0,P1,P2,P3,P4,P5;


//....  you find it in a post above
 
Thank you deVries. will try it ...
Reason: