//+------------------------------------------------------------------+
//|                                                    MultiMA.mq4   |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//|                                       adpated from Alligator     |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Yellow
#property indicator_color5 Orange
//---- input parameters
extern int MA1Period=89;
extern int MA1Shift=0;
extern int MA2Period=55;
extern int MA2Shift=0;
extern int MA3Period=34;
extern int MA3Shift=0;
extern int MA4Period=21;
extern int MA4Shift=0;
extern int MA5Period=13;
extern int MA5Shift=0;
//---- indicator buffers
double ExtMA1Buffer[];
double ExtMA2Buffer[];
double ExtMA3Buffer[];
double ExtMA4Buffer[];
double ExtMA5Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- line shifts when drawing
   SetIndexShift(0,MA1Shift);
   SetIndexShift(1,MA2Shift);
   SetIndexShift(2,MA3Shift);
   SetIndexShift(3,MA4Shift);
   SetIndexShift(4,MA5Shift);
//---- first positions skipped when drawing
   SetIndexDrawBegin(0,MA1Shift+MA1Period);
   SetIndexDrawBegin(1,MA2Shift+MA2Period);
   SetIndexDrawBegin(2,MA3Shift+MA3Period);
   SetIndexDrawBegin(3,MA4Shift+MA4Period);
   SetIndexDrawBegin(4,MA5Shift+MA5Period);
//---- 5 indicator buffers mapping
   SetIndexBuffer(0,ExtMA1Buffer);
   SetIndexBuffer(1,ExtMA2Buffer);
   SetIndexBuffer(2,ExtMA3Buffer);
   SetIndexBuffer(3,ExtMA4Buffer);
   SetIndexBuffer(4,ExtMA5Buffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,EMPTY,2);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2);
   SetIndexStyle(2,DRAW_LINE,EMPTY,2);
   SetIndexStyle(3,DRAW_LINE,EMPTY,2);
   SetIndexStyle(4,DRAW_LINE,EMPTY,2);
//---- index labels
   SetIndexLabel(0,"MA1");
   SetIndexLabel(1,"MA2");
   SetIndexLabel(2,"MA3");
   SetIndexLabel(3,"MA4");
   SetIndexLabel(4,"MA5");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| MA Calculation                                         |
//+------------------------------------------------------------------+
int start()
  {
   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++)
     {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      ExtMA1Buffer[i]=iMA(NULL,0,MA1Period,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMA2Buffer[i]=iMA(NULL,0,MA2Period,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMA3Buffer[i]=iMA(NULL,0,MA3Period,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMA4Buffer[i]=iMA(NULL,0,MA4Period,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMA5Buffer[i]=iMA(NULL,0,MA5Period,0,MODE_EMA,PRICE_CLOSE,i);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

