//+------------------------------------------------------------------+
//|                                                     LSMA nrp.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property  copyright "copyleft mladen"
#property  link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightGray
#property indicator_color2 DodgerBlue
#property indicator_color3 DeepPink
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//
//
//
//
//

extern int    LSMAPeriod   = 23;
extern int    LSMAPrice    =  0;
//
//
//
//
//

double lsma[];
double lsmau[];
double lsmad[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   SetIndexBuffer(0,lsma);
   SetIndexBuffer(1,lsmau);  SetIndexStyle(1,DRAW_ARROW);  SetIndexArrow(1,159);
   SetIndexBuffer(2,lsmad);  SetIndexStyle(2,DRAW_ARROW);  SetIndexArrow(2,159);
   return(0);
}

//
//
//
//
//

int start()
{ 
   int      counted_bars=IndicatorCounted();
   int      limit,i;

   if(counted_bars < 0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(i = limit; i >= 0; i--)
   {
      lsma[i]  = 3.0*iMA(NULL,0,LSMAPeriod,0,MODE_LWMA,LSMAPrice,i)-2.0*iMA(NULL,0,LSMAPeriod,0,MODE_SMA,LSMAPrice,i);
      lsmau[i] = EMPTY_VALUE;
      lsmad[i] = EMPTY_VALUE;
         if (lsma[i] > lsma[i+1]) lsmau[i] = lsma[i];
         if (lsma[i] < lsma[i+1]) lsmad[i] = lsma[i];
   }   
   return(0);
}