due to a paper linked here by Fernando (thanks!) I tried to use this by indicators. First I wanted to compare it to the original - to check whether it is correct or weird.
First I compare the 'selfmade' BB (Tomato, sma dotted) against the original BB from the terminal (Magenta, solid) - as you can see (Comment err=0.0) no difference!
Then I calculated the incremental BB acc. to equation 24, 25:
which I realized as follows:
According to my understanding I assumed that the resulting bands (Lime-Green) should be close (not exactly the same of course!) to the original BB - but they are far away. Am I doing something wrong?
At last I coded the incremental BB (=incremental calculation of the variance) of the ema - which is close to the original BBs. It could be improved it you increase α by e.g. 3.0*α:
This now looks like:
As you can see the emaBB squeezes like the orgBB but it is more volatile due the the 'big' coeff1*α.
So this kind of BB - the incremental emaBB seem to be an alernative to the org BB which has to calculate at each tick Bandperiod times the squared difference - if this matters for someone.
But why is the incremental smaBB not working - anybody with an idea?
The attached code shows that I use for everything the same setup:
So any BB uses a multiplier of 2.0.
Carl, I had already posted for you a working version of EMA Bands here. Why don't you just look at the code and compare it to your rendition!
EDIT: PS! Also the "Incremental Simple Moving Variance" (equations 24 & 25) in the paper is not the variance for a "SMA". The type of Moving Average in the paper is better known by traders as the "Smoothed Moving Average". Using that for trying to make a standard "Bollinger" will not succeed. You would be creating a "Smoothed Moving Average Bollinger" and not that classical SMA Bollinger.
I know it can be confusing but mathematicians and traders sometimes call things by different names!
"Incremental Simple Moving Average" = "Cumulative Moving Average" = "SSMA - Smoothed Moving Average" (not "SMA - Simple Moving Average").
EDIT2: Actually I need to correct the previous edit, because the "Incremental Simple Moving Average" is not exactly the same as a "Smoothed" although the results are similar. It is as the other name implies "Cumulative". As it progresses, the period changes, increasing by 1 at every Bar. So on the first the period is "n=1" but by the last bar the period is equivalent to "n=Bars". It looks similar to the "Smoothed" when using a fixed period (n= constant) but technically they are different.
EDIT3: Scratch all of the above because I myself am mixing "Apples" and "Oranges", so lets start again.
The "Incremental Simple Moving Variance" (equations 24 & 25) in the paper is not the variance & standard deviation for a "SMA - Simple Moving Average". The equations in the paper for the "Incremental Simple Moving Standard Deviation" would require a variable period, starting at (n=1) for the first bar and up to (n=Bars) for the last bar. If you use a (n=constant), then the Standard Deviation will be continually growing as the calculation progresses, hence why you have such "wide" banding.
In essence you cannot use the equations in the paper for the classical Bollinger Bands. You can only use the other equations of Bollinger varaints with EMA (or SSMA) or LWMA, but not for SMA.
Also, the "SSMA - Smoothed Moving Average", is actually a variant of the EMA, so my previous scratched statements are incorrect. The weight for the SSMA is (1 / Period) while for an EMA it is (2 / ( Period + 1 ) ).
The formula S[n] for the emaBB is:
As I don't calculate the ema myself but take the one from the terminal - so I don't have to use the "latter form" but can use equation (143).
By the way it is the same as the latter form if you just do:
So I calculate in only two lines (s.a. and here without my added coeff):
So I think we do pretty much the same - no?
Concerning the sma-variance I read (right after equation 12 and as the first sentence of the next chapter "Incremental variance":
"Knuth notes  that equation 12 is prone to loss of precision because it takes the difference between twolarge sums of similar size, and suggests equation 24 as an alternative that avoids this problem."
So from the name of the chapter "Incremental variance" and that Knuth suggests a more precise method than equation 12 (which is used by the default BB) I assume that at the end in equation 24,25 I get a more precise variance than 12 provides - isn't that correct? But what I get is practically not usable!
"Knuth notes  that equation 12 is prone to loss of precision because it takes the difference between two large sums of similar size, and suggests equation 24 as an alternative that avoids this problem."
Since, I heavily edited my previous post and it took a while for it to settle, so please have a look at it again! It will explain why you are having those problems and why you can't use those equations for the Classical Bollinger Bands.
EDIT: PS! I can still use the equations 24 & 25 if you recalculate it only over the constant period window on every new bar as a less error prone alternative in substituting the one used by MetqQuotes (which is based on the sum of squares that is more prone to round errors).
I don't agree here: "... has a variable period, starting at (n=1) for the first bar and up to (n=Bars) for the last bar."
if you look at eq. 7:
you see our normal calculation of the variance with n as the common known BandsPeriod. There is no hint that the meaning of n has changed.
And as S[n] means the new, the most recent variance I do understand x[n] as the actual applied price (in my case Close[i]). Only this way eq. 25
makes sense divided by the number of element from which the sma was calculated.
Even more clearly is my interpretation if you look at eq. 47 of the weighted ma where he sums up the weights:
to use W[n] in the same way later:
For a simple sma with n periods all n "weigths" are equal 1 and their sum = n!
In the paper, it is clear that "n" is for the entire sample/data size and not for a rolling window. The variance calculation is cumulative. For the EMA, that problem does not exist because there is no explicit dependency on the "n" period, even though the value is also cumulative (keeping tracking from the very first bar). But for the "simple" one, you either have to known "n" before hand, or you have to make it sequential (and also make adjustments to the MA equation as well to compensate).
You can use equations 24 & 25 (and 4) in your indicator, but only if you recalculate over the constant
period window only on every new bar as a less error prone alternative in
substituting the one used by MetaQuotes (which is based on the sum of
squares that is more prone to rounding errors).
EDIT: I have to correct myself here again because I have been calling it "Incremental Simple Moving Average and Variance" which is incorrect. The correct name used by the paper is "Incremental Mean and Variance" which is more indicative of the "cumulative" effect and having no "moving window" in its calculations.
As I stated, use them only over the "window", not over the entire bar history.
For example, if your period is 5 bars, and you are currently evaluating bar [i], as a series (0 being the first bar), then run the equations only over the range [i-4] to [i] when n = 5.
Then when evaluating bar [i+1], run the equations over [i-3] to [i+1], etc.