Download MetaTrader 5

Discussion of article "MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window"

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
187155
MetaQuotes Software Corp.  

New article MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window has been published:

The ring buffer is the simplest and the most efficient way to arrange data when performing calculations in a sliding window. The article describes the algorithm and shows how it simplifies calculations in a sliding window and makes them more efficient.

At the start of the calculation, the indicator simply adds new values to the ring buffer of the moving average. You do not have to control the number of added values. All calculations and removals of obsolete elements occur automatically. If the indicator is called when changing the price of the last bar, the last moving average value should be replaced with a new one. The ChangeValue method is responsible for that.

The graphical display of the indicator is equivalent to the standard moving average:

Fig. 1. The simple moving average calculated in the ring buffer

Author: Vasiliy Sokolov

Savio Araujo
53
Savio Araujo  

Dear Vasiliy

First of all, thank you for this excellent article and its implementations with different indicators.

I would ask you whether it would be possible to post a sample of code for the section of calculating Highs/Lows with the ring buffer? I am finding difficult to get the right results when the market is running. It seems I loose the pointer when updating the changing prices with OnChangeValue() function.

Thanks in advance.

Vasiliy Sokolov
26424
Vasiliy Sokolov  
Savio Araujo:

Dear Vasiliy

First of all, thank you for this excellent article and its implementations with different indicators.

I would ask you whether it would be possible to post a sample of code for the section of calculating Highs/Lows with the ring buffer? I am finding difficult to get the right results when the market is running. It seems I loose the pointer when updating the changing prices with OnChangeValue() function.

Thanks in advance.


See this example: https://www.mql5.com/en/articles/3047#c6

Savio Araujo
53
Savio Araujo  
Vasiliy Sokolov:

See this example: https://www.mql5.com/en/articles/3047#c6


I have seen it. As I have checked the examples you provided. They show the same problem I had when dealing with updating the values while the market is running. Check the Stochastic you provided. Adding a new value is not a problem, but when we try to use Stoch.ChangeLast() or OnChangeValue() in CRiMaxMin class, it does not work. It does not change the value accordingly. If you could check it or send an example of a working code, that would be very nice.

Thank you.

To add comments, please log in or register