Gaussian filter





//+------------------------------------------------------------------+
//|                                                           mladen |
//|                                                  gaussian filter |
//+------------------------------------------------------------------+
#property copyright "Copyleft © 2008, mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers    1
#property indicator_color1     Red
#property indicator_level1     0.0
#property indicator_levelcolor DarkSlateGray

//
//
//
//
//

extern int Length  = 20;
extern int Order   = 2;
extern int Price   = PRICE_CLOSE;

//
//
//
//
//

double buffer[];
double coeffs[][3];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorDigits(15);
   Length = MathMax(Length,2);
   Order  = MathMax(MathMin(Order,12),1);
      InitCoeffs(Length,Order);

   //
   //
   //
   //
   //
      
   SetIndexBuffer(0,buffer); SetIndexDrawBegin(0,Length);
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//


int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;

   //
   //
   //
   //
   //
   
   for(i = limit; i >= 0; i--)
   {
      buffer[i] = iMA(NULL,0,1,0,MODE_SMA,Price,i)*coeffs[Order][1];
      double sign = 1;
         for (int r=1; r <= Order; r++, sign *= -1.0)
                  buffer[i] += sign*coeffs[r][0]*coeffs[r][2]*buffer[i+r];
   }
   return(0);
}



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

#define Pi 3.141592653589793238462643

void InitCoeffs(int length, int n)
{
   double b = (1.0 - MathCos(2.0*Pi/length))/(MathPow(MathSqrt(2.0),2.0/n) - 1.0);
   double a = -b + MathSqrt(b*b + 2.0*b);

   ArrayResize(coeffs,n+1);
   for(int r=0; r<=n; r++)
   {
       coeffs[r][0] = fact(n)/(fact(n-r)*fact(r));
       coeffs[r][1] = MathPow(    a,r);
       coeffs[r][2] = MathPow(1.0-a,r);
   }
}

//
//
//
//
//

int fact(int n)
{
  if(n==1||n==0)
        return(1);
  else  return(n*fact(n-1));
}





Sample





Analysis



Market Information Used:



Indicator Curves created:



Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: