SeriesInfoInteger returns 0 - page 2

 
Screenshot
Files:
sc.png  166 kb
 
log
Files:
20210426.log  2 kb
 
chinaski:

I did, long instead of int. Same problem. PrintFormat accepts %d for long also, according help. checked also %i %x.

Still returns 0.

Just as a simplified test, use the following in the OnCalculate (not tested or compiled, just written out):

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[])
{
   if( rates_total > 0 )
   {
      long bars = SeriesInfoInteger( _Symbol, PERIOD_CURRENT, SERIES_BARS_COUNT );
      Print( "Bars: ", (string) bars, "; Rates Total: ", (string) rates_total );
   }
   else
      Print( "Chart not yet initialised!" );

   return rates_total;
}
And then show Experts log of output
 
Fernando Carreiro:

Just as a simplified test, use the following in the OnCalculate (not tested or compiled, just written out):

And then show Experts log of output

This works

 

Questions.

1. Is this documented ?

2. Why keeps it failing. OnCalculate is called with each tick ?

Thank you

 
chinaski:

Questions.

1. Is this documented ?

2. Why keeps it failing. OnCalculate is called with each tick ?

1. What specifically do you mean by "Is this Documented"?

2. Mine worked, yours did not! Something is wrong in your code.

  1. Mistake using it in OnInit instead of OnCalculate
  2. Mistake using "int" instead of "long"
  3. Mistake not checking "rates_total" to see if chart is ready or not
Yes, OnCalculate should be called on each tick and on other occasions too when data needs to be reprocessed.
 
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


void get_data(void)
{
   ResetLastError();
   long bars=SeriesInfoInteger(_Symbol,PERIOD_CURRENT,SERIES_BARS_COUNT);
   PrintFormat("bars=%x code=%d",GetLastError());

   ResetLastError();
   MqlRates         rates_array[];
   int count_copied= CopyRates( _Symbol,PERIOD_CURRENT,0,100,rates_array);    
   PrintFormat("rates copied=%d code=%d",count_copied,GetLastError());
}

int OnInit()
{
    //get_data();
    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[])
  {
//---
   
   get_data();
   PrintFormat("rates total=%d",rates_total);
   /*
  if( rates_total > 0 )
   {
      long bars = SeriesInfoInteger( _Symbol, PERIOD_CURRENT, SERIES_BARS_COUNT );
      Print( "Bars: ", (string) bars, "; Rates Total: ", (string) rates_total );
   }
   else
      Print( "Chart not yet initialised!" );   
    */
   return(rates_total);
  }
  

Please have a look on the code above and on the log i attached. You can see a rates total > 0 and the call of

SeriesInfoInteger(_Symbol,PERIOD_CURRENT,SERIES_BARS_COUNT);

stil failing.

I thank you for your help but the use of SeriesInfoInteger is non intuitive here and behaves very unexpected. 

Files:
20210426.log  3 kb
 
Fernando Carreiro:

1. What specifically do you mean by "Is this Documented"?

2. Mine worked, yours did not! Something is wrong in your code.

  1. Mistake using it in OnInit instead of OnCalculate
  2. Mistake using "int" instead of "long"
  3. Mistake not checking "rates_total" to see if chart is ready or not
Yes, OnCalculate should be called on each tick and on other occasions too when data needs to be reprocessed.

No, i think, my code should work without making a big thread here. This is my opinion. Your code works, yes, thank you, but why this special coding needed at all ?

This is what i mean by documented.

 
chinaski: Please have a look on the code above and on the log i attached. You can see a rates total > 0 and the call of

stil failing.

I thank you for your help but the use of SeriesInfoInteger is non intuitive here and behaves very unexpected. 

Wrong:

PrintFormat("bars=%x code=%d",GetLastError());

Correct:

PrintFormat("bars=%lld code=%d",bars,GetLastError());


Also, why do you need that extra code when the data is already available to you within the OnCalculate?

It has "rates_total" which is the total number of bars (i.e.SERIES_BARS_COUNT).

It already has all the data for time[], open[], high[], low[], close[], tick_volume[], volume[], spread[] and there is no need to use CopyRates?

You are making your own programming difficult when the data it is already there and easily accessible.

EDIT: Yes it is all documented, but you are not following the documentation. That is why you are having this difficult time!

 
Fernando Carreiro:

Wrong:

Correct:


Also, why do you need that extra code when the data is already available to you within the OnCalculate?

It has "rates_total" which is the total number of bars (i.e.SERIES_BARS_COUNT).

It already has all the data for time[], open[], high[], low[], close[], tick_volume[], volume[], spread[] and there is no need to use CopyRates?

You are making your own programming difficult when the data it is already there and easily accessible.

EDIT: Yes it is all documented, but you are not following the documentation. That is why you are having this difficult time!

Sorry

PrintFormat("bars=%x code=%d",GetLastError());

Is a mistake by me. But you can see in my original code it is correct, even it uses int as i guess there is an implicit cast.

You say:

"Also, why do you need that extra code when the data is already available to you within the OnCalculate?

It has "rates_total" which is the total number of bars (i.e.SERIES_BARS_COUNT).

It already has all the data for time[], open[], high[], low[], close[], tick_volume[], volume[], spread[] and there is no need to use CopyRates?

You are making your own programming difficult when the data it is already there and easily accessible.

EDIT: Yes it is all documented, but you are not following the documentation. That is why you are having this difficult time!"


I think this is not the point. There is a function, promising a service and this function works not reliable in OnInit and in OnCalculate only with your code.

This takes time. 

I checked again the call in OnInit and it works now! Why that ?? Also with integer type.

Reason: