sinc_MA_001





//+------------------------------------------------------------------+
//|                                                      sinc_MA.mq4 |
//|                                          Copyright © 2006, gpwr. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, gpwr."
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 2
//Global constants
#define pi 3.141592653589793238462643383279502884197169399375105820974944592
//Input parameters
extern int    N      =2560; // Number of last bars. Must be the power of 2. 0: all data.
extern int    htrun  =3;   // Number of the last wavelets to truncate.
// Damping factor. Higher Q gives more ripple. Q=1 gives sinc function. 
extern double Q      =0.5;
//Global variables
int n;      
int pwrMax; 
//Indicator buffers
double sMA[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   if(N <= 0) 
       N = Bars;
   n = 1;
   int pwr = 0;
   while(n <= N)
     {
       pwr++;
       n *= 2;
     }
   pwr--;
   n = MathPow(2, pwr);
   Print("pwr=", pwr);
   if(htrun <= 0) 
       htrun = 0;
   if(htrun >= pwr) 
       htrun = pwr;
   pwrMax = pwr - htrun;
   IndicatorBuffers(1);
   SetIndexBuffer(0, sMA);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorShortName("sincMA");
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
    return(0);
  } 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//START--------------------------------------------------------------+
int start()
  {
   ArrayInitialize(sMA, EMPTY_VALUE);
   double Fit[], Dif[];
   ArrayResize(Fit, n+1);
   ArrayResize(Dif, n+1);
   for(int i = 0; i <= n; i++)
     {
       Fit[i] = (Close[n] - Close[0])*i / n + Close[0];
       Dif[i] = Close[i] - Fit[i];
       sMA[i] = Fit[i];
     }
   int ss = 2*n; // sampling step
   for(int p = 1; p <= pwrMax; p++)
     {
       ss = ss / 2;
       for(i = 0; i <= n; i++)
         {
           Fit[i] = 0.0;
           for(int j = 1; j <= n / ss; j++)
               Fit[i] += Dif[j*ss - ss / 2]*wave(2*j - 1 - 2.0*i / ss, Q);
         }
       for(i = 0; i <= n; i++)
         {
           Dif[i] -= Fit[i];
           sMA[i] += Fit[i];
         }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//sinc function------------------------------------------------------+
double wave(double x, double Q)
  {
   if(x == 0.0)
       return(1.0);
   else 
       return(MathSin(pi*x) / (pi*x) / (x*x + 1)*(Q*x*x + 1));
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: