Problem with ZigZag indicator - page 2

 
I forgot to highlight the indicator values, the minimum one matches but maximum does not match as I tried to show in 2nd graph...
 
aed71:

The below graph shows the minimum value (both cursor point value, data window value and output is the same)

The below one is 6 ticks later the highest high part of the graph. Both data window and cursor points are same however the output is not same and besides it returns both low and high value.

2nd

I checked that iCustom() loads indicator correctly. The low value is the same but high value is not. Could it be related with ZigZag indicator?

What I'm doing wrong I really could not understand.


I see only one value coming from your ZigZag indicator

this value what is it ??

 
aed71:

The below graph shows the minimum value (both cursor point value, data window value and output is the same)

The below one is 6 ticks later the highest high part of the graph. Both data window and cursor points are same however the output is not same and besides it returns both low and high value.

2nd

I checked that iCustom() loads indicator correctly. The low value is the same but high value is not. Could it be related with ZigZag indicator?

What I'm doing wrong I really could not understand.

You are using the ZigZag incorrectly in your iCustom example. The Standard ZigZag by MetQuotes has THREE (not two) Buffers (Modes or Line Index in iCustom)

  1. Mode = 0: Hold both the High and Low ZigZag Points.
  2. Mode = 1: High Points but not necessarily only ZigZag points (as it also holds repaint points).
  3. Mode = 2: Low Points but not necessarily only ZigZag points (as it also holds repaint points).

You will need to compare the first buffer (Mode 0) with the other 2 buffers in order do decide if it is a High Point or a Low Point (e.g. if both Buffer 1 and Buffer 3 have the same value then it is a Low ZigZag point, and if both Buffer 1 and Buffer 2 are the same then it is a High point).

Also, in order to better understand how a ZigZag works and how it repaints, I suggest playing around with my ZigZagZug indicator. However, in your code use the the MetaQuotes ZigZag, as it is faster. My version does more processing because of the extra features and is thus slower.

PS! If Buffer 1 (Mode = 0) has a value of 0.0, but the other buffers have non-zero values, then they are older repaint points and NOT ZigZag Points.

In your code your are using the Mode 0 Buffer as the Low and Mode 1 Buffer as High. That is totally incorrect.

 
FMIC:

You are using the ZigZag incorrectly in your iCustom example. The Standard ZigZag by MetQuotes has THREE (not two) Buffers (Modes or Line Index in iCustom)

  1. Mode = 0: Hold both the High and Low ZigZag Points.
  2. Mode = 1: High Points but not necessarily only ZigZag points (as it also holds repaint points).
  3. Mode = 2: Low Points but not necessarily only ZigZag points (as it also holds repaint points).

You will need to compare the first buffer (Mode 0) with the other 2 buffers in order do decide if it is a High Point or a Low Point (e.g. if both Buffer 1 and Buffer 3 have the same value then it is a Low ZigZag point, and if both Buffer 1 and Buffer 2 are the same then it is a High point).

Also, in order to better understand how a ZigZag works and how it repaints, I suggest playing around with my ZigZagZug indicator. However, in your code use the the MetaQuotes ZigZag, as it is faster. My version does more processing because of the extra features and is thus slower.

PS! If Buffer 1 (Mode = 0) has a value of 0.0, but the other buffers have non-zero values, then they are older repaint points and NOT ZigZag Points.

In your code your are using the Mode 0 Buffer as the Low and Mode 1 Buffer as High. That is totally incorrect.


Look here https://www.mql5.com/en/forum/149492/page2#912747 outsidebars is a problem for the old coded Zigzag

The yellow line is giving a better way how zigzag has to display

 
deVries:


Look here https://www.mql5.com/en/forum/149492/page2#912747 outsidebars is a problem for the old coded Zigzag

The yellow line is giving a better way how zigzag has to display


Outside bars has nothing to do with "aed71's" current dilemma. His use of the ZigZag is just incorrect.

Please don't deviate from the current problem as you will just confuse the situation.

Besides, I also gave a link to my ZigZagZug code that does not have that problem.

 
FMIC:

You are using the ZigZag incorrectly in your iCustom example. The Standard ZigZag by MetQuotes has THREE (not two) Buffers (Modes or Line Index in iCustom)

  1. Mode = 0: Hold both the High and Low ZigZag Points.
  2. Mode = 1: High Points but not necessarily only ZigZag points (as it also holds repaint points).
  3. Mode = 2: Low Points but not necessarily only ZigZag points (as it also holds repaint points).

You will need to compare the first buffer (Mode 0) with the other 2 buffers in order do decide if it is a High Point or a Low Point (e.g. if both Buffer 1 and Buffer 3 have the same value then it is a Low ZigZag point, and if both Buffer 1 and Buffer 2 are the same then it is a High point).

Also, in order to better understand how a ZigZag works and how it repaints, I suggest playing around with my ZigZagZug indicator. However, in your code use the the MetaQuotes ZigZag, as it is faster. My version does more processing because of the extra features and is thus slower.

PS! If Buffer 1 (Mode = 0) has a value of 0, but the other buffers have values, then they are older repaint points.


Great, thanks for the important hints! Now I understood why it doesn't work...

I think the original code of Metaquotes ZigZag is not correct since it has 2 buffers only. So I was thinking that one of them should be high and the other low...

In fact the title also mismatchs, I saw recently. Somebody should check it!

I'm referring to the code here https://www.mql5.com/en/code/7796

//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
//---- indicator buffers
double ExtMapBuffer[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_SECTION);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(0,0.0);
//---- indicator short name
   IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    shift, back,lasthighpos,lastlowpos;
   double val,res;
   double curlow,curhigh,lasthigh,lastlow;

   for(shift=Bars-ExtDepth; shift>=0; shift--)
     {
      val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
      if(val==lastlow) val=0.0;
      else 
        { 
         lastlow=val; 
         if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer[shift+back];
               if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0; 
              }
           }
        } 
      ExtMapBuffer[shift]=val;
      //--- high
      val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
      if(val==lasthigh) val=0.0;
      else 
        {
         lasthigh=val;
         if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer2[shift+back];
               if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0; 
              } 
           }
        }
      ExtMapBuffer2[shift]=val;
     }

   // final cutting 
   lasthigh=-1; lasthighpos=-1;
   lastlow=-1;  lastlowpos=-1;

   for(shift=Bars-ExtDepth; shift>=0; shift--)
     {
      curlow=ExtMapBuffer[shift];
      curhigh=ExtMapBuffer2[shift];
      if((curlow==0)&&(curhigh==0)) continue;
      //---
      if(curhigh!=0)
        {
         if(lasthigh>0) 
           {
            if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
            else ExtMapBuffer2[shift]=0;
           }
         //---
         if(lasthigh<curhigh || lasthigh<0)
           {
            lasthigh=curhigh;
            lasthighpos=shift;
           }
         lastlow=-1;
        }
      //----
      if(curlow!=0)
        {
         if(lastlow>0)
           {
            if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
            else ExtMapBuffer[shift]=0;
           }
         //---
         if((curlow<lastlow)||(lastlow<0))
           {
            lastlow=curlow;
            lastlowpos=shift;
           } 
         lasthigh=-1;
        }
     }
  
   for(shift=Bars-1; shift>=0; shift--)
     {
      if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0;
      else
        {
         res=ExtMapBuffer2[shift];
         if(res!=0.0) ExtMapBuffer[shift]=res;
        }
     }
  }
 
aed71:


Great, thanks for the important hints! Now I understood why it doesn't work...

I think the original code of Metaquotes ZigZag is not correct since it has 2 buffers only. So I was thinking that one of them should be high and the other low...

In fact the title also mismatchs, I saw recently. Somebody should check it!

I'm referring to the code here https://www.mql5.com/en/code/7796


Don't use that Code! That is Ancient!

Use the code that is currently being pushed through the LiveUpdates. Use the current 600+ version or at least the 509 version.

PS! NB! Also, use just "ZigZag" in the Name and not "ZigZag.ex4" in the iCustom.

 
FMIC:


Don't use that Code! That is Ancient!

Use the code that is currently being pushed through the LiveUpdates. Use the current 600+ version or at least the 509 version.

PS! NB! Also, use just "ZigZag" in the Name and not "ZigZag.ex4" in the iCustom.


Hi FMIC,

Thanks for the tips. I was adding ex4 at the end of the file not to forget to compile it. Unfortunately my new build 610 ZigZag replaced by the old one.

I decided to use yours, since time is not an issue for me. I face some problems here as well, I would appreciate if you can guide me.

I used the same code stated above just changed the filename with your version. I'm using parameters 6,5,3; that's the only difference from your default settings.

What I faced some issues:

Firstly the indicator loads each time in every tick to read zh,zl values. And at the end it releases all loads at the end (which you cannot see in the picture) stating something like "2014.02.22 09:35:09.171 2013.11.01 22:55 Custom indicator ZigZagZug EURUSD,M15: removed". Please refer to the log file I've attached. Does it cause any memory issues later?

Secondly in the journal the counter cnt jumped from cnt8 to cnt84 which is strange. In the logs it does not jump. I think I should consider the logs as correct values.

The third and most critical one is that it found two lows consequently which it should not. In the figure I want to get the high and low values of the gray zigzag lines but when I write down all the high and lows in the log they are exactly the same with your pink and cyan color dots. However I need the zig zag values only. I've checked the other buffers but did not bring the correct values. Any suggestions? Or should I go with the classical zigzag (for build 610?)

Thanks.

ZigZagZug

 
aed71:


Hi FMIC,

Thanks for the tips. I was adding ex4 at the end of the file not to forget to compile it. Unfortunately my new build 610 ZigZag replaced by the old one.

I decided to use yours, since time is not an issue for me. I face some problems here as well, I would appreciate if you can guide me.

I used the same code stated above just changed the filename with your version. I'm using parameters 6,5,3; that's the only difference from your default settings.

Any suggestions? Or should I go with the classical zigzag (for build 610?)

Thanks.

There is nothing wrong with using the new 610 ZigZag. In fact I encourage you to use that instead so that it will be forward compatible with future builds. Don't use the old one or even my one.

My ZigZagZug indicator uses extra parameters and in a different order and type, so you cannot just use a similar iCustom that you are using now. It is completely different.

Also I use 7 buffers in the indicator for the extra features. It is supposed to be used as I visual learning tool for understanding the ZigZag and not really for use in an EA.

PS! It is normal to have an Indicator Load and Unload several times during a back-test of an EA using iCustom. It all depends on how the EA and the Indicator is coded. In order to prevent that and to make an EA faster, I usually recode only the essential code into the EA itself so as not to depend on external indicators, but that is another matter not directly related to your case. Just a suggestion for your future EAs.

 
aed71:


Hi FMIC,

... I want to get the high and low values of the gray zigzag lines but when I write down all the high and lows in the log they are exactly the same with your pink and cyan color dots. However I need the zig zag values only. ...

Thanks.


As explained before in an earlier post, you can not just use the High and Low buffer to get ZigZag points as they also include repainted points as well (aqua and magenta circles on ZigZagZug). On the standard ZigZag it is this way too, but you just don't see them. That is why my indicator shows them so you can understand it better.

You have to compare the High and Low buffers to the first one that holds BOTH Low and Highs in order to filter out ONLY ZigZag points.

NB! You will need to compare the first buffer (Mode 0) with the other 2 buffers in order do decide if it is a High Point or a Low Point (e.g. if both Buffer 1 and Buffer 3 have the same value then it is a Low ZigZag point, and if both Buffer 1 and Buffer 2 are the same then it is a High point).

If you want, attach your file to a post, and I will correct it so you can see how to use it correctly ( ATTACH it, don't use SRC so as not to be long post ).

Reason: