#property indicator_chart_window
#property indicator_buffers 22
#property indicator_color1   Green
#property indicator_color2   Green
#property indicator_color3   Green
#property indicator_color4   Green
#property indicator_color5   Green
#property indicator_color6   Green
#property indicator_color7   Green
#property indicator_color8   Green
#property indicator_color9   Green
#property indicator_color10  Green
#property indicator_color11  Green
#property indicator_color12  Green
#property indicator_color13  Green
#property indicator_color14  Green
#property indicator_color15   Green
#property indicator_color16   Green
#property indicator_color17  Green
#property indicator_color18  Green
#property indicator_color19  Green
#property indicator_color20  Green
#property indicator_color21  Green
#property indicator_color22  Green

//---- input parameters
input int p1=270; 
input int s1=0;   
input int p2=280; 
input int s2=0;  
input int p3=290;  
input int s3=0;
input int p4=300; 
input int s4=0;   
input int p5=310; 
input int s5=0;  
input int p6=320;  
input int s6=0;
input int p7=330; 
input int s7=0;   
input int p8=340; 
input int s8=0;  
input int p9=350;  
input int s9=0;
input int p10=360; 
input int s10=0;   
input int p11=370; 
input int s11=0;  
input int p12=380;  
input int s12=0;
input int p13=390; 
input int s13=0;  
input int p14=400;  
input int s14=0;
input int p15=410; 
input int s15=0;   
input int p16=420; 
input int s16=0;  
input int p17=430;  
input int s17=0;
input int p18=440;  
input int s18=0;
input int p19=450; 
input int s19=0;   
input int p20=460; 
input int s20=0;  
input int p21=470;  
input int s21=0;
input int p22=480;  
input int s22=0;

   
//---- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
double Buffer9[];
double Buffer10[];
double Buffer11[];
double Buffer12[];
double Buffer13[];
double Buffer14[];
double Buffer15[];
double Buffer16[];
double Buffer17[];
double Buffer18[];
double Buffer19[];
double Buffer20[];
double Buffer21[];
double Buffer22[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   IndicatorDigits(Digits);
//---- line shifts when drawing
   SetIndexShift(0 ,s1);
   SetIndexShift(1 ,s2);
   SetIndexShift(2 ,s3);
   SetIndexShift(3 ,s4);
   SetIndexShift(4 ,s5);
   SetIndexShift(5 ,s6);
   SetIndexShift(6 ,s7);
   SetIndexShift(7 ,s8);
   SetIndexShift(8 ,s9);
   SetIndexShift(9 ,s10);
   SetIndexShift(10,s11);
   SetIndexShift(11,s12);
   SetIndexShift(12,s13);
   SetIndexShift(13,s14);
   SetIndexShift(14,s15);
   SetIndexShift(15,s16);
   SetIndexShift(16,s17);
   SetIndexShift(17,s18);
   SetIndexShift(18,s19);
   SetIndexShift(19,s20);
   SetIndexShift(20,s21);
   SetIndexShift(21,s22);
//---- first positions skipped when drawing
   SetIndexDrawBegin(0, s1+p1);
   SetIndexDrawBegin(1, s2+p2);
   SetIndexDrawBegin(2, s3+p3);
   SetIndexDrawBegin(3, s4+p4);
   SetIndexDrawBegin(4, s5+p5);
   SetIndexDrawBegin(5 ,s6+p6);
   SetIndexDrawBegin(6, s7+p7);
   SetIndexDrawBegin(7, s8+p8);
   SetIndexDrawBegin(8, s9+p9);
   SetIndexDrawBegin(9, s10+p10);
   SetIndexDrawBegin(10,s11+p11);
   SetIndexDrawBegin(11,s12+p12);
   SetIndexDrawBegin(12,s13+p13);
   SetIndexDrawBegin(13,s14+p14);
   SetIndexDrawBegin(14,s15+p15);
   SetIndexDrawBegin(15,s16+p16);
   SetIndexDrawBegin(16,s17+p17);
   SetIndexDrawBegin(17,s18+p18);
   SetIndexDrawBegin(18,s19+p19);
   SetIndexDrawBegin(16,s20+p20);
   SetIndexDrawBegin(17,s21+p21);
   SetIndexDrawBegin(18,s22+p22);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0, Buffer1);
   SetIndexBuffer(1, Buffer2);
   SetIndexBuffer(2, Buffer3);
   SetIndexBuffer(3, Buffer4);
   SetIndexBuffer(4, Buffer5);
   SetIndexBuffer(5, Buffer6);
   SetIndexBuffer(6, Buffer7);
   SetIndexBuffer(7, Buffer8);
   SetIndexBuffer(8, Buffer9);
   SetIndexBuffer(9, Buffer10);
   SetIndexBuffer(10,Buffer11);
   SetIndexBuffer(11,Buffer12);
   SetIndexBuffer(12,Buffer13);
   SetIndexBuffer(13,Buffer14);
   SetIndexBuffer(14,Buffer15);
   SetIndexBuffer(15,Buffer16);
   SetIndexBuffer(16,Buffer17);
   SetIndexBuffer(17,Buffer18);
   SetIndexBuffer(18,Buffer19);
   SetIndexBuffer(19,Buffer20);
   SetIndexBuffer(20,Buffer21);
   SetIndexBuffer(21,Buffer22);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexStyle(8,DRAW_LINE);
   SetIndexStyle(9,DRAW_LINE);
   SetIndexStyle(10,DRAW_LINE);
   SetIndexStyle(11,DRAW_LINE);
   SetIndexStyle(12,DRAW_LINE);
   SetIndexStyle(13,DRAW_LINE);
   SetIndexStyle(14,DRAW_LINE);
   SetIndexStyle(15,DRAW_LINE);
   SetIndexStyle(16,DRAW_LINE);
   SetIndexStyle(17,DRAW_LINE);
   SetIndexStyle(18,DRAW_LINE);
   SetIndexStyle(19,DRAW_LINE);
   SetIndexStyle(20,DRAW_LINE);
   SetIndexStyle(21,DRAW_LINE);
//---- index labels
   SetIndexLabel(0,"MA 270");
   SetIndexLabel(1,"MA 280");
   SetIndexLabel(2,"MA 290");
   SetIndexLabel(3,"MA 300");
   SetIndexLabel(4,"MA 310");
   SetIndexLabel(5,"MA 320");
   SetIndexLabel(6,"MA 330");
   SetIndexLabel(7,"MA 340");
   SetIndexLabel(8,"MA 350");
   SetIndexLabel(9,"MA 360");
   SetIndexLabel(10,"MA 370");
   SetIndexLabel(11,"MA 380");
   SetIndexLabel(12,"MA 390");
   SetIndexLabel(13,"MA 400");
   SetIndexLabel(14,"MA 410");
   SetIndexLabel(15,"MA 420");
   SetIndexLabel(16,"MA 430");
   SetIndexLabel(17,"MA 440");
   SetIndexLabel(18,"MA 450");
   SetIndexLabel(19,"MA 460");
   SetIndexLabel(20,"MA 470");
   SetIndexLabel(21,"MA 480");
  }
//+------------------------------------------------------------------+
//| Bill Williams' Alligator                                         |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int limit=rates_total-prev_calculated;
//---- main loop
   for(int i=0; i<limit; i++)
     {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      Buffer1[i]    =iMA(NULL,0,p1 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer2[i]    =iMA(NULL,0,p2 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer3[i]    =iMA(NULL,0,p3 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer4[i]    =iMA(NULL,0,p4 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer5[i]    =iMA(NULL,0,p5 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer6[i]    =iMA(NULL,0,p6 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer7[i]    =iMA(NULL,0,p7 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer8[i]    =iMA(NULL,0,p8 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer9[i]    =iMA(NULL,0,p9 ,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer10[i]   =iMA(NULL,0,p10,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer11[i]   =iMA(NULL,0,p11,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer12[i]   =iMA(NULL,0,p12,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer13[i]   =iMA(NULL,0,p13,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer14[i]   =iMA(NULL,0,p14,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer15[i]   =iMA(NULL,0,p15,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer16[i]   =iMA(NULL,0,p16,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer17[i]   =iMA(NULL,0,p17,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer18[i]   =iMA(NULL,0,p18,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer19[i]   =iMA(NULL,0,p19,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer20[i]   =iMA(NULL,0,p20,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer21[i]   =iMA(NULL,0,p21,0,MODE_LWMA,PRICE_MEDIAN,i);
      Buffer22[i]   =iMA(NULL,0,p22,0,MODE_LWMA,PRICE_MEDIAN,i);
     }
//---- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
