如何只提取Zigzag指标提取的底部转折点?

 

尊敬的各位,如何修改代码以只显示人字形的底部?

下面的代码可以成功提取人字形指标提取的顶部。在init()函数 中,tops[]已被指定为索引缓冲区....,但是否可以通过修改iCustom调用的倒数第二个参数,只显示较低转折点的底部?如果答案是否定的。那么我在MT4平台上应该怎么做?我曾尝试将0和2作为最后的第二个参数,但结果不是我想要的....。

我的代码附在后面,以方便你使用。我已经尽可能地简化了它...谢谢你的时间和考虑。
int start()
{
  int counted_bars=IndicatorCounted();
  int limit=0;
  limit = Bars-counted_bars;
  
  for(int shift=limit-1;shift>=0;shift--)
  {
    tops[shift]=iCustom (NULL,0,"ZigZag", 12,5,3, 1, shift);
    if(tops[shift]>0.1) tops[shift]=tops[shift];
  }
  
  return(0);
}

附加的文件:
 

比如说比较

double K = iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
if (K==Low[i] && K>0)  //..low zigzag......   
 

deVries,

非常感谢你的及时答复。你的意思是简单地将iCustom的最后第二个参数改为0?我以前也试过这样做。结果肯定不是我想要的。为了使我的问题更清楚,我展示了以下两个数字来说明我的问题....

.FIg.1 上图中显示了不期望的顶部(A.B.C.D.e)。

图1:当我想只显示僵尸时,却显示了不需要的顶点!我想在我只想显示底部的时候过滤掉所有不需要的顶部。

图2.仅显示所需的顶部

FIg2.所需的顶部被显示出来,没有任何不需要的底部。这是我想要的结果。

所以我的问题是:是否有可能只显示底部的点而不显示A/B/C/D/E点?我希望我已经把问题说清楚了.....。

非常感谢您的及时回复....

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

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Magenta
#property indicator_color3 LightSkyBlue


//---- indicator parameters
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
//---- indicator buffers
double ZigzagBuffer[];
double HighMapBuffer[];
double LowMapBuffer[];
int level=3; // recounting's depth 
bool downloadhistory=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexStyle(1,DRAW_SECTION);   
   SetIndexStyle(2,DRAW_SECTION);   
//---- indicator buffers mapping
   SetIndexBuffer(0,ZigzagBuffer);
   SetIndexBuffer(1,HighMapBuffer);
   SetIndexBuffer(2,LowMapBuffer);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);   
   SetIndexEmptyValue(2,0.0);   

//---- indicator short name
   IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars = IndicatorCounted();
   int limit,counterZ,whatlookfor;
   int shift,back,lasthighpos,lastlowpos;
   double val,res;
   double curlow,curhigh,lasthigh,lastlow;

   if (counted_bars==0 && downloadhistory) // history was downloaded
     {
      ArrayInitialize(ZigzagBuffer,0.0);
      ArrayInitialize(HighMapBuffer,0.0);
      ArrayInitialize(LowMapBuffer,0.0);
     }
   if (counted_bars==0) 
     {
      limit=Bars-ExtDepth;
      downloadhistory=true;
     }
   if (counted_bars>0) 
     {
      while (counterZ<level && i<100)
        {
         res=ZigzagBuffer[i];
         if (res!=0) counterZ++;
         i++;
        }
      i--;
      limit=i;
      if (LowMapBuffer[i]!=0) 
        {
         curlow=LowMapBuffer[i];
         whatlookfor=1;
        }
      else
        {
         curhigh=HighMapBuffer[i];
         whatlookfor=-1;
        }
      for (i=limit-1;i>=0;i--)  
        {
         ZigzagBuffer[i]=0.0;  
         LowMapBuffer[i]=0.0;
         HighMapBuffer[i]=0.0;
        }
     }
      
   for(shift=limit; shift>=0; shift--)
     {
      val=Low[iLowest(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=LowMapBuffer[shift+back];
               if((res!=0)&&(res>val)) LowMapBuffer[shift+back]=0.0; 
              }
           }
        } 
      if (Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
      //--- high
      val=High[iHighest(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=HighMapBuffer[shift+back];
               if((res!=0)&&(res<val)) HighMapBuffer[shift+back]=0.0; 
              } 
           }
        }
      if (High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
     }

   // final cutting 
   if (whatlookfor==0)
     {
      lastlow=0;
      lasthigh=0;  
     }
   else
     {
      lastlow=curlow;
      lasthigh=curhigh;
     }
   for (shift=limit;shift>=0;shift--)
     {
      res=0.0;
      switch(whatlookfor)
        {
         case 0: // look for peak or lawn 
            if (lastlow==0 && lasthigh==0)
              {
               if (HighMapBuffer[shift]!=0)
                 {
                  lasthigh=High[shift];
                  lasthighpos=shift;
                  whatlookfor=-1;
                  ZigzagBuffer[shift]=lasthigh;
                  res=1;
                 }
               if (LowMapBuffer[shift]!=0)
                 {
                  lastlow=Low[shift];
                  lastlowpos=shift;
                  whatlookfor=1;
                  ZigzagBuffer[shift]=lastlow;
                  res=1;
                 }
              }
             break;  
         case 1: // look for peak
            if (LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
              {
               ZigzagBuffer[lastlowpos]=0.0;
               lastlowpos=shift;
               lastlow=LowMapBuffer[shift];
               ZigzagBuffer[shift]=lastlow;
               res=1;
              }
            if (HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
              {
               lasthigh=HighMapBuffer[shift];
               lasthighpos=shift;
               ZigzagBuffer[shift]=lasthigh;
               whatlookfor=-1;
               res=1;
              }   
            break;               
         case -1: // look for lawn
            if (HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
              {
               ZigzagBuffer[lasthighpos]=0.0;
               lasthighpos=shift;
               lasthigh=HighMapBuffer[shift];
               ZigzagBuffer[shift]=lasthigh;
              }
            if (LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
              {
               lastlow=LowMapBuffer[shift];
               lastlowpos=shift;
               ZigzagBuffer[shift]=lastlow;
               whatlookfor=1;
              }   
            break;               
         default: return; 
        }
     }

   return(0);
  }
//+------------------------------------------------------------------+

可以只显示人字形的缓冲区

zigzag正在重新绘制


看看这个结果

 

这是我得出的结果。我还没有检查上面deVries的结果[他发帖时我正在做这个]。

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1

double Bottoms[];
double Toppers[];

int init()
{

   IndicatorBuffers(2);

   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,Bottoms);
   SetIndexEmptyValue(0,0.0);

   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,Toppers);
   SetIndexEmptyValue(1,0.0);

  IndicatorShortName("zz show top & bottom");
  return(0);
}

int deinit()
{
  return(0);
}

int start()
{
  int counted_bars=IndicatorCounted();
  int limit=0;
  limit = Bars-counted_bars;
  
  for(int shift=limit-1;shift>=0;shift--)
  {
    int ExtDepth=12; int ExtDeviation=5; int ExtBackstep=3;
    int ZigzagBuffer=0; int HighMapBuffer=1; int LowMapBuffer=2;
    
    Bottoms[shift]=iCustom(
        Symbol(),0,"ZigZag",
        ExtDepth, ExtDeviation, ExtBackstep,
        LowMapBuffer, shift
    );
    
    Toppers[shift]=iCustom(
        Symbol(),0,"ZigZag",
        ExtDepth, ExtDeviation, ExtBackstep,
        HighMapBuffer, shift
    );
    
    if(Bottoms[shift]>0.1) Bottoms[shift]=Bottoms[shift];
    if(Toppers[shift]>0.1) Toppers[shift]=Toppers[shift];
  }
  
  return(0);
}

 
ubzen:

这是我得出的结果。我还没有检查上面deVries的结果[他发帖时我正在做这个]。

很好 在你的代码的帮助下,我来到了这个......。

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_width1 3
#property indicator_color2 Green
#property indicator_width2 3
#property indicator_color3 Yellow
#property indicator_width3 3


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


double ZigZag[];
double Bottoms[];
double Toppers[];

int init()
{
   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ZigZag);
   SetIndexEmptyValue(0,0.0);
   
   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,Bottoms);
   SetIndexEmptyValue(1,0.0);

   SetIndexStyle(2,DRAW_SECTION);
   SetIndexBuffer(2,Toppers);
   SetIndexEmptyValue(2,0.0);

  IndicatorShortName("zz show top & bottom");
  return(0);
}

int deinit()
{
  return(0);
}

int start()
{
  int counted_bars=IndicatorCounted();
  int limit=0;
  limit = Bars-counted_bars;
  
  for(int shift=limit-1;shift>=0;shift--)
  {
    ZigZag[shift]=iCustom(
        Symbol(),0,"ZigZag",
        ExtDepth, ExtDeviation, ExtBackstep,
        0, shift
    );

    if(ZigZag[shift]>0.1 && Low[shift]==ZigZag[shift]) Bottoms[shift]=ZigZag[shift];
    if(ZigZag[shift]>0.1 && High[shift]==ZigZag[shift]) Toppers[shift]=ZigZag[shift];
  }
  
  return(0);
}

这是给的结果


现在,底部和顶部都与 "之 "字形匹配。

 
deVries: 不错的ubzen,在你的代码的帮助下,我来到了这个......这就是结果
干得好,deVries
 
亲爱的各位,在你们的帮助和善意下,特别是deVries和Ubzen的帮助下,我的指标成功地画出了在这个欢快的初春早晨由之字形指标 提取的底部转折点之间的联系....:)
 
d



deVries:

不错的ubzen,在你的代码的帮助下,我来到了这个......。

这是给的结果

现在底部和顶部都与 "之 "字形匹配。





你好,deVries。

非常感谢你的代码。如果我想知道最后一条之字形腿的斐波那契回撤线与前一条之字形腿相比有多远。如何做到这一点?

我想做的是像图片一样,但下面的代码,我试图没有使它...

谢谢。

撸起袖子加油干

飞博回撤


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_width1 3
#property indicator_color2 Green
#property indicator_width2 3
#property indicator_color3 Yellow
#property indicator_width3 3


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


double ZigZag[];
double Bottoms[];
double Toppers[];
double resBuffer[][];

//---
int init() {
   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_SECTION);
   SetIndexBuffer(0,ZigZag);
   SetIndexEmptyValue(0,0.0);
   
   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,Bottoms);
   SetIndexEmptyValue(1,0.0);

   SetIndexStyle(2,DRAW_SECTION);
   SetIndexBuffer(2,Toppers);
   SetIndexEmptyValue(2,0.0);

  IndicatorShortName("zz show top & bottom");
  return(0);
}

int deinit()
{
  ObjectDelete("myFibo");
  return(0);
}

int start()
{
  int counted_bars=IndicatorCounted();
  int limit=0;
  limit = Bars-counted_bars;
  int k=0, m=0;
  int candle1=0, candle2=0;
  double prc1=0, prc2=0;
  
  for(int shift=limit-1;shift>=0;shift--) {
    ZigZag[shift]=iCustom(
        Symbol(),0,"ZigZag",
        ExtDepth, ExtDeviation, ExtBackstep,
        0, shift
    );

    if(ZigZag[shift]>0.1 && Low[shift]==ZigZag[shift]) {
      Bottoms[shift]=ZigZag[shift];
      resBuffer[k][0] = Bottoms[shift];
      resBuffer[k][1] = shift;
      k++;
    }
    if(ZigZag[shift]>0.1 && High[shift]==ZigZag[shift]) {
      Toppers[shift]=ZigZag[shift];
      resBuffer[k][0] = Toppers[shift];
      resBuffer[k][1] = shift;
      k++;
    }
  } // ende for
  
  //---
  for(m=k;m>=0;m--) {
   candle1 = resBuffer[m][1];
   prc1 = resBuffer[m][0];
   candle2 = resBuffer[m-1][1];
   prc2 = resBuffer[m-1][0];
   //---
         ObjectDelete("myFibo");
         ObjectCreate("myFibo", OBJ_FIBO, 0, Time[candle1], prc2, Time[candle2], prc1);
 
  } // ende for
          
  return(0);
}
 
jackprobe:


嗨,deVries。

非常感谢您的代码。如果我想知道上一个 "之 "字形腿的斐波那契回撤线与上一个 "之 "字形腿相比有多远。如何做到这一点?

谢谢。

千斤顶


用这种方式画斐波纳契,用之字形指标iCustom 找到两个点

0.0 1.6154

100.0 1.6168

差额0.0014

最后的高点=1.6169

与0.0 0.0015的差异在% 0.0015/0.0014 * 100% = 107%的距离 + 0.0001

这就是你的意思吗?

 

嗨,deVries。

谢谢你。是的,它就像你发来的图片一样。 但我想知道如何编写代码。它必须计算之前的每一个Zigzag腿,然后画出Fibonacci水平,这样我们就知道当前/最后一个Zigzag走了多远。

编辑:我把代码发到了前面的帖子里。它不会画出斐波 那契线...

谢谢

原因: