Time Frame error in the indicator

 

Hello everyone, I created a simple indicator that reads 2 time frame and according to the trend puts a red or green dots. But sometimes it happens that the dots are 3 instead of 2

this is my code:

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 Red
#property indicator_label1 "15sell"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 Lime
#property indicator_label2 "15buy"

#property indicator_type3 DRAW_ARROW
#property indicator_width3 1
#property indicator_color3 Red
#property indicator_label3 "30sell"

#property indicator_type4 DRAW_ARROW
#property indicator_width4 1
#property indicator_color4 Lime
#property indicator_label4 "30buy"

//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];


extern double TF15 = 5;
extern double TF30 = 5.5;
datetime time_alert; 

double myPoint; //initialized in OnInit

//--- Custom functions ----------------------------------------------- 

double ExampleFunction()
{
   return(High[1] - Low[1]);
}

//--- End of custom functions ----------------------------------------

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Base4 @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | Base4 @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 159);
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, 0);
   SetIndexArrow(2, 159);
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, 0);
   SetIndexArrow(3, 159);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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 = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
      ArrayInitialize(Buffer3, 0);
      ArrayInitialize(Buffer4, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; 
      
      double Max1  = MathMax(High[1+i], Low[1+i]);
      double Min1  = MathMin(High[1+i], Low[1+i]);      
      
      double Max15 = MathMax(High[15+i],Low[15+i]);
      double Min15 = MathMin(High[15+i],Low[15+i]);
      
      double Max30 = MathMax(High[30+i],Low[30+i]);
      double Min30 = MathMin(High[30+i],Low[30+i]);   
      
      
       
      //Indicator Buffer 1 TF 15min
      if(Min1 < Max15
      )
        {
         Buffer1[1+i] = Low [1+i] - TF15 * myPoint; //Red
        }
      else      
        {
         Buffer2[1+i] = High[1+i] + TF15 * myPoint; //Lime
        }
        
      //Indicator Buffer 2 TF 35min
      if(Min1 < Max30
      )
        {
         Buffer3[1+i] = Low [1+i] - TF30 * myPoint; //Red
        }
      else      
        {
         Buffer4[1+i] = High[1+i] + TF30 * myPoint; //Lime
        }
      
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+