诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

Kaufman均线 Kaufman2.mq4

Kaufman2 指标创建自定义均线。

图表:Kaufman2 指标

源码:

//+------------------------------------------------------------------+
//|                                                     Kaufman2.mq4 |
//|                                  Copyright 2004, by konKop wellx |
//+------------------------------------------------------------------+
#property copyright "Copyright 2004, by konKop, GOODMAN, Mstera, af wellx"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Sienna

extern int       periodAMA=9;
extern int       nfast=2;
extern int       nslow=30;
extern int       G=2;

double kAMAbuffer[];
int    cbars=0;
double slowSC,fastSC;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,kAMAbuffer);
   IndicatorDigits(6);
   cbars=IndicatorCounted();
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int    i,pos=0;
   double noise,AMA,AMA0,signal,ER;
   double dSC,ERSC,wlxSSC;

   slowSC=(2.0 /(nslow+1));
   fastSC=(2.0 /(nfast+1));

   if (Bars<=(periodAMA+2)) return(0);

   if (cbars<0) return(-1);
   if (cbars>0) cbars--;
   pos=Bars-periodAMA-2;
   AMA0=Close[pos+1];
   while (pos>=0)
     {
      if(pos==Bars-periodAMA-2) AMA0=Close[pos+1];
      signal=MathAbs(Close[pos]-Close[pos+periodAMA]);
      noise=0;
      for(i=0;i<periodAMA;i++)
       {
        noise=noise+MathAbs(Close[pos+i]-Close[pos+i+1]);
       };
      ER =signal/noise;
      dSC=(fastSC-slowSC);
      ERSC=ER*dSC;
      wlxSSC=ERSC+slowSC;
      AMA=AMA0+(MathPow(wlxSSC,G)*(Close[pos]-AMA0));
      kAMAbuffer[pos]=AMA;

      AMA0=AMA;
      pos--;
     };
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » Kaufman均线 Kaufman2.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏