//+------------------------------------------------------------------+
//|                                              ROC_Smoothed_v1.mq4 |
//|                                  Copyright © 2007, Forex-TSD.com |
//|             Original Code by IgorAD for KST, modified by Linuxser|                                  
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  DodgerBlue
#property indicator_width1  2
#property indicator_level1  0
//---- input parameters
extern int Mode   = 0;
extern int ROCPeriod   = 14;
extern int SmoothFactor   = 14;

extern string  s1=" Mode 0. SMA";
extern string  s2=" Mode 1. EMA";
extern string  s3=" Mode 2. LWMA";
extern string  s4=" Mode 3. SMMA";

//---- buffers
double ROC[];
double ROC1[];

int l1,m1,MAMode;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   IndicatorBuffers(5);
   SetIndexBuffer(0,ROC);
   SetIndexBuffer(1,ROC1);
   
//---- name for DataWindow and indicator subwindow label
   short_name="SM ROC ("+ROCPeriod+","+SmoothFactor+","+Mode+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   if(Mode == 0) // 5-Minute Bar Short-term KST
   {
   //(Mov(ROC(C,6,%),10,S)*1)+(Mov(ROC(C,10,%),10,S)*2)+(Mov(ROC(C,15,%),8,S)*3)+(Mov(ROC(C,20,%),15,S)*4)
   l1 =  ROCPeriod;
   m1 = SmoothFactor; 
   MAMode = MODE_SMA;
   }
   else
   if(Mode == 1) // 5-Minute Bar Long-term KST
   {
   
   l1 =  ROCPeriod;
   m1 = SmoothFactor; 
   MAMode = MODE_EMA;
   } 
   else
   if(Mode == 2) // 10/15-Minute Bar Short-term KST
   {

   l1 =  ROCPeriod;
   m1 = SmoothFactor; 
   MAMode = MODE_LWMA;
   } 
   else
   if(Mode == 3) // 10/15-Minute Bar Long-term KST
   {

   l1 =  ROCPeriod;
   m1 = SmoothFactor; 
   MAMode = MODE_SMMA;
   } 
   
//----
   SetIndexDrawBegin(0,l1+m1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| ROC Smoothed                                                     |
//+------------------------------------------------------------------+
int start()
{
   int i,limit,counted_bars=IndicatorCounted();
//----
   if(Bars<=l1+m1) return(0);
//---- initial zero
   if ( counted_bars < 0 ) return(-1);
   if ( counted_bars ==0 ) limit=Bars-1;
   
   if ( counted_bars < 1 ) 
   
   for(i=1;i<=l1+m1;i++) 
   {
   ROC[Bars-i]=0.0;
   ROC1[Bars-i]=0.0;

   }
//----
   if(counted_bars>0) limit=Bars-counted_bars;
   limit--;
     
   for(i=limit; i>=0; i--)
   {
   if(Close[i+l1]>0) ROC1[i] = (Close[i]/Close[i+l1]-1)*100;
   }
   
   for(i=limit; i>=0; i--)
   ROC[i] = iMAOnArray(ROC1,0,m1,0,MAMode,i);

   
   return(0);
}
//+------------------------------------------------------------------+