//+------------------------------------------------------------------+
//|                                                  RSI_EMA_MTF.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_color1 DodgerBlue
#property indicator_color2 Lime
#property indicator_buffers 2

extern int MoMPeriod = 14;
extern int MaType = MODE_EMA;
extern int MaPeriod = 50;
extern int TimeFrame = 60;

double mom[],
       ema[],
       momTF[],
       emaTF[];
       
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   
   SetIndexBuffer(0,mom);
   SetIndexBuffer(1,ema);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(2,momTF);
   SetIndexBuffer(3,emaTF);
   
   IndicatorShortName("MTF Momentum "+tf());
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
     int bbshift,limit,limitTF;
     limit=Bars;
     limitTF = iBars(Symbol(),TimeFrame);
     
     for(int i=0; i<limitTF; i++) momTF[i] = iMomentum(Symbol(),TimeFrame,MoMPeriod,PRICE_CLOSE,i);
     for(int j=0; j<limitTF; j++) emaTF[j] = iMAOnArray(momTF,0,MaPeriod,0,MaType,j);
     
     for(int t=0; t<limit; t++)
     {
         bbshift = iBarShift(Symbol(),TimeFrame,Time[t]);
         mom[t] = momTF[bbshift];
         ema[t] = emaTF[bbshift];
     }

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

string tf()
{
   switch(TimeFrame)
   {
      case PERIOD_M1: return("M(1)");
      case PERIOD_M5: return("M(5)");
      case PERIOD_M15: return("M(15)");
      case PERIOD_M30: return("M(30)");
      case PERIOD_H1: return("H(1)");
      case PERIOD_H4: return("H(4)");
      case PERIOD_D1: return("D(1)");
      case PERIOD_W1: return("W(1)");
      case PERIOD_MN1: return("MN(1)");
      default:return("Unknown timeframe");
   }
}