Whats wrong with my code? it freezes the terminal

 

i am  trying to calculate where the period separator might appear on different timeframes ,

indicator itself works on h4 and below , but when i attach it to D1 , it just freezes my mt4 ,

altho the calculations arent correct at the moment which i can work on to make the calculation correct 

right now its giving me results a few candles before or after the actual time but i can work on it 

but the main issue is the freezing 

here is my code :


#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


int timefr ;  int bari;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   if(Period()<=60 )
     {
       int curday=TimeDay(TimeCurrent());
       
        for(int i=0;i<1500;i++)
          {
           datetime timee= TimeDay(Time[i]);    
           if(curday == timee)
             {
              
              
              bari= bari+1;
    
              
             }
             else
               {
                cari=bari;
                i=1566;
               }
          }
     }
   



   else if(Period()==240)
          {
          int curday=TimeDayOfWeek(TimeCurrent());
          bari=0;
             for(int i=0;i<=31;i++)
               {
                 datetime timee= TimeDayOfWeek(Time[i]);    
                 if(timee != 0)
                   {
                    bari= bari+1;
                    Print (bari);
                   }
                  else
                    {
                     i = 32;
                    }
               }
          }



   
    else if(Period()==1440)
          {
                  int curday=TimeMonth(TimeCurrent());
       bari=0;
       for(int i=0;i<31;i++)
         {
           datetime timee= TimeMonth(Time[i]);    
           if(timee == curday)
             {
              bari= bari+1;
             }
            else
              {
               i = 24;
              }
         }
          }  



   
      else if(Period()==10080)
          {
                  int curday=TimeYear(TimeCurrent());
         bari=0;
       for(int i=0;i<55;i++)
         {
           datetime timee= TimeYear(Time[i]);    
           if(timee ==curday)
             {
              bari= bari+1;
             }
            else
              {
               i = 56;
              }
         }
            }



 
    ObjectCreate(0,"zxc",OBJ_VLINE,0,Time[bari],0);
    ObjectSetInteger(0,"zxc",OBJPROP_COLOR,clrRed);
    ObjectSetInteger(0,"zxc",OBJPROP_STYLE,STYLE_SOLID);




//---
   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[])
  {


   return(rates_total);
  }
//+------------------------------------------------------------------+
 
       for(int i=0;i<31;i++)
         {
           datetime timee= TimeMonth(Time[i]);    
           if(timee == curday)
             {
              bari= bari+1;
             }
            else
              {
               i = 24;
              }

This creates an endless loop. To exit from a loop, use the command break.

 
lippmaje:

This creates an endless loop. To exit from a loop, use the command break.

thanks man this is probably the most goofiest mistake i have made ............i forgot to  change "i=24" to "i = 31"