首页/学院/交易策略/EA智能交易/文章详细

MT4指标:NonLagZigZag_v2源码

外汇网2021-06-17 09:41:36 126
汇外网 - 全球专业的黄金外汇门户导航行情资讯网站

这是一款改编ZigZag将来MT4指标

//+------------------------------------------------------------------+

//| NonLagZigZag_v2.mq4 |

//| Copyright ?2006, TrendLaboratory |

//| http://finance.groups.yahoo.com/group/TrendLaboratory |

//| E-mail: igorad2003@yahoo.co.uk |

//+------------------------------------------------------------------+

#property copyright "Copyright ?2006, TrendLaboratory"

#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"

//----

#property indicator_chart_window

#property indicator_buffers 1

//----

#property indicator_color1 Gold

#property indicator_width1 2

//---- input parameters

extern int Price =0; //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close)

extern int Length =100; //Period of NonLagMA

extern double PctFilter =2; //Dynamic filter in decimals

//----

double ZZBuffer[];

double MABuffer[];

double trend[];

double Del[];

double AvgDel[];

//----

int ilow, ihigh, nlow, nhigh, prevnhigh,prevnlow, BarsBack;

double alfa[];

datetime lotime,hitime;

int i, Phase, Len, Cycle=4, Back=0;

double Coeff, beta, t, Sum, Weight, g;

double pi=3.1415926535;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(5);

SetIndexStyle(0,DRAW_SECTION);

SetIndexBuffer(0,ZZBuffer);

SetIndexBuffer(1,MABuffer);

SetIndexBuffer(2,trend);

SetIndexBuffer(3,Del);

SetIndexBuffer(4,AvgDel);

tring short_name;

//---- indicator line

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

//---- name for Data万得ow and indicator subwindow label

hort_name="NonLagZigZag("+Length+")";

IndicatorShortName(short_name);

SetIndexLabel(0,"NonLagZigZag");

//----

SetIndexEmptyValue(0,0.0);

SetIndexDrawBegin(0,Length*Cycle+Length);

//----

Coeff= 3*pi;

Phase=Length-1;

Len=Length*Cycle + Phase;

ArrayResize(alfa,Len);

Weight=0;

for(i=0;i

{

if (i<=Phase-1) t=1.0*i/(Phase-1);

else t=1.0 + (i-Phase+1)*(2.0*Cycle-1.0)/(Cycle*Length-1.0);

eta=MathCos(pi*t);

g=1.0/(Coeff*t+1);

if (t<=0.5)g=1;

alfa[i]=g * beta;

Weight+=alfa[i];

}

//----

return(0);

}

//+------------------------------------------------------------------+

//| NonLagZigZag_v2 |

//+------------------------------------------------------------------+

int start()

{

int i,shift,limit;

double price,smin,smax;

int counted_bars = IndicatorCounted();

if(counted_bars < 0) return(-1);

if(counted_bars > 0) counted_bars--;

limit = Bars - counted_bars;

if(counted_bars==0) limit-=1+1+MathMax(Len,Length);

for(shift=limit;shift>=0;shift--)

{

Sum=0;

for(i=0;i<=Len-1;i++)

{

rice=iMA(NULL,0,1,0,3,Price,i+shift);

Sum+=alfa[i]*price;

}

if (Weight > 0) MABuffer[shift]=Sum/Weight;

Del[shift]=MathAbs(MABuffer[shift] - MABuffer[shift+1]);

//----

double sumdel=0;

for(i=0;i<=Length-1;i++) sumdel+=Del[shift+i];

AvgDel[shift]=sumdel/Length;

//----

double sumpow=0;

for(i=0;i<=Length-1;i++) sumpow+=MathPow(Del[shift+i]-AvgDel[shift+i],2);

double StdDev=MathSqrt(sumpow/Length);

double Filter=PctFilter * StdDev;

if (Filter < Point) Filter=Point;

if(MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter)MABuffer[shift]=MABuffer[shift+1];

//----

trend[shift]=trend[shift+1];

if (MABuffer[shift]-MABuffer[shift+1] > Filter) trend[shift]= 1;

if (MABuffer[shift+1]-MABuffer[shift] > Filter) trend[shift]=-1;

if(trend[shift]>0)

{

if(trend[shift]!=trend[shift+1])

{

ilow=LowestBar(iBarShift(NULL,0,hitime,FALSE)-shift,shift);

lotime=Time[ilow];

ZZBuffer[ilow]=Low[ilow];

}

else

if (shift==0)

{

int hilen=iBarShift(NULL,0,lotime,FALSE);

high=HighestBar(hilen,0);

ZZBuffer[nhigh]=High[nhigh];

if (nhigh== 0) for(i=hilen-1;i>=1;i--) ZZBuffer[i]=0;

if (nhigh > 0) for(i=nhigh-1;i>=0;i--) ZZBuffer[i]=0;

}

}

if (trend[shift]<0)

{

if(trend[shift]!=trend[shift+1])

{

ihigh=HighestBar(iBarShift(NULL,0,lotime,FALSE)-shift,shift);

hitime=Time[ihigh];

ZZBuffer[ihigh]=High[ihigh];

}

else

if (shift==0)

{

int lolen=iBarShift(NULL,0,hitime,FALSE);

low=LowestBar(lolen,0);

ZZBuffer[nlow]=Low[nlow];

if (nlow==0) for(i=lolen-1;i>=1;i--) ZZBuffer[i]=0;

if (nlow >0) for(i=nlow-1;i>=0;i--) ZZBuffer[i]=0;

}

}

}

return(0);

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int LowestBar(int len,int k)

{

double min=10000000;

int lobar;

//----

for(int i=k+len-1;i>=k;i--)

if(Low[i] < min) {min=Low[i]; lobar=i;}

if(len<=0) lobar=k;

return(lobar);

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int HighestBar(int len,int k)

{

double max=-10000000;

int hibar;

for(int i=k+len-1;i>=k;i--)

if(High[i] > max) {max=High[i]; hibar=i;}

if(len<=0) hibar=k;

return(hibar);

}

//+------------------------------------------------------------------+

标签:

随机快审展示
  • 快审 13黄金夜里现价策略布局!原油黄金交易参考在线指导
  • 快审 2.16俄乌局势遇冷猛击原油价格、黄金价格 美盘1860以下持续买跌!原油多空反复震荡,美盘93.6空!
  • 快审 瑞中央银行通胀上升并没有是加息的正值理由 瑞郎人民币下挫
  • 快审 4.11外汇黄金行情行情分析及交易参考,黄金空单被套怎么办?
  • 快审 5.3原油黄金日间行情分析及策略推荐
  • 快审 4.5黄金震荡酝酿单边击穿 原油回弹暂定空
  • 快审 黄金空单连续获利10连胜。轻松交易完美获利
  • 快审 5-10黄金弱势不改欧盘定强弱 今日行情行情行情分析
  • 快审 2.24俄乌事件逐渐退却,1960空单获利40美金出局, 回踩1910直接多
  • 快审 5.18 黄金回踩1815持续空
  • 快审 黄金今日实时行情行情分析及黄金最新操作策略推荐
  • 快审 1.2黄金短线超卖,下周行情预期及交易参考
  • 快审 金银还会涨吗?原油下周开盘行情操作
  • 快审 黄金显现反转信号 短时间买涨机会到来
  • 快审 黄金不破高峰坚定看跌,原油日K线顶部结构已呈现
  • 快审 黄金1863多盈利持有,夜里运行计划1880
  • 快审 1.11星期二独家恒指小纳指德指原油黄金天然气铜交易参考
  • 快审 5.13原油黄金夜里美盘行情分析及最新交易参考
  • 快审 4.28黄金最新行情行情分析,原油独家操作策略布局
  • 快审 莫德纳专利上诉失利暴跌 Snowflake Q3营收成长佳大
  • 快审 4.12今日黄金是否连续上升?最新黄金行情行情分析策略布局