//+------------------------------------------------------------------+
//|                                                       MaisMA.mq4 |
//|                                                   Pavel ( 2010 ) |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Pavel Borodin ( 2010 )"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 MediumBlue
//---- input parameters
extern int       N=100;
extern double    m=1.5;
extern int       Shift=1;
extern int       Frame=100;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   int  draw_begin;
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(1,Shift);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   IndicatorShortName("MaisMA ("+N+", "+Shift+")");
   draw_begin=Frame;
   SetIndexDrawBegin(0,draw_begin);
   ArrayInitialize(ExtMapBuffer,0.0);

   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int  i,i2,k,counted_bars=IndicatorCounted();
   int counter, n ;
   double d, val;
   
   if(counted_bars<1)
      for(i=1;i<=Frame;i++)
        {
         ExtMapBuffer1[Bars-i]=EMPTY_VALUE;
         ExtMapBuffer2[Bars-i]=EMPTY_VALUE;
        }

   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   

   for(i=0; i<limit; i++)
   {
      counter = 1;
      i2 = 0;
      val = 0;
      while(counter<=N)
      {
         d = MathAbs(Close[i+i2]-Close[i+i2+1])/0.00001;
         if (d < 1) d = 1;
         d = MathPow(d,m);
         n = MathRound(d);
         for(k=0; k<n; k++)
         {
            val+=Close[i+i2]/N;
            counter++;
            if(counter > N) break;
         }
         i2++;
      
         //ExtMapBuffer1[i] = iMA(NULL,0,N,Shift,MODE_SMA,PRICE_CLOSE,i);
         ExtMapBuffer1[i] = val;
      }
   }
   for(i=0; i<limit; i++)
   {
     ExtMapBuffer1[i] = ExtMapBuffer1[i]/2 + ExtMapBuffer1[i+1]/2;
     ExtMapBuffer2[i] =ExtMapBuffer1[i];
   }
    //  ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1,0,2,0,MODE_SMA,i);
   //ExtMapBuffer1[i]=ExtMapBuffer[i];
   
   
   
   

//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+