Download MetaTrader 5

Correct usage of SERIES_SYNCRONIZED?

To add comments, please log in or register
Tony
262
Tony  

Hi

In trying to prevent a divide by zero error, I realised that the indicator was calculating before the data was loaded or updated. I think I need to return without calculation if the data is not ready. I saw someone else use SeriesInfoInteger( NULL, 0, SERIES_SYNCRONIZED ), but is this the correct (or good) usage? Any comments would be helpful.

Cheers

Jellybean

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 i;
   long Count;
   double PDayHigh, PDayLow;
   double Range;

   ArraySetAsSeries( time, true );
   ArraySetAsSeries( high, true );
   ArraySetAsSeries( low, true );
   ArraySetAsSeries( close, true );

   // Return if the data is not completely loaded *** is this the correct usage for SERIES_SYNCHRONIZED? ***
   if( !SeriesInfoInteger( NULL, 0, SERIES_SYNCRONIZED ) )     // if data is not synchronised
   {
      Print( __FILE__, __FUNCTION__ , "- Waiting for data synchronisation" );
      return( 0 );
   }

   i = rates_total - prev_calculated;
   if( i > rates_total - 2 )
      i = rates_total - 2;

   while( i >= 0 )
   {
      ...
      ...
      ...
      i--;
   } // while( i >= 0 )

   // return value of prev_calculated for next call
   return( rates_total );
}
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / History Database Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / History Database Properties - Documentation on MQL5
Tony
262
Tony  

Any ideas?

The help says what it is, but says nothing about what conditions exist for true or false. Does sychronised really mean that the data is all loaded without gaps?

ENUM_SERIES_INFO_INTEGER

Identifier

Description

Type

SERIES_BARS_COUNT

Bars count for the symbol-period for the current moment

long

SERIES_FIRSTDATE

The very first date for the symbol-period for the current moment

datetime

SERIES_SERVER_FIRSTDATE

The very first date in the history of the symbol on the server regardless of the timeframe

datetime

SERIES_TERMINAL_FIRSTDATE

The very first date in the history of the symbol in the client terminal, regardless of the timeframe

datetime

SERIES_SYNCRONIZED

Symbol/period data synchronization flag for the current moment

bool


Jellybean


Slava
Moderator
6936
Slava  
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Timeseries and Indicators Access / Organizing Data Access - Documentation on MQL5
Tony
262
Tony  

Thank you Stringo

All is clear now.

Jellybean
To add comments, please log in or register