Discussion of article "Implementing indicator calculations into an Expert Advisor code" - page 4

 
Aleksey Vyazmikin #:
I didn't understand from the article, does the class-indicator have protection against missing bars? For example, there was a connection break for 5 bars, and then the history was loaded, will the class-indicator refill only the last value in the buffer or make a full recalculation?

If you look in the standard indicator class, it uses the CopyBuffer function when updating data. I.e. it fills the whole buffer from the terminal history, not some part of it.

bool CIndicatorBuffer::Refresh(const int handle,const int num)
  {
//--- check
   if(handle==INVALID_HANDLE)
     {
      SetUserError(ERR_USER_INVALID_HANDLE);
      return(false);
     }
//---
   m_data_total=CopyBuffer(handle,num,-m_offset,m_size,m_data);
//---
   return(m_data_total>0);
  }
 
Dmitriy Gizlyk #:

If you look in the standard indicator class, it uses the CopyBuffer function when updating data. I.e. it fills the whole buffer from the terminal history, not some part of it.

And recalculation of the whole history at each new bar?

Isn't it too costly then? Why not determine the date of the last calculation and copy the data for this particular piece of time?

 
Aleksey Vyazmikin #:

And recalculating the whole story on every new bar?

Isn't that too costly then? Why not determine the date of the last calculation and copy the data for this particular slice of time?

I apologise, the previous post was not about the article, but about the standard library.
In the article, the indicator is calculated in the Calculate method. Here we first determine the number of bars from the last recalculation and only then recalculate the remaining part.

  • cur_date - current time;
  • m_last_calculate - time of the last recalculation.

bool CMA::Calculate(void)
  {
   datetime cur_date=(datetime)SeriesInfoInteger(m_Symbol,m_Timeframe,SERIES_LASTBAR_DATE);
   if(m_last_calculate==cur_date && ArraySize(m_source_data)==m_history_len)
      return true;
//---
   if(!LoadHistory())
      return false;
//---
   int shift=Bars(m_Symbol,m_Timeframe,m_last_calculate,cur_date)-1;
 
Dmitriy Gizlyk #:

I apologise, the previous post was not about the article, but about the standard library.
In the article, the indicator is calculated in the Calculate method. Here we first determine the number of bars from the last recalculation and only then recalculate the remaining part.

  • cur_date - current time;
  • m_last_calculate - time of the last recalculation.

Thanks for the clarification!

 

thanks alot 

Very nice concept , but if I want to write a price action indicator with multiple prices (high,low,close,open)which calculates indicator value based on i.e difference of high and low there is a problem of having only one array of data (m_source_data  in CIndicator class),is there a way to work around this or do you suggest to modify the CIndicator class and make the m_source_data an array of (mqlRates or CArrayBuffer ,...)?

 
Mehrdad Sarrafi #:

thanks alot 

Very nice concept , but if I want to write a price action indicator with multiple prices (high,low,close,open)which calculates indicator value based on i.e difference of high and low there is a problem of having only one array of data (m_source_data  in CIndicator class),is there a way to work around this or do you suggest to modify the CIndicator class and make the m_source_data an array of (mqlRates or CArrayBuffer ,...)?

Yes, you can modify CIndicator to create m_source_data as array of MqlRates. I recommend MqlRates because other ways you will need some actions to synchronize data in different arrays.