How to combine 2 moving averages? MQL4 programming

 
//+------------------------------------------------------------------+
//|                                                         dASD.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 6

input int MAPeriod1 = 5;
input int MAPeriod2 = 25;
input ENUM_MA_METHOD MAMethod = MODE_EMA;

double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];

#define Indicator1 0
#define Indicator2 1
#define Indicator3 2
#define Indicator4 3
#define Indicator5 4
#define Indicator6 5
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexStyle(Indicator1,DRAW_LINE,STYLE_SOLID,2,clrFireBrick);
   SetIndexBuffer(Indicator1,Buffer1);

   SetIndexStyle(Indicator2,DRAW_LINE,STYLE_SOLID,2,clrYellow);
   SetIndexBuffer(Indicator2,Buffer2);

   SetIndexStyle(Indicator3,DRAW_LINE,STYLE_SOLID,2,clrPink);
   SetIndexBuffer(Indicator3,Buffer3);

   SetIndexStyle(Indicator4,DRAW_LINE,STYLE_SOLID,2,clrPink);//felfele
   SetIndexBuffer(Indicator4,Buffer4);

   SetIndexStyle(Indicator5,DRAW_LINE,STYLE_SOLID,2,clrGreen);//lefele
   SetIndexBuffer(Indicator5,Buffer5);

   SetIndexStyle(Indicator6,DRAW_LINE,STYLE_SOLID,2,clrGreen);
   SetIndexBuffer(Indicator6,Buffer6);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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;
   double MA1,
          MA2;

   limit = rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;

   for(int i = limit-1; i>=0; i--)
     {

      MA1=iMA(Symbol(),Period(),MAPeriod1,0,MAMethod,PRICE_CLOSE,i);
      MA2=iMA(Symbol(),Period(),MAPeriod2,0,MAMethod,PRICE_CLOSE,i);

      double tomb[2];
      tomb[0]=MA1;
      tomb[1]=MA2;

      int maxindex = ArrayMaximum(tomb,WHOLE_ARRAY,0);
      double max = tomb[maxindex];

      if(max==MA2)
        {
         Buffer3[i]=MA2;
        }
      else
         if(max==MA1)
           {
            Buffer4[i]=MA1;
           }
      if(max==MA2)
        {
         Buffer5[i]=MA1;
        }
      else
         if(max==MA1)
           {
            Buffer6[i]=MA2;
           }

     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Hi i did this indicator for i want to use 2 or more MA and i want to draw the lower MA  but when the other MA cross this than the other MA will be the lowest so draw that ema  but in my program i have a pause in drawing :( what is the problem ?
Files:
Nnvtelen1.png  14 kb
Npvtelen.png  30 kb
Reason: