CPU intensive indicator for use in EA

 
Hi. I have written a complex cpu intensive indicator that takes a relatively long time to run - perhaps 2 minutes for 100,000 bars. I would like to make this custom indicator available to an EA using iCustom and CopyBuffer. However, my understanding is that CopyBuffer will call my indicator and expect it to process all bars, irrespective of the start index and count passed to CopyBuffer. This would obviously take several minutes to complete.

So my question is how do I effectively and efficiently write a complex cpu intensive indicator for use in an EA?

Ideally I would like to pass a start index and bar count to CopyBuffer that can be accessed by the indicator, or make them available to this function some how.

Thank you.
 

100.000 bars? Don't calculate what you do not need.

CopyBuffer just copies the already calculated buffer. It will not trigger another calculation.

 

That’s my point! How do I ensure that when I call CopyBuffers it does not call my indicator to request it to process the entire history of bars. Perhaps I am misunderstanding something here. The documentation does not make it clear.

When I add my indicator to a chart, it processes just 800 bars at a time from the last visible bar going back in time, not the entire price history. This works well and there is virtually no lag. However, now I want to add this indicator to my EA using iCustom and CopyBuffers, but can’t find a way to control the number of bars that the indicator will process. CopyBuffers allows a start index and bar count, but this assumes that the entire data buffer has been filled.

Thanks

 
CopyBuffer() has nothing to do with the quantity of bar calculation.

CopyBuffer() is only a special version of ArrayCopy().

To avoid unnecessary bar calculations, you must make sure that the indicator calculation algorithm is correct.

You should focus on "rates_total" and "prev_calculated" in OnCalculate(), not CopyBuffer() in OnTick().

 
robnorthen:
Hi. I have written a complex cpu intensive indicator that takes a relatively long time to run - perhaps 2 minutes for 100,000 bars. I would like to make this custom indicator available to an EA using iCustom and CopyBuffer. However, my understanding is that CopyBuffer will call my indicator and expect it to process all bars, irrespective of the start index and count passed to CopyBuffer. This would obviously take several minutes to complete.

So my question is how do I effectively and efficiently write a complex cpu intensive indicator for use in an EA?

Ideally I would like to pass a start index and bar count to CopyBuffer that can be accessed by the indicator, or make them available to this function some how.

Thank you.

yes just set a maxbars parameter and set it to 1 when backtesting in an EA

 
Tools → Options (control-O) → Charts → change Max bars in chart to something reasonable like 1K.
Reason: