//+------------------------------------------------------------------+
//|                                              TDI OnChart MAs.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3


extern int    MA_Period1                 = 13;
extern int    MA_Method1                 = 0;
extern int    MA_Price1                  = 0;
extern int    MA_Shift1                  = 0;
extern color  MA_Color1                  = Yellow;

extern int    MA_Period2                 = 7;
extern int    MA_Method2                 = 0;
extern int    MA_Price2                  = 0;
extern int    MA_Shift2                  = 0;
extern color  MA_Color2                  = Red;

extern int    MA_Period3                 = 2;
extern int    MA_Method3                 = 0;
extern int    MA_Price3                  = 0;
extern int    MA_Shift3                  = 0;
extern color  MA_Color3                  = LimeGreen;

//-------------------------------------------------------------------------------------------------
double MABuffer1[];
double MABuffer2[];
double MABuffer3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    IndicatorBuffers(3);
    
    SetIndexBuffer(0, MABuffer1);
    
    SetIndexBuffer(1, MABuffer2);
    
    SetIndexBuffer(2, MABuffer3);
    
  
    IndicatorShortName("TDI OnChart MAs");
  }
//----
 return(0);
 
int deinit(){ return(0);  }

int start()
  {
  
   SetIndexStyle (0, DRAW_LINE,0,2,MA_Color1);
         
   SetIndexStyle (1, DRAW_LINE,0,2,MA_Color2);
          
   SetIndexStyle (2, DRAW_LINE,0,2,MA_Color3);
  
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
     {
   
   MABuffer1[i]=iMA(NULL, 0, MA_Period1,MA_Shift1,MA_Method1, MA_Price1, i);
   MABuffer2[i]=iMA(NULL, 0, MA_Period2,MA_Shift2,MA_Method2, MA_Price2, i);
   MABuffer3[i]=iMA(NULL, 0, MA_Period3,MA_Shift3,MA_Method3, MA_Price3, i);
 
   }    
  return(0);
  }
 
//+---------------------------------------------------------------------------------------------------------+