//+------------------------------------------------------------------+
//|                                                        S-RoC.mq4 |
//|                                    Copyright (C) 2009 DragoTrade |
//|                        Licensed under GNU General Public License |
//+------------------------------------------------------------------+
#property copyright "DragoTrade" 
#property link      "https://forexsystemsru.com/indikatory-foreks/86203-indikatory-sobranie-sochinenii-tankk.html"   ///"https://forexsystemsru.com/1259817-post7617.html"   ///https://forexsystemsru.com/1198113-post65.html"   //http://forexsystemsru.com/indikatory-foreks-f41/" 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  clrGold  //Yellow
#property indicator_width1  3
#property indicator_style1  STYLE_DOT
//---
#property indicator_level1  0
#property indicator_levelcolor clrMediumVioletRed  //DarkSlateGray  //DimGray  //DarkOrchid  //SteelBlue //MediumOrchid
#property indicator_levelstyle STYLE_DOT  //DASH
//---- input parameters
extern int               MAPeriod  =  13;
extern int              ROCPeriod  =  21;
extern ENUM_MA_METHOD      MAMode  =  MODE_EMA;
extern ENUM_APPLIED_PRICE MAPrice  =  PRICE_WEIGHTED;  // VWMA Price to use 
//---- buffers
double ROC[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexBuffer(0,ROC);   SetIndexStyle(0,DRAW_LINE);
   IndicatorShortName("S-RoC TT ["+(string)MAPeriod+"+"+(string)ROCPeriod+"]");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{                                                /// Справочник МТ4:
   int i=Bars-(ROCPeriod+MAPeriod)-1;             /// Momentum определяется как отношение сегодняшней цены к цене n периодов назад:
   double t, curr, prev;                           /// MOMENTUM = CLOSE (i) / CLOSE (i - n) * 100

   while (i>=0)
    {
     curr = iMA(NULL,0,MAPeriod,0,MAMode,MAPrice,i);
     prev = iMA(NULL,0,MAPeriod,0,MAMode,MAPrice,i+ROCPeriod);
     //---
     if (prev!=0) t = (curr-prev)/prev;
     //---
     ROC[i] = t;
     i--;
    }
//----
//----
return(0);
}
//+------------------------------------------------------------------+