指标名称:Gann_S9[color=rgba(0, 0, 0, 0.9)]
版本:MT4 ver. 2.01
[size=16.002px]Gann_S9是基于改进型ZigZag的趋势分析工具,通过自动绘制支撑/阻力线和甘氏角度线,帮助交易者识别潜在的趋势转折点。
[size=16.002px]指标包含以下主要功能: 智能绘制ZigZag折线 自动生成支撑/阻力位 绘制甘氏角度线 标记关键价格水平
1. 核心功能ZigZag折线:自动标记显著的高低点 支撑/阻力线: 蓝色:支撑位 红色:阻力位 角度线:以基准点为中心展开的扇形线
2. 参数调整建议[td]参数组 | 推荐值 | 效果说明 | ZigZag | Depth=21, Deviation=5 | 平衡灵敏度和稳定性 | 角度线 | angle=22.5°, kol_lev=8 | 显示8条不同角度线 | 样式 | Width=2, Style=0 | 使用粗实线提高可视性 | 3. 交易信号解读趋势确认:当价格突破多条角度线时 反转信号:ZigZag出现新折点 + 角度线群集 支撑阻力:水平线密集区为关键价位
参数:
部分代码展示:
- //+------------------------------------------------------------------+//| Gann_S9.mq4 |//+------------------------------------------------------------------+//| Copyright © 2009-2024, www.QChaos.com |//| https://www.qchaos.com/ |//+------------------------------------------------------------------+#property copyright "Copyright © 量化混沌, www.qchaos.com"#property link "https://www.qchaos.com"#property version "2.01"#property strict#property indicator_chart_window#property indicator_buffers 1#property indicator_color1 AliceBlue#property strict#property indicator_width1 0#property indicator_style1 2//----//---基本参数extern double angle_up = 22.5; // 上升角度基数(度)extern double angle_dn = 22.5; // 下降角度基数(度)extern int Width = 0; // 线宽extern int Style = 2; // 线型(0-实线,1-虚线等)extern int kol_lev = 8; // 角度线数量extern color ResistanceColor = Tomato;// 阻力颜色extern color SupportColor = DodgerBlue;// 支撑颜色
- color 颜色;//---ZigZag参数extern int ExtDepth=21; // 折线深度(柱数)extern int ExtDeviation=5; // 最小偏差点数extern int ExtBackstep=3; // 回退步数//---其他参数extern color Level_0 = LightSteelBlue;// 基准线颜色extern bool lev_V = true; // 显示垂直线extern color Level_V = LightSteelBlue;// 垂直线颜色extern int Complect = 0; // 线组编号
- //----//----double ZigZagBuffer[];int timeFirstBar=0;int flag;bool work=true;double vel_prev;//+------------------------------------------------------------------+//| ZigZag initialization function |//+------------------------------------------------------------------+int init() {//---- SetIndexBuffer(0,ZigZagBuffer); SetIndexStyle(0,DRAW_SECTION,2); SetIndexEmptyValue(0,0.0);
- IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");//---- return(0); }//+------------------------------------------------------------------+//| deinit |//+------------------------------------------------------------------+int deinit() {//---- ObjDel(); Comment("");//---- return(0); }//+------------------------------------------------------------------+//| ZigZag iteration function |//+------------------------------------------------------------------+int start() {//----+ 检查柱数是否足够用于正确计算指标 if(Bars-1<ExtDepth) return(0);//----+ 为未计算柱引入整型内存变量 static int time2,time3,time4;//----+ 为未计算柱引入浮点型变量 static double ZigZag2,ZigZag3,ZigZag4;//----+ 引入整型变量用于未计算柱并获取已计算柱 int MaxBar,limit,supr2_bar,supr3_bar,supr4_bar,counted_bars=IndicatorCounted();//---- 错误检查 if(counted_bars<0) return(-1);//---- 最后一个已计算柱需要重新计算 if(counted_bars>0) counted_bars--;
- //----+ 变量声明 int index, shift, back,lasthighpos,lastlowpos; double val,res,TempBuffer[1]; double curlow,curhigh,lasthigh,lastlow;
- int metka=0; // =0 - 第一个ZZ转折前 =1 - 寻找最大值标记 =2 - 寻找最小值标记
- //---- 定义最旧柱的编号 MaxBar=Bars-ExtDepth;//---- 定义循环起始柱编号 if(counted_bars==0 || Bars-counted_bars>2) { limit=MaxBar; } else { //---- supr2_bar=iBarShift(NULL,0,time2,TRUE); supr3_bar=iBarShift(NULL,0,time3,TRUE); supr4_bar=iBarShift(NULL,0,time4,TRUE); //---- limit=supr3_bar; if((supr2_bar<0)||(supr3_bar<0)||(supr4_bar<0)) { limit=MaxBar; } }
- if(limit>=MaxBar || timeFirstBar!=Time[Bars-1]) { timeFirstBar=Time[Bars-1]; limit=MaxBar; }
- if(limit==MaxBar) ArrayResize(TempBuffer,Bars); else ArrayResize(TempBuffer,limit+ExtBackstep+1);
- //----+-------------------------------------------------+ for(shift=limit; shift>=0; shift--) { //--- Low 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=ZigZagBuffer[shift+back]; if((res!=0)&&(res>val)) ZigZagBuffer[shift+back]=0.0; } } } if(Low[shift]==val) { ZigZagBuffer[shift]=val; //if (ExtLabel==1) la[shift]=val; } else ZigZagBuffer[shift]=0.0;
- //--- 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=TempBuffer[shift+back]; if((res!=0)&&(res<val)) TempBuffer[shift+back]=0.0; } } } if(High[shift]==val) { TempBuffer[shift]=val; //if (ExtLabel==1) ha[shift]=val; } else TempBuffer[shift]=0.0; }// final cutting lasthigh=-1; lasthighpos=-1; lastlow= -1; lastlowpos= -1;//----+-------------------------------------------------+
- for(shift=limit; shift>=0; shift--) { curlow=ZigZagBuffer[shift]; curhigh=TempBuffer[shift]; if((curlow==0)&&(curhigh==0)) continue; //--- if(curhigh!=0) { if(lasthigh>0) { if(lasthigh<curhigh) TempBuffer[lasthighpos]=0; else TempBuffer[shift]=0; } //--- if(lasthigh<curhigh || lasthigh<0) { lasthigh=curhigh; lasthighpos=shift; } lastlow=-1; } //---- if(curlow!=0) { if(lastlow>0) { if(lastlow>curlow) ZigZagBuffer[lastlowpos]=0; else ZigZagBuffer[shift]=0; } //--- if((curlow<lastlow)||(lastlow<0)) { lastlow=curlow; lastlowpos=shift; } lasthigh=-1; } }//----+-------------------------------------------------+ for(shift=limit; shift>=0; shift--) { res=TempBuffer[shift]; if(res!=0.0) ZigZagBuffer[shift]=res; }
- int i=0,j=0; res=0; for(shift=0; i<3; shift++) { if(ZigZagBuffer[shift]>0) { i++; if(i==1 && ZigZagBuffer[shift]==High[shift]) { j=shift; res=ZigZagBuffer[shift]; } if(i==2 && res>0 && ZigZagBuffer[shift]==High[shift]) { if(ZigZagBuffer[shift]>=ZigZagBuffer[j]) ZigZagBuffer[j]=0; else ZigZagBuffer[shift]=0; res=0; i=0; j=0; shift=0; } } }
-
- if(limit<MaxBar) { ZigZagBuffer[supr2_bar]=ZigZag2; ZigZagBuffer[supr3_bar]=ZigZag3; ZigZagBuffer[supr4_bar]=ZigZag4; for(int qqq=supr4_bar-1; qqq>supr3_bar; qqq--) ZigZagBuffer[qqq]=0; for(int ggg=supr3_bar-1; ggg>supr2_bar; ggg--) ZigZagBuffer[ggg]=0; }//+---+============================================+
- double vel1, vel2, vel3, vel4; int bar1, bar2, bar3, bar4; int count; if(limit==MaxBar) supr4_bar=MaxBar; for(int bar=supr4_bar; bar>=0; bar--) { if(ZigZagBuffer[bar]!=0) { count++; vel4=vel3; bar4=bar3; vel3=vel2; bar3=bar2; vel2=vel1; bar2=bar1; vel1=ZigZagBuffer[bar]; bar1=bar; ObjDel(); if(count<3) continue; if((vel3<vel2)&&(vel2<vel1)) { ZigZagBuffer[bar2]=0; bar=bar3+1; } if((vel3>vel2)&&(vel2>vel1)) { ZigZagBuffer[bar2]=0; bar=bar3+1; } if((vel2==vel1)&&(vel1!=0)) { ZigZagBuffer[bar1]=0; bar=bar3+1; } } }
- time2=Time[bar2]; time3=Time[bar3]; time4=Time[bar4]; ZigZag2=vel2; ZigZag3=vel3; ZigZag4=vel4;
复制代码
|