



int get_vozrast(int initial_shift, int Body, int iflag)
{
   // расчет октавы по времени
   //
   double initial_gradus = get_astro_gradus(initial_shift, Body, iflag);
   //
   
   check_friday(initial_shift);
   
   int shift = initial_shift;
   double past_gradus = initial_gradus;
   double vozrast = 0;
   double add_360 = 0.0;
   double dt_count = 0;
   double current_gradus;
   
   while(vozrast < 359.99)
   {
     shift = shift - 1;
     if(is_trading_time(shift) == true) dt_count = dt_count + 1; // dt_count increase
     current_gradus = get_astro_gradus(shift, Body, iflag);
     if(current_gradus < past_gradus) add_360 = add_360 + 1.0;
     vozrast = current_gradus + add_360*360.0 - initial_gradus;
     past_gradus = current_gradus;
   }
   //Print(shift);
   return(dt_count);
}
void check_friday(int& shift)
{
   if((Period() < PERIOD_D1)&&(TimeDayOfWeek(get_datetime(shift)) == 5))
   {
     while((TimeDayOfWeek(get_datetime(shift)) == 5)||(TimeDayOfWeek(get_datetime(shift)) == 6)||(TimeDayOfWeek(get_datetime(shift)) == 0))
     {
       shift = shift - 1;
     }
   }
}
bool is_trading_time(int shift)
{
   if(Period() >= PERIOD_D1) return(true);
   datetime d;
   d = get_datetime(shift);
   if((TimeDayOfWeek(d) == 0)||(TimeDayOfWeek(d) == 6)) return(false);
   if((TimeDayOfWeek(d) == 5)&&(TimeHour(d) > 22)) return(false);
   return(true);
}
datetime get_datetime(int shift)
{
   datetime d;
   if(shift >= 0)
   {
     d = Time[shift];
   }
   else
   {
     d = Time[0] + MathAbs(shift)*Period()*60;
   }
   return(d);
}


