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

 
jackprobe:

嗨,deVries。

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

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

谢谢



你能告诉我你是如何用这个指标得到0.0和100.0的数值的吗?
 
deVries:

你能告诉我你是如何用这个指标得到0.0和100.0的值的吗?

我使用MT4菲波回撤工具手动 制作的.....。:) 我想要的其实是那张图片,但还是不知道如何编码。

关于iCustom,我是否应该像下面这样调用它(调用你的TopBottomZigzag.ex4文件)?

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

谢谢

 
jackprobe:

我使用MT4菲波回撤工具手动 制作的.....。:) 我想要的其实是那张图片,但还是不知道如何编码。

关于iCustom,我应该像下面这样调用它(调用你的TopBottomZigzag.ex4文件)?

谢谢


不,那是错误的缓冲区,你必须找到i的值,在哪个栏的顶部或底部将是什么?

如果我把它与我在CodeBase中发布的版本相比较,就会发现Zigzag在低点有线,在高点有线

//+------------------------------------------------------------------+
//|                                              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++;
      }
}

这是我在创建这个主题的指标之前用普通的Zigzag做的。

看看你是否找到了其中的逻辑

.

(编辑帖子以提供你在CodeBase中找到的正确版本的链接)

 
deVries:


不,那是错误的缓冲区,你必须找到i的值,在哪个栏的顶部或底部会有。

如果我将其与我在CodeBase中发布的版本进行比较,可以看到低点有线,高点有线的Zigzag

这是我在创建这个主题的指标之前用普通的Zigzag做的。

看看你是否找到了其中的逻辑

.

(编辑帖子以提供你在CodeBase中找到的正确版本的链接)


你好,deVries。

谢谢你的链接。 我刚刚尝试用iCustom来调用你的指标,我把它命名为 "TopBottomZigzag.ex4" 。结果很好。这次菲波线是由代码创建的...:)

只是我仍然不能使前一个ZZ腿的Fibo .... :( 它总是只画最后一个ZZ腿。 而且还不能定义Fibo水平线的长度 ...

谢谢你的好代码 ....

- 傻瓜

//+------------------------------------------------------------------+
//|                                                       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);      
}
 

明天我将继续

这一部分

   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);

必须要改变

 

如果你看一下你的图片,你会发现斐波那契只在最后两个ZZ点的水平上绘制。

你的问题是 "不能使前一个ZZ腿的Fibo .... :( 它总是只画最后一个ZZ腿。而且还不能定义Fibo水平线的长度..."

所以你必须检查 你的代码是怎么做的,以及它是如何产生你现在的结果的

.

我们想知道你的编码在这部分做了什么?

  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;
      }
   }       

从一些打印语句开始,我们必须找出正在发生的事情。

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);
//.....
      }

你看到发生了什么?

 

嗨,deVries。

使用警报 而不是打印。如果蜡烛在腿的内部(不是在腿的末端或开始),我们就无法捕捉到价格。但是在腿的末端,我们可以看到价格(请看图表上的红色和绿色箭头)。因此,我认为可以使用iCustom,但有一个错误的编码,我仍然不知道它在哪里。

编辑:也许我必须使用数组/缓冲区来保存所有的Z字形末端的信息(Z字形末端的价格&Z字形末端的蜡烛数&Z字形末端的保险数)。 可能我必须使用3x1数组的类型=双数,或只是使用1x1数组的类型字符串(但首先必须做 "连接 "所有结束Zigzag点的信息)????


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;
      }
   }       
 

嗨,deVries。

是的,你是对的。如果我试图捕捉这个值,并把它放到数组中,结果总是0(零) ....
我还是不明白,为什么它可以显示箭头(代表ZZ的结束),但当我试图把它放入数组时,结果却是0......?

谢谢


     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;
      }
 

使用代码库中的指标,那么代码必须是这样的

//   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);
      
     }/* 

在图表上测试这个,你会看到打印出来的数据(没有用的警报)。

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

每一个tick 你都要重新计算,删除几次对象并重新放置新的对象,直到最后一次计算!=0

我给出的代码是什么?

//+------------------------------------------------------------------+
//|                                              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
 
谢谢你deVries.将尝试它...