Индикатор не сразу начинает работать - страница 3

 

Модернизировал код, теперь с 3-4 раза грузится :)

//+------------------------------------------------------------------+
//| Custom indicator Check Load History function                     |
//+------------------------------------------------------------------+
bool CheckLoadHistory( string symbol, ENUM_TIMEFRAMES period, datetime start_date )
{
  if ( !SymbolInfoInteger( symbol, SYMBOL_SELECT ) )
  {
    if ( GetLastError() == ERR_MARKET_UNKNOWN_SYMBOL ) return( false );
    SymbolSelect( symbol,true );
  }
  
//---
  if ( MQL5InfoInteger( MQL5_PROGRAM_TYPE ) == PROGRAM_INDICATOR && Period() == period && Symbol() == symbol )
      return( false ); 
//---
  datetime first_date = 0;
  datetime times[1];
  int fail_cnt = 0;
//---
  while ( fail_cnt < 100  )
  {
    SeriesInfoInteger( symbol, PERIOD_M1, SERIES_TERMINAL_FIRSTDATE, first_date );
    
    if ( first_date > 0 )
    {
      CopyTime( symbol, period, first_date + PeriodSeconds( period ), 1, times );
//--- 
      if( SeriesInfoInteger( symbol,period, SERIES_FIRSTDATE, first_date ) )
      {
        if ( symbol == _Symbol )
        {
          if ( ( first_date > 0 ) && ( first_date <= start_date ) ) return( true );
        }
        else
        {
          if ( first_date > 0 ) return( true );
        }  
      }  
    }
    fail_cnt++;
    Sleep( 10 );
  }  
  if ( first_date == 0 ) Print( "Данных по символу ", symbol, " нет в терминале!"); //НА САМОМ ДЕЛЕ ЕСТЬ!
//---     
  int max_bars = TerminalInfoInteger( TERMINAL_MAXBARS );
//--- load symbol history info
   datetime first_server_date = 0;
   fail_cnt = 0;
   while( fail_cnt < 100 )
   {
     SeriesInfoInteger( symbol, PERIOD_M1, SERIES_SERVER_FIRSTDATE, first_server_date );
   
     if ( first_server_date > 0 ) 
     {
       return( true );
     }  
     fail_cnt++;
     Sleep( 10 );
   }  
  if ( first_server_date == 0 )
  {
    Print( "История по символу ", symbol, " не загружена!");
    return( false );
  }  
//--- wait for timeseries build
  while( !SeriesInfoInteger( symbol, period, SERIES_SYNCHRONIZED ) && !IsStopped() ) Sleep( 10 );
//--
  int bars = Bars( symbol, period );
//---  
  if ( bars > 0 )
  { 
    if ( bars >= max_bars ) return( false );
//--- ask for first date
    if ( SeriesInfoInteger( symbol, period, SERIES_FIRSTDATE, first_date ) )
    {
      if ( symbol == _Symbol )
      {
        if ( ( first_date > 0 ) && ( first_date <= start_date ) ) return( true );
      }
      else
      {
        if ( first_date > 0 ) return( true );
      }    
    }
  }
  else
  {
    Print( "Не получены данные по символу ", symbol );
  } 
  return( false ); 
}
Причина обращения: