Errors, bugs, questions - page 1802

 
Alexey Kozitsyn:
Are you suggesting to do this on every tick?
I support synchronisation on every trigger of OnBookEvent() :(
 
prostotrader:
I support synchronisation at every trigger of OnBookEvent() :(
No questions here, the question is that in addition to this, it's suggested to call CopyRates().... every time. This seems to me to be some kind of a tantrum...
 
Alexey Kozitsyn:
There's no question, the question is that in addition to this, it's suggested to call CopyRates().... every time. This seems to me to be a tantrum...

:)

void OnBookEvent(const string &symbol)
{
  if(symbol == Symbol())
  {
    GetBars(Symbol(), time_frame);
  }  
}

This is how I was taught in SD

 
prostotrader:

:)

void OnBookEvent(const string &symbol)
{
  if(symbol == Symbol())
  {
    GetBars(Symbol(), time_frame);
  }  
}

If you want to say or show something, please show it properly... I don't want to guess what function you have here and what it does.

Added:

Did you teach me? And you didn't give an implementation?

 
Alexey Kozitsyn:

If you want to say or show something, please show it properly... I don't want to guess what function you have here and what it does.

Added:

Did you teach me? And you didn't give an implementation?

What is normal?

They said that in two minutes the data is unloaded and to maintain synchronization

they told me to call Bars.

//+------------------------------------------------------------------+
//| Custom indicator Get bars function                               |
//+------------------------------------------------------------------+
int GetBars(string symbol, ENUM_TIMEFRAMES period)
{
  if(!IsStopped())
  {
    if(SymbolIsSynchronized(symbol))
    {
      if(bool(SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED)))
      {
        int a_bars = Bars(symbol, period);  
        if(a_bars > 0)
        {
          return(a_bars);
        }
        else
        {
          return(GetLocalData(symbol, period));
        }  
      }
      else
      {
        return(GetLocalData(symbol, period));
      }    
    }  
    else
    {
      return(LoadServerData(symbol, period));
    }  
  }  
  return(0);
}
I'll look for the full implementation.
 

Here is

//+------------------------------------------------------------------+
// Custom indicator Check timer function                             |
//+------------------------------------------------------------------+
bool CheckTimer(const ulong start_value, const ulong per_value)
{
  ulong end_value = GetMicrosecondCount();
  if(end_value < start_value)
  {
    if((start_value - end_value) >= per_value) return(true);
  }
  else
  {
    if((end_value - start_value) >= per_value) return(true);
  }
  return(false);
}
//+------------------------------------------------------------------+
//| Custom indicator Get local data function                         |
//+------------------------------------------------------------------+
int GetLocalData(const string a_symbol, ENUM_TIMEFRAMES a_period)
{
  long first_date;
  int fail_cnt = 0;
  while((fail_cnt < 3) && !IsStopped())
  {
    first_date = long( SeriesInfoInteger(a_symbol, PERIOD_M1, SERIES_TERMINAL_FIRSTDATE));
    if(first_date > 0)
    {
      int f_cnt = 0;
      datetime times[1];
      long a_bars = 0;
      while((f_cnt < 5) && !IsStopped())
      {
        if(bool(SeriesInfoInteger(a_symbol, PERIOD_M1, SERIES_BARS_COUNT, a_bars)))
        {
          if ( a_bars > 0 )
          {
            if( bool(SeriesInfoInteger(a_symbol, a_period, SERIES_BARS_COUNT, a_bars)))
              if(a_bars > 0) return(int(a_bars));
          }
        }
        else
        {
//--- force timeseries build
          CopyTime(a_symbol, a_period, 0, 1, times);
          ulong start_tick = GetMicrosecondCount();
          while(!CheckTimer(start_tick, 5000))
          {
            f_cnt--;
            f_cnt++;
          }  
        }
        f_cnt++;
      }
    }
    else
    {
      ulong start_tick = GetMicrosecondCount();
      while(!CheckTimer(start_tick, 5000))
      {
        fail_cnt--;
        fail_cnt++;
      }
    }
//---  
    fail_cnt++;
  }
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator Get server data function                        |
//+------------------------------------------------------------------+
int LoadServerData(const string a_symbol, ENUM_TIMEFRAMES period)
{
  int fail_cnt = 0;
  while((fail_cnt < 5) && !IsStopped())
  {  
    long first_date = long(SeriesInfoInteger(a_symbol, PERIOD_M1, SERIES_SERVER_FIRSTDATE));
    if(first_date > 0)
    {
      if(SymbolIsSynchronized(a_symbol))
      {
        return(GetLocalData(a_symbol, period));
      }  
    }
    else
    {
      ulong start_tick = GetMicrosecondCount();
      while(!CheckTimer(start_tick, 20000))
      {
        fail_cnt--;
        fail_cnt++;
      }
    }    
    fail_cnt++;
  }
  return(0);  
}
//+------------------------------------------------------------------+
//| Custom indicator Get bars function                               |
//+------------------------------------------------------------------+
int GetBars(string symbol, ENUM_TIMEFRAMES period)
{
  if(!IsStopped())
  {
    if(SymbolIsSynchronized(symbol))
    {
      if(bool(SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED)))
      {
        int a_bars = Bars(symbol, period);  
        if(a_bars > 0)
        {
          return(a_bars);
        }
        else
        {
          return(GetLocalData(symbol, period));
        }  
      }
      else
      {
        return(GetLocalData(symbol, period));
      }    
    }  
    else
    {
      return(LoadServerData(symbol, period));
    }  
  }  
  return(0);
}


By calling GetBars, we are backing up synchronisation or trying to retrieve data

 
prostotrader:

What is normal?

They said that after two minutes the data is unloaded and to keep it in sync

they said to call Bars.

//+------------------------------------------------------------------+
//| Custom indicator Get bars function                               |
//+------------------------------------------------------------------+
int GetBars(string symbol, ENUM_TIMEFRAMES period)
{
  if(!IsStopped())
  {
    if(SymbolIsSynchronized(symbol))
    {
      if(bool(SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED)))
      {
        int a_bars = Bars(symbol, period);  
        if(a_bars > 0)
        {
          return(a_bars);
        }
        else
        {
          return(GetLocalData(symbol, period));
        }  
      }
      else
      {
        return(GetLocalData(symbol, period));
      }    
    }  
    else
    {
      return(LoadServerData(symbol, period));
    }  
  }  
  return(0);
}

Aren't these the analogues:

if(SymbolIsSynchronized(symbol))
if(bool(SeriesInfoInteger(symbol, period, SERIES_SYNCHRONIZED)))

Yes, it seemed to me that Bars() returns 0 if there is no synchronisation... I'll have to do a test...

 
Alexey Kozitsyn:
Are you suggesting that you do this on every tick?
Why? A single action is enough.

As long as the symbol is selected in the market overview and the history for the symbol is held by the Expert Advisor, then it is kept in sync. Holding by the Expert Advisor means that you need to access this history at least once every 2 minutes, for example by copying one bar. If the history is synchronized, no time is spent on copying one bar - only a few processor cycles. Or, as it was just said here, ask for the number of bars, also a few clock cycles
 
Slawa:
Why? A single action is enough.

As long as the symbol is selected in the market review and the history on the symbol is held by the Expert Advisor, it is kept in sync. Expert Advisor holding means that you need to access this history at least once every 2 minutes, for example by copying one bar. If the history is synchronized, then no time is spent on copying one bar - only a few processor clocks.

Do the indicators include an interval of 2 minutes?

Yes, and by checking the fact of synchronisation will the synchronisation also be held?

 
Alexey Kozitsyn:

Do the indicators include an interval of 2 minutes?

Yes, will the synchronisation check also hold the synchronisation?

It also applies to indicators. Create a 1-minute timer and ask the number of bars of all timeseries you are interested in.

Synchronization is not held by checking the fact of synchronization.
Reason: