Number of values in custom stochastic indicator buffers not rendered correctly on chart

 

Hi all,

I have developed a stochastic indicator that has an UpdateBuffer function that receives parameters that allows it to update the Signal and Main buffers with appropriate values. On GU/M5, rates_total is set to 100,731 of which the first 731 records correspond to null datetime values. The remaining 100,000 records correspond with good datetime bar values. The main problem that I am experiencing is that whilst there are 100,000 correct values in the buffers, the indicator window is only showing circa 1024 records. I am working in MT5 for the first time (after using MT4 for a few years) so, I'm not exactly sure whether I have missed something obvious or whether I am simply missing the point! :) I have included the UpdateBuffer code and some screenshots that show the problem. If anyone could take a look and advise accordingly, that would be greatly appreciated.

Thanks.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool UpdateBuffer(
   int rates_total,
   int prev_calculated,
   CiStochastic &levelPtr,
   int levelHandle,
   int &levelBarsCalculated,
   ENUM_TIMEFRAMES levelTimeframe,
   double &mainBuffer[],
   double &signalBuffer[])
  {
   double lookbackCount = LookbackBars(_Period, levelTimeframe);
//---   
   levelPtr.Refresh(OBJ_ALL_PERIODS);

//--- number of values copied from the iStochastic indicator
   int valuesToCopy;
//--- determine the number of values calculated in the indicator
   int calculated=BarsCalculated(levelHandle);
//---
   if(calculated<=0)
     {
      PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
      return false;
     }
   if(prev_calculated==0 || calculated!=levelBarsCalculated || rates_total>prev_calculated+1)
     {
      if(calculated>rates_total)
         valuesToCopy=rates_total;
      else
         valuesToCopy=calculated;
     }
   else
     {
      //--- it means that it's not the first time of the indicator calculation, and since the last call of OnCalculate()
      //--- for calculation not more than one bar is added
      valuesToCopy=(rates_total-prev_calculated)+1;
     }

//--- memorize the number of values in the Stochastic Oscillator indicator
   levelBarsCalculated=calculated;
//---
   int limit = (int)MathMax(valuesToCopy, lookbackCount);

//--- TEMP CODE
        int countStrikes=0;
//---

   for(int i = limit; i >= 0; i--)
     {
      //---
      datetime currentTfTime = CUtils::GetTime(_Period, i);

      if(currentTfTime==NULL)
         continue;

      int targetTfShift = iBarShift(NULL, levelTimeframe, currentTfTime);
      datetime targetTfTime = CUtils::GetTime(levelTimeframe, targetTfShift);
      //---
      mainBuffer[i] = levelPtr.Main(targetTfShift);
      signalBuffer[i] = levelPtr.Signal(targetTfShift);

      //--- TEMP CODE
      countStrikes++;
      //---
     }
//---
        int mainSize=ArraySize(mainBuffer);
        int sigSize=ArraySize(signalBuffer);
        Print("countStrikes: ",countStrikes);
        Print("mainBuffer",mainSize);
        Print("signalBuffer",sigSize);

   return true;
  }


Screenshot debug window shows the values at the end of the function call.

Here is a screen shot of the 1024 bars-worth of stochastic values.


Cheers! :)

 

Have you checked whether the orientation of your buffers is the way you thing it is - meaning that the first bar (buffer[0]) is the very first or the actual bar or is it the last bar - this is different in mql5 compared to mql4.

Here is an explantation: https://www.mql5.com/en/docs/series/bufferdirection.

Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
  • www.mql5.com
The default indexing of all arrays and indicator buffers is left to right. The index of the first element is always equal to zero. Thus, the very first element of an array or indicator buffer with index 0 is by default on the extreme left position, while the last element is on the extreme right position. An indicator buffer is a dynamic array...
 
Carl Schreiber:

Have you checked whether the orientation of your buffers is the way you thing it is - meaning that the first bar (buffer[0]) is the very first or the actual bar or is it the last bar - this is different in mql5 compared to mql4.

Here is an explantation: https://www.mql5.com/en/docs/series/bufferdirection.

Hi Carl,

Thanks for your comments. Yes, the orientation is correct. I've added some more output code to show this, you'll see the index value getting smaller and the date value getting higher (more recent). Then, you can see index 2,1,0 getting new values as new data comes in on OnCalculate.


So, it looks OK in that respect. Any further thoughts?

Many thanks.

 
Resolved, thanks.
Reason: