📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    ZigZag显示顶点值指标 

    360 LV19
    2016-11-14 · 9562 阅读
    1. //+------------------------------------------------------------------+
    2. //|                                                       Zigzag.mq4 |
    3. //|                 Copyright ?2005-2007, MetaQuotes Software Corp. |
    4. //|                                 
    5. //+------------------------------------------------------------------+
    6. #property copyright "Copyright ?2007, MetaQuotes Software Corp."

    7. #property indicator_chart_window
    8. #property indicator_buffers 1
    9. #property indicator_color1 Red
    10. //---- indicator parameters
    11. extern int ExtDepth=12;
    12. extern int ExtDeviation=5;
    13. extern int ExtBackstep=3;
    14. extern color White_Color=White;
    15. extern int LineWidth=2;
    16. //---- indicator buffers
    17. double ZigzagBuffer[];
    18. double HighMapBuffer[];
    19. double LowMapBuffer[];
    20. int level=3; // recounting's depth
    21. bool downloadhistory=false;
    22. string rp1="rp";
    23. int a=0;

    24. //+------------------------------------------------------------------+
    25. //|                                                                  |
    26. //+------------------------------------------------------------------+
    27. int deinit() {
    28.    ObjectsDeleteAll();
    29. }
    30. //+------------------------------------------------------------------+
    31. //| Custom indicator initialization function                         |
    32. //+------------------------------------------------------------------+
    33. int init()
    34.   {
    35.    IndicatorBuffers(3);
    36. //---- drawing settings
    37.    SetIndexStyle(0,DRAW_SECTION);
    38. //---- indicator buffers mapping
    39.    SetIndexBuffer(0,ZigzagBuffer);
    40.    SetIndexBuffer(1,HighMapBuffer);
    41.    SetIndexBuffer(2,LowMapBuffer);
    42.    SetIndexEmptyValue(0,0.0);

    43. //---- indicator short name
    44.    IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
    45. //---- initialization done
    46.    return(0);
    47.   }
    48. //+------------------------------------------------------------------+
    49. //|                                                                  |
    50. //+------------------------------------------------------------------+
    51. int start()
    52.   {
    53.    int i, counted_bars = IndicatorCounted();
    54.    int limit,counterZ,whatlookfor;
    55.    int shift,back,lasthighpos,lastlowpos;
    56.    double val,res;
    57.    double curlow,curhigh,lasthigh,lastlow;

    58.    if (counted_bars==0 && downloadhistory) // history was downloaded
    59.      {
    60.       ArrayInitialize(ZigzagBuffer,0.0);
    61.       ArrayInitialize(HighMapBuffer,0.0);
    62.       ArrayInitialize(LowMapBuffer,0.0);
    63.      }
    64.    if (counted_bars==0)
    65.      {
    66.       limit=Bars-ExtDepth;
    67.       downloadhistory=true;
    68.      }
    69.    if (counted_bars>0)
    70.      {
    71.       while (counterZ<level && i<100)
    72.         {
    73.          res=ZigzagBuffer[i];
    74.          if (res!=0) counterZ++;
    75.          i++;
    76.         }
    77.       i--;
    78.       limit=i;
    79.       if (LowMapBuffer[i]!=0)
    80.         {
    81.          curlow=LowMapBuffer[i];
    82.          whatlookfor=1;
    83.         }
    84.       else
    85.         {
    86.          curhigh=HighMapBuffer[i];
    87.          whatlookfor=-1;
    88.         }
    89.       for (i=limit-1;i>=0;i--)  
    90.         {
    91.          ZigzagBuffer[i]=0.0;  
    92.          LowMapBuffer[i]=0.0;
    93.          HighMapBuffer[i]=0.0;
    94.         }
    95.      }
    96.       
    97.    for(shift=limit; shift>=0; shift--)
    98.      {
    99.       val=Low[iLowest(NULL,0,MODE_LOW,ExtDepth,shift)];
    100.       if(val==lastlow) val=0.0;
    101.       else
    102.         {
    103.          lastlow=val;
    104.          if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
    105.          else
    106.            {
    107.             for(back=1; back<=ExtBackstep; back++)
    108.               {
    109.                res=LowMapBuffer[shift+back];
    110.                if((res!=0)&&(res>val)) LowMapBuffer[shift+back]=0.0;
    111.               }
    112.            }
    113.         }
    114.       if (Low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
    115.       //--- high
    116.       val=High[iHighest(NULL,0,MODE_HIGH,ExtDepth,shift)];
    117.       if(val==lasthigh) val=0.0;
    118.       else
    119.         {
    120.          lasthigh=val;
    121.          if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
    122.          else
    123.            {
    124.             for(back=1; back<=ExtBackstep; back++)
    125.               {
    126.                res=HighMapBuffer[shift+back];
    127.                if((res!=0)&&(res<val)) HighMapBuffer[shift+back]=0.0;
    128.               }
    129.            }
    130.         }
    131.       if (High[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
    132.      }

    133.    // final cutting
    134.    if (whatlookfor==0)
    135.      {
    136.       lastlow=0;
    137.       lasthigh=0;  
    138.      }
    139.    else
    140.      {
    141.       lastlow=curlow;
    142.       lasthigh=curhigh;
    143.      }
    144.    for (shift=limit;shift>=0;shift--)
    145.      {
    146.       res=0.0;
    147.       switch(whatlookfor)
    148.         {
    149.          case 0: // look for peak or lawn
    150.             if (lastlow==0 && lasthigh==0)
    151.               {
    152.                if (HighMapBuffer[shift]!=0)
    153.                  {
    154.                   lasthigh=High[shift];
    155.                   lasthighpos=shift;
    156.                   whatlookfor=-1;
    157.                   ZigzagBuffer[shift]=lasthigh;
    158.                   res=1;
    159.                  }
    160.                if (LowMapBuffer[shift]!=0)
    161.                  {
    162.                   lastlow=Low[shift];
    163.                   lastlowpos=shift;
    164.                   whatlookfor=1;
    165.                   ZigzagBuffer[shift]=lastlow;
    166.                   res=1;
    167.                  }
    168.               }
    169.              break;  
    170.          case 1: // look for peak
    171.             if (LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
    172.               {
    173.                ZigzagBuffer[lastlowpos]=0.0;
    174.                lastlowpos=shift;
    175.                lastlow=LowMapBuffer[shift];
    176.                ZigzagBuffer[shift]=lastlow;
    177.                res=1;
    178.               }
    179.             if (HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
    180.               {
    181.                lasthigh=HighMapBuffer[shift];
    182.                lasthighpos=shift;
    183.                ZigzagBuffer[shift]=lasthigh;
    184.                whatlookfor=-1;
    185.                res=1;
    186.               }   
    187.             break;               
    188.          case -1: // look for lawn
    189.             if (HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
    190.               {
    191.                ZigzagBuffer[lasthighpos]=0.0;
    192.                lasthighpos=shift;
    193.                lasthigh=HighMapBuffer[shift];
    194.                ZigzagBuffer[shift]=lasthigh;
    195.               }
    196.             if (LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
    197.               {
    198.                lastlow=LowMapBuffer[shift];
    199.                lastlowpos=shift;
    200.                ZigzagBuffer[shift]=lastlow;
    201.                whatlookfor=1;
    202.               }   
    203.             break;               
    204.          default: return;
    205.         }
    206.      }
    207.      
    208.      for (shift=limit;shift>=0;shift--)
    209.       {
    210.       Printrightprice("RP" + DoubleToStr(ZigzagBuffer[shift], Digits), ZigzagBuffer[shift], shift, White_Color, LineWidth);
    211.       CrEAtLine("rp1" + DoubleToStr(ZigzagBuffer[shift], Digits), shift,Yellow);
    212.       
    213.      }
    214.    return(0);
    215.   }
    216.   
    217. //+------------------------------------------------------------------+
    218. //| 显示顶点值                                                       |
    219. //+------------------------------------------------------------------+
    220. void Printrightprice(string mapName, double mapPrice, int mapShift, color mapColor, int mapwidth)
    221. {
    222.    ObjectCreate(mapName, OBJ_ARROW, 0, Time[mapShift], mapPrice);
    223.    ObjectSet(mapName, OBJPROP_COLOR, mapColor);
    224.    ObjectSet(mapName, OBJPROP_WIDTH, mapwidth);
    225.    ObjectSet(mapName, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
    226.    
    227.    
    228. }  
    229. //+------------------------------------------------------------------+
    230. void CrEAtLine(string objName,int time1,color Cl)                             //画水平线函数
    231. {
    232.   // ObjectDelete(objName);
    233.   ObjectCreate(objName,OBJ_VLINE,0,Time[time1],0);
    234.   ObjectSet(objName,OBJPROP_COLOR,Cl);
    235. }
    236.    void wt(string labelname,string date,int j,int x,int y,color colorvalue,int fontsize) //创建WT函数,进行文字显示。
    237. {
    238.    ObjectDelete(labelname);
    239.    ObjectCreate(labelname,OBJ_LABEL,0,0,0);
    240.    ObjectSetText(labelname,date,fontsize,"arial",colorvalue);
    241.    ObjectSet(labelname,OBJPROP_CORNER,j);
    242.    ObjectSet(labelname,OBJPROP_XDISTANCE,x);
    243.    ObjectSet(labelname,OBJPROP_YDISTANCE,y);
    244.    
    245. }
    复制代码


    ZigZag.mq4
    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 9 个

    cooker_wang LV11

    发表于 2017-3-30 19:58:12 | 显示全部楼层

    非常感谢分享,请问一下,怎么才能获取zigzag最后两个拐点的数值?

    阅乐芙月 LV7

    发表于 2018-8-26 17:07:49 | 显示全部楼层

    不错不错,很好哦

    jaryk LV18

    发表于 2018-8-26 17:20:41 | 显示全部楼层

    ZigZag显示顶点值指标

    巴黎不快乐 LV3

    发表于 2020-6-19 20:52:14 | 显示全部楼层

    看帖回帖是美德!:lol

    一笑 LV3

    发表于 2020-6-21 10:26:47 | 显示全部楼层

    找到好贴不容易,我顶你了,谢了

    winer LV3

    发表于 2020-6-23 00:22:42 | 显示全部楼层

    谢谢分享~~~很需要

    a178 LV4

    发表于 2020-7-2 16:09:04 | 显示全部楼层

    真好 ,特牛的东西 非常感谢

    快速开始 LV3

    发表于 2020-7-29 18:11:35 | 显示全部楼层

    学习了,不错

    xsoqwstu LV3

    发表于 2020-11-9 20:06:12 | 显示全部楼层

    支持下
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服