#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  LimeGreen
#property indicator_color2  PaleVioletRed
#property indicator_color3  PaleVioletRed
#property indicator_width3  2
#property indicator_style1  STYLE_DOT
#property indicator_style2  STYLE_DOT
#property indicator_level1  0

extern int FastPeriod  = 10;
extern int FastMethod  = MODE_EMA;
extern int FastPrice   = PRICE_CLOSE;
extern int SlowPeriod  = 50;
extern int SlowMethod  = MODE_EMA;
extern int SlowPrice   = PRICE_CLOSE;
extern int Price       = PRICE_CLOSE;
extern int PricePeriod = 5;
extern int PriceMethod = MODE_EMA;

double bandUp[];
double bandDn[];
double price[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()
{
   IndicatorDigits(6); 
      SetIndexBuffer(0,bandUp);
      SetIndexBuffer(1,bandDn);
      SetIndexBuffer(2,price);
      return(0);  
}  
int deinit() { return(0);  }  

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);

   //
   //
   //
   //
   //
   
   for(int i=limit; i>=0; i--)
   {
      double ma1 = iMA(NULL,0,FastPeriod ,0,FastMethod ,FastPrice,i);
      double ma2 = iMA(NULL,0,SlowPeriod ,0,SlowMethod ,SlowPrice,i);
      double prc = iMA(NULL,0,PricePeriod,0,PriceMethod,    Price,i);
         double range = MathAbs(ma1-ma2);
         while (true)
         {
            if (prc>ma1 && prc>ma2) { price[i] =  1;              break; }
            if (prc<ma1 && prc<ma2) { price[i] = -1;              break; }
            if (range!=0)           { price[i] = (prc-ma2)/range; break; }
                                      price[i] = 0;               break;
         }            
      bandUp[i] =  1;
      bandDn[i] = -1;
   }
   return(0);
}