I want to copy only 2 years of data with CopyBuffer()

 

Hi all, I'm trying to copy only 2 years of history to my indicator buffer (I want to conduct some study on the 2 years of history of values)

My problem is that when I run below code and check size of copied array it returns over 100'000 of 1 hour bars which is probably almost entire available history. Do I need to copy it manually to another array if I only want to have 2 years of data to analyse?

input datetime inpFrom = D'2020.01.01';
input datetime inpTo   = D'2022.05.18';   

int OnInit()
{
   SetIndexBuffer(0, BufEMA, INDICATOR_DATA);

   ArraySetAsSeries(BufEMA, true);

   HandleEMA = iCustom( _Symbol, PERIOD_CURRENT, "MyIndicators\\EMA_S\\EMA_S.ex5" );

   if( HandleEMA == INVALID_HANDLE ) {
      PrintFormat( "Failed to create HandleEMA for the symbol %s/%s, error code %d",
                   _Symbol,
                   EnumToString( PERIOD_CURRENT ),
                   GetLastError() );
      return ( INIT_FAILED );
   }
   return(INIT_SUCCEEDED);
}


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
ResetLastError();

   if( CopyBuffer( HandleEMA, 0, inpTo, inpFrom, BufEMA) <= 0) {
      PrintFormat( "1.Failed to copy data from the EMA S indicator, error code %d", GetLastError() );
      return ( 0 );
   }

   Print( ArraySize( BufEMA)); // on EURSD 1H chart console says: 100403

return (prev_calculated);
}

I'm trying to use this function (by the way I don't think they made it clear what is the start and end date - which should be earliest and which latest - so I tried both ways with the same result).

int  CopyBuffer( 
   int       indicator_handle,     // indicator handle 
   int       buffer_num,           // indicator buffer number 
   datetime  start_time,           // start date and time 
   datetime  stop_time,            // end date and time 
   double    buffer[]              // target array to copy 
   );
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
  • www.mql5.com
This article is about traditional and unusual algorithms of averaging packed in simplest and single-type classes. They are intended for universal usage in almost all developments of indicators. I hope that the suggested classes will be a good alternative to 'bulky' calls of custom and technical indicators.