What the Lowest and Highest functions return - page 4

 
I'll try experimenting with the code given by composter on the first page. Maybe something will work.
 
nen:
Correct, it is calculated. The cell number is found. From this cell (time series) the value of maximum or minimum of the bar is taken. It is considered that the maximum has been found on this bar. This value is then placed in the indicator buffer with the found number. The maximum of the indicator should correspond to the maximum on the bar. In my code, maximum is also taken from the array (timeseries) with the same found number and compared to the value of val. It is checked to see if we are doing the right thing: we put into the buffer with this number the value of val. It should also be equal to the maximum of the bar. Comparison of numbers taken from the same place is quite correct.

It seems to me that comparison ...==val, is dangerous because it is the cell number that may change from tick to tick. Especially at small timeframes where there are a lot of closely matched Low and High. However, we should think it over, maybe we mean different moments.
 
nen, would you like to test this zigzag? Actually, this is a request to everyone who has experience of using zigzags and knows what he wants from the zigzag. Maybe you can make something useful out of this prototype?
//+------------------------------------------------------------------+
//|                                                      CZigZag.mq4 |
//|                                         Copyright © 2006, Candid |
//|                                                   likh@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Candid"
#property link      "likh@yandex.ru"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue

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

int    shift;
double res;
int i;
int fBar;
double CurMax,CurMin;
int CurMaxPos,CurMinPos;
int CurMaxBar,CurMinBar;
double hPoint;
double mhPoint;
double EDev;
int MaxDist,MinDist;
bool FirstRun;
bool AfterMax,AfterMin;

//---- indicator buffers
double ZigZag[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- indicators
   SetIndexStyle(0,DRAW_SECTION);
//---- indicator buffers mapping
   SetIndexBuffer(0,ZigZag);
   SetIndexEmptyValue(0,0.0);
//---- indicator short name
   IndicatorShortName("CZigZag("+ExtDepth+","+ExtDeviation+")");
   
   FirstRun = true;
//----
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
//----
   
//----
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  int counted_bars=IndicatorCounted();
  
  if (FirstRun) {
    hPoint = 0.5*Point;
    mhPoint = -hPoint;
//    EDev = ExtDeviation*Point;
    EDev = (ExtDeviation+0.5)*Point;
    AfterMax = true;
    AfterMin = true;
    fBar = Bars-1;
    CurMax = High[fBar];
    CurMaxBar = 1;
    CurMin = Low[fBar];
    CurMinBar = 1;
    MaxDist = 0;
    MinDist = 0;
    FirstRun = false;
  }
//----
  fBar = Bars-counted_bars-1;
  if (fBar > Bars-2) fBar = Bars-2;
  for(shift=fBar; shift>=0; shift--) {
    if (AfterMax) {
//      res = Low[shift]-CurMin-hPoint;
      res = Low[shift]-CurMin;
//      if (res < 0) {
      if (res < mhPoint) {
        ZigZag[Bars-CurMinBar] = 0;
        CurMin = Low[shift];
        CurMinBar = Bars-shift; 
        ZigZag[Bars-CurMinBar] = CurMin;
      } else {  //  if (res < 0)
//        if (res > 0 ) {
        if (res > hPoint ) {
          MaxDist = Bars-CurMaxBar-shift+1;
          MinDist = Bars-CurMinBar-shift+1;
          if ((MaxDist>ExtDepth && MinDist>ExtDepth) || res > EDev) {
            AfterMax = false;
            AfterMin = true;
            CurMaxBar = CurMinBar+1;
            CurMaxPos = Bars-CurMaxBar;
            CurMax = High[CurMaxPos];
            for (i=CurMaxPos-1;i>=shift;i--) {
              if (High[i] > CurMax+hPoint) {
                CurMaxBar = Bars-i;
                CurMax = High[i];
              }
            }  //  for (i=CurMaxPos-1;i>=shift;i--)
            ZigZag[Bars-CurMaxBar] = CurMax;
          }  //  if ((MaxDist>ExtDepth && MinDist>ExtDepth) || res > EDev)
        }  //  if (res > 0 )
      }  // else if (res < 0)
    }  //  if (AfterMax) 
    if (AfterMin) {
//      res = CurMax-High[shift]-hPoint;
      res = CurMax-High[shift];
//      if (res < 0) {
      if (res < mhPoint) {
        ZigZag[Bars-CurMaxBar] = 0;
        CurMax = High[shift];
        CurMaxBar = Bars-shift; 
        ZigZag[Bars-CurMaxBar] = CurMax;
      } else {  //  if (res < 0)
//        if (res > 0 ) {
        if (res > hPoint ) {
          MaxDist = Bars-CurMaxBar-shift+1;
          MinDist = Bars-CurMinBar-shift+1;
          if ((MaxDist>ExtDepth && MinDist>ExtDepth) || res > EDev) {
            AfterMin = false;
            AfterMax = true;
            CurMinBar = CurMaxBar+1;
            CurMinPos = Bars-CurMinBar;
            CurMin = Low[CurMinPos];
            for (i=CurMinPos-1;i>=shift;i--) {
              if (Low[i] < CurMin-hPoint) {
                CurMinBar = Bars-i;
                CurMin = Low[i];
              }
            }  //  for (i=CurMinPos-1;i>=shift;i--)
            ZigZag[Bars-CurMinBar] = CurMin;
          }  //  if ((MaxDist>ExtDepth && MinDist>ExtDepth) || res > EDev)
        }  //  if (res > 0 )
      }  // else if (res < 0)
    }  //  if (AfterMin) 
  }  //  for(shift=fBar; shift>=0; shift--)
//----
  return(0);
}
//+------------------------------------------------------------------+


Please note that although the parameter names are retained, they work differently.


 
Here too, check out my ZigZag, might help get to the bottom of it ....

//+------------------------------------------------------------------+
//|                                                        DT_ZZ.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, klot."
#property link      "klot@mail.ru"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Blue
#property indicator_color3 Red
//---- indicator parameters
extern int ExtDepth=12;
//---- indicator buffers
double zzL[];
double zzH[];
double zz[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 //  IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexArrow(2,159);
   SetIndexArrow(1,159);
//---- indicator buffers mapping
   SetIndexBuffer(0,zz);
   SetIndexBuffer(1,zzH);
   SetIndexBuffer(2,zzL);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
     
//---- indicator short name
   IndicatorShortName("DT_ZZ("+ExtDepth+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    i,shift,pos,lasthighpos,lastlowpos,curhighpos,curlowpos;
   double curlow,curhigh,lasthigh,lastlow;
   double min, max;
   ArrayInitialize(zz,0.0);
   ArrayInitialize(zzL,0.0);
   ArrayInitialize(zzH,0.0);
   
   lasthighpos=Bars; lastlowpos=Bars;
   lastlow=Low[Bars];lasthigh=High[Bars];
  for(shift=Bars-ExtDepth; shift>=0; shift--)
    {
      curlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,shift);
      curlow=Low[curlowpos];
      curhighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,shift);
      curhigh=High[curhighpos];
      //------------------------------------------------
      if( curlow>=lastlow ) { lastlow=curlow; }
      else
         { 
            //идем вниз
            if( lasthighpos>curlowpos  ) 
            { 
            zzL[curlowpos]=curlow;
              ///*
              min=100000; pos=lasthighpos;
               for(i=lasthighpos; i>=curlowpos; i--)
                  { 
                    if (zzL[i]==0.0) continue;
                    if (zzL[i]<min) { min=zzL[i]; pos=i; }
                    zz[i]=0.0;
                  } 
               zz[pos]=min;
               //*/
            } 
          lastlowpos=curlowpos;
          lastlow=curlow; 
         }
      //--- high
      if( curhigh<=lasthigh )  { lasthigh=curhigh;}
      else
         {  
            // идем вверх
            if( lastlowpos>curhighpos ) 
            {  
            zzH[curhighpos]=curhigh;
           ///*
               max=-100000; pos=lastlowpos;
               for(i=lastlowpos; i>=curhighpos; i--)
                  { 
                    if (zzH[i]==0.0) continue;
                    if (zzH[i]>max) { max=zzH[i]; pos=i; }
                    zz[i]=0.0;
                  } 
               zz[pos]=max;
           //*/     
            }  
         lasthighpos=curhighpos;
         lasthigh=curhigh;    
         }       
    //----------------------------------------------------------------------
    }
 return(0);
}
//+------------------------------------------------------------------+



 
nen would you like to test this zigzag? Actually, this is a request to anyone who has experience with zigzags and knows what they want from a zigzag. Maybe you can make something useful out of this prototype?
Please keep in mind that although the names of parameters are the same, they work differently.


Candid. I will have a look at it. The first time I installed it, I had the following observation.
There are several consecutive bars with the same highs. Your variant of the zigzag draws the break (top) on the last bar. That is, the bar closest to zero. Ideally, the break should be drawn on the first bar, which is farthest from the zero bar. The first vertex that appears is significant. It's the same with mtnemums. I can cite several sources (from the literature), where it is required to do so.
 
klot , thank you. Following the idea of your DT-ZigZag I have now made my indicator to work with high timeframe data. But I have only left the idea. I have made my own algorithm. Yesterday I made some more fixes in zigzag. Now I have uploaded it for collective testing. I will certainly try your variant. Here is the description of the indicator that caused the whole mess: http://onix-trade.net/forum/index.php?showtopic=373. Please note that DT-ZigZag mode uses the external zigzag that is included with the indicator. And this external zigzag sometimes fails on the first beam. A new version of the external zigzag is being tested.
 
klot Thank you. Following the idea of your DT-ZigZag I have now made my indicator to work with data of higher timeframes. But I left only the idea. I have made my own algorithm. Yesterday I made some more fixes in zigzag. Now I have uploaded it for collective testing. I will certainly try your variant. Here is the description of the indicator that caused the whole mess: http://onix-trade.net/forum/index.php?showtopic=373. Please note that DT-ZigZag mode uses the external zigzag that is included with the indicator. And this external zigzag sometimes fails on the first beam. A new version of the external zigzag is being tested.

Yes, I noticed :) just an idea :) . I am now using my ZZ all over the place (code in the post above) It works more stable with other TF data.
 
nen:
On the first installation, the following observation immediately arose.
There are several consecutive bars with the same highs. Your zigzag option draws a break (top) on the last bar.
Aha, so I chose the wrong "option". I will now edit the code in the source post. Sign of the changes are the commented out lines of the wrong "option".
 
Candid, it's fine now.
Klot, interesting option.

If your zigzag variants show interesting results, can I apply them in my development?
 
If your zig-zag variants show interesting results, can you apply them in your design?
Yes, of course. If the outcome of testing is positive, I'll even try to add it to the Code Base.
Reason: