Libraries: The class to create the ring buffer

 

The class to create the ring buffer:

The class allows to organize the mini time series, indicator minibuffers, short sized buffers to store intermediate stream data inside the Expert Advisor or indicator.

Author: Konstantin Gruzdev

 

Can this class reduce the memory consumed by the indicator?

And what about the memory consumed by an Expert Advisor using several such indicators?

Or was the task set differently - just to provide convenient access to streaming data?

 
komposter:

Can this class reduce the memory consumed by the indicator?

And the memory consumed by an Expert Advisor using several such indicators?

Or was the task set differently - just to provide convenient access to streaming data?

Of course it will. The class was written precisely to reduce memory. In all buffers, including buffers for intermediate data, only the size of the last data specified by the user is stored in memory.

They should publish examples.

 
Lizar:

Must publish examples.

Examples

At the moment of publication there are three examples of using the ring buffer:

Class for building Moving Average
Class for building Average True Range
Class for building Average Directional Movement Index.

There are already examples, only 2 and 3 links are broken.
 
fyords:
There are already examples, only the 2nd and 3rd links are broken.
These examples have not been published yet. They are still being checked. The links will work when they are published.
 

A little analogy for better understanding:

  • the ring buffer in this implementation is an analogue of a time series, i.e. the most recent data has index 0, the oldest "buffer size"-1
  • the ring buffer size is an analogue of TERMINAL_MAXBARS, but unlike TERMINAL_MAXBARS, the buffer size is set by the user during initialisation and can be changed during use, while keeping the most recent data.
  • Just as with TERMINAL_MAXBARS, data beyond the buffer size is not available, but all recent data within the buffer size is available.
  • indicator data can be stored in the ring buffer as in the indicator buffer, but to display it on the chart you need to copy the data to the indicator buffer.
  • If the indicator data do not need to be displayed, they do not need to be copied to the indicator buffers, but used for their calculations directly from the ring buffer (see examples), which significantly saves memory and time when recalculating the indicator.

 
Lizar:
  • indicator data can be stored in the ring buffer as in the indicator buff er, but in order to display them on the chart you need to copy the data to the indicator buffer.
  • If the indicator data do not need to be displayed, they do not need to be copied to the indicator buffers, but used for their calculations directly from the ring buffer (see examples), which significantly saves memory and time when recalculating the indicator.

This is what I was asking about.

How can you save memory if you still need a full-fledged indicator buffer?

It turns out that you can save memory only if you transfer intermediate calculations to the ring buffer, and this does not solve all problems.

What I want is that an indicator with 20 displayed buffers, calculating the last 1000 bars, occupies the same amount of memory when "Max. bars in window" = 1000 and when "Max. bars in window" = 9999999999.

And this is apparently impossible =(

 
But thanks anyway for your public labour.
 
komposter:

That's what I was asking.

How do you save memory if you still need a full-fledged indicator buffer?

It turns out that you can save memory only if you transfer intermediate calculations to the ring buffer, and this does not solve all the problems.

What I want is that an indicator with 20 displayed buffers, calculating the last 1000 bars, occupies the same amount of memory when "Max. bars in window" = 1000 and when "Max. bars in window" = 9999999999.

And this is apparently impossible =(

Yes, it is possible to save only on those data that do not need to be stored in the indicator buffer.

There are a couple of ideas how you can sometimes reduce memory consumption in this case too.

Indicator buffers are needed in two cases: when you need to see a picture on the chart and when you need to get data from indicator buffers in other indicators or Expert Advisor. For example, in the tester (not in the visualisation mode) you can use the ring buffer instead of the indicator buffer, if it was used only for visualisation, and in the normal mode the usual indicator buffer. This will allow you to save memory during optimisation. I even managed to increase the speed of optimisation. Similarly with data transfer from indicator buffers, you can try to use other ways of getting data from the indicator and then you can use ring buffers instead of indicator buffers.

 
Lizar:

Yes, it is possible to save only on data that does not need to be stored in the indicator buffer.

There are a couple of ideas how you can sometimes reduce memory consumption in this case too.

Indicator buffers are needed in two cases: when you need to see a picture on the chart and when you need to get data from indicator buffers in other indicators or Expert Advisor. For example, in the tester (not in the visualisation mode) you can use the ring buffer instead of the indicator buffer, if it was used only for visualisation, and in the normal mode the usual indicator buffer. This will allow you to save memory during optimisation. I even managed to increase the speed of optimisation. Similarly with transferring data from indicator buffers, you can try to use other ways of getting data from the indicator and then you can use ring buffers instead of indicator buffers.

It's a pity, of course, I had already got excited.

Thanks anyway.

I will wait for a normal solution from the developers.

 
komposter:

It's a shame, of course, I was already excited.

Thanks anyway.

I will wait for a normal solution from the developers.

Ok.