另类MA均线 FIR_MA.mq4-MT4指标-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

另类MA均线 FIR_MA.mq4

FIR_MA 指标创建另类均线。

图表:FIR_MA 指标

源码:

//+------------------------------------------------------------------+
//|                                                       FIR_MA.mq4 |
//|                                                  v.1  09/04/2006 |
//+------------------------------------------------------------------+
#property copyright " v.1  09/04/2006"
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2

#define pi 3.141592653589793238462643383279502884197169399375105820974944592

extern int  Periods = 4;   // 1/(2*Periods) sets the filter bandwidth
extern int  Taps    = 21;  // must be an odd number
extern int  Window  = 4;   // selects windowing function

double FIRMA[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
{
   ArrayInitialize(FIRMA, EMPTY_VALUE);
   IndicatorBuffers(1);
   SetIndexBuffer(0, FIRMA);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorShortName("FIRMA");
   SetIndexShift(0, -(Taps - 1) / 2);
     Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
 }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   double w[];
   ArrayResize(w, Taps);
   double wsum = 0.0;
   for(int k = 0; k < Taps; k++)
     {
       switch(Window)
         {
           case 1: w[k] = 1.0; break; 
           case 2: w[k] = 0.50 - 0.50*MathCos(2.0*pi*k / Taps); break;
           case 3: w[k] = 0.54 - 0.46*MathCos(2.0*pi*k / Taps); break;
           case 4: w[k] = 0.42 - 0.50*MathCos(2.0*pi*k / Taps) + 
                          0.08*MathCos(4.0*pi*k / Taps); break;
           case 5: w[k] = 0.35875 - 0.48829*MathCos(2.0*pi*k / Taps) + 
                          0.14128*MathCos(4.0*pi*k / Taps) - 
                          0.01168*MathCos(6.0*pi*k / Taps); break;
           default: w[k] = 1;break;
         }
       if(k != Taps / 2.0) 
           w[k] = w[k]*MathSin(pi*(k - Taps / 2.0) / Periods) / pi / (k - Taps / 2.0);
       wsum+=w[k];
     }
   int i = Bars - 1 - IndicatorCounted();
   while(i >= 0)
     {
       if(i <= Bars - Taps)
         {
           FIRMA[i] = 0.0;
           for(k = 0; k < Taps; k++) 
               FIRMA[i] += Close[i+k]*w[k] / wsum;
         }
       i--;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类MA均线 FIR_MA.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏