Incremental Bollinger bands calculation ... - page 2

 

Sorry, but this I completely do not understand.

The normal variance is calculated by looking back n bars. The incremental calculation like the ema looks back only 1 bar. So even the eq. 24,25 support exactly this idea looking back only at the previous bar - that is the advantage especially for greater n!

Beside that in mt4 it can lead to errors if you calculate with e.g. ..[i-4].

Please as it seems that you have an alternative idea how it has to be coded and my code-version is not satisfying can you code your idea?

 
Carl Schreiber:Sorry, but this I completely do not understand.

The normal variance is calculated by looking back n bars. The incremental calculation like the ema looks back only 1 bar. So even the eq. 24,25 support exactly this idea looking back only at the previous bar - that is the advantage especially for greater n!

Beside that in mt4 it can lead to errors if you calculate with e.g. ..[i-4]. Please as it seems that you have an alternative idea how it has to be coded and my code-version is not satisfying can you code your idea?

Please remember that the paper in question was not written with "Indicators" in mind. It has more of a "signal processing" or "data processing" idea behind it. As far as the "incremental simple mean and variance", there is no real advantage to using it in an Indicator, except with regards to lowering the "rounding error" when compared the the usual "sum of squares" method which is used by MetaQuotes.

The "incremental" or "cumulative" nature is useful for data processing, because one can run various parallel calculations on incoming "on-line" data in order to achieve a much faster calculation. For example, if one were to calculate the Simple Mean and Variance for a window of 16 samples (n = 16), you could run 16 parallel calculations where each one is shifted by one sample. In this way, at any one sample position, one of those parallel calculations would hold the mean and variance for that sample. The method described is also useful, for when one knows how many samples will be processed before-hand, but wishes to calculate the values as they arrive and not as an entire batch only at the very end.

The maths in the paper does however, serve as a basis for deriving other equations that could be adapted to use in Indicators. However, my main interest for the paper, is mostly to do with the "exponential" part, that is a special case and that can be used for Indicators because it can be used as a "moving average" and I am using it to derive equations for calculating variance for the Zero-Lag EMA and the Hull EMA (and others). Since, I currently have no interest in the "Simple Mean and Variance", I have not really dedicated much time or effort to deriving new equations based on that part.

 
Carl Schreiber: Sorry, but this I completely do not understand. The normal variance is calculated by looking back n bars. The incremental calculation like the ema looks back only 1 bar. So even the eq. 24,25 support exactly this idea looking back only at the previous bar - that is the advantage especially for greater n! Beside that in mt4 it can lead to errors if you calculate with e.g. ..[i-4]. Please as it seems that you have an alternative idea how it has to be coded and my code-version is not satisfying can you code your idea?

In a follow-up, I did some searching on the Internet for a variation of the SMA equations that were in the paper referenced on this thread, but adapted for "rolling" (i.e. Moving Average).

I found one at the following link: http://stackoverflow.com/questions/5147378/rolling-variance-algorithm

The answer for your specific request (SMA Variance), is the proposed, at the above link, by "DanS" (edited by "PhilL") and a subsequent improvement is proposed by "Jaime".

Hope that helps!

Rolling variance algorithm
Rolling variance algorithm
  • stackoverflow.com
I'm trying to find an efficient, numerically stable algorithm to calculate a rolling variance (for instance, a variance over a 20-period rolling window). I'm aware of the Welford algorithm that efficiently computes the running variance for a...
Reason: