prev_calculated logic in Expert Advisors?

 

I am trying to convert an indicator that is too complex to be called by iCustom into an expert advisor. When I say too complicated, I mean that we would need to copy hundreds of indicator buffers. So Instead I am porting the indicator code directly to the EA code. Most of it is straightforward, but I am not sure how to deal with prev_calculated.

In indicators, we typically check the value of prev_calculated to decide for how many bars we need to calculate the value of the indicator. My idea is to implement a similar approach in my EA OnTick function: set a global or a static int variable called to 0.  Check how many bars are available in the history, perform calculations until all bars have been used, and set rates_total to the number of available bars OnTick function. In the next calls of OnTick, we compare rates_total with the new number of bars available and decide if calculations need to be made. I am not sure though that this approach will work. In particular, sometimes in the indicators, prev_calculated is set to 0 during execution. Such a behaviour would not be captured by my approach. But do we expect a similar behaviour in an EA ?

Can anyone please comment?