//+------------------------------------------------------------------+
//|                                                  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

#property indicator_level1 250
#property indicator_level2 100
#property indicator_level3 0
#property indicator_level4 -100
#property indicator_level5 -250
		

extern int CCIPeriod = 14;
extern int MaType = MODE_EMA;
extern int MaPeriod = 50;
extern int TimeFrame = 0;

double cci[],
       ema[],
       cciTF[],
       emaTF[];
       
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   
   SetIndexBuffer(0,cci);
   SetIndexBuffer(1,ema);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(2,cciTF);
   SetIndexBuffer(3,emaTF);
   
   IndicatorShortName("MTF CCI"+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++) cciTF[i] = iCCI(Symbol(),TimeFrame,CCIPeriod,PRICE_TYPICAL,i);
     for(int j=0; j<limitTF; j++) emaTF[j] = iMAOnArray(cciTF,0,MaPeriod,0,MaType,j);
     
     for(int t=0; t<limit; t++)
     {
         bbshift = iBarShift(Symbol(),TimeFrame,Time[t]);
         cci[t] = cciTF[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)");
      case PERIOD_MN1: return("MN(1)");
      default:return("Unknown timeframe");
   }
}