Hi Sir,

Please help me that how to Write a Bollinger Band formula using by EMA instead of MA ?

Thank you!

Grace

Hi Sir,

Please help me that how to Write a Bollinger Band formula using by EMA instead of MA ?

Thank you!

Grace

Bollinger Bands is just adding/subtracting standard deviation to/from some MA.

So nothing magically about it.

```
/// BBands using EMA instead of MA
/// @link https://forum.amibroker.com/t/how-to-write-a-bol-band-using-by-ema-instead-of-ma/11930/2
P = C;
period = 20;
width = 2;
myMa = EMA( P, period );
StdDev= width*Stdev( P, period );
bandTop = myMa + StdDev;
bandBot = myMa - StdDev;
Plot( C, "Price", colorDefault, styleBar );
Plot( myMa, "EMA", colorLime, styleDashed );
Plot( bandTop, "EMA BBTop", ColorRed, styleLine );
Plot( bandBot, "EMA BBBottom", ColorRed, styleLine);
```

4 Likes

It is worth noting that StDev measures deviation of sample of **finite** length, the same way as simple moving average MA measures average (expected value) of sample of **finite** length.

EMA on the other hand is a infinite response filter, which means that it takes infinite number of samples to produce the value (due to its recursive formulation) and as such is quite a different beast than MA and purists would say that using it with standard deviation isn't 100% correct thing (at least from purely mathematical point of view).

3 Likes

Thank you so much Sir

@graceleung there was a slight variation on the concept in Stocks & Commodities magazine in the Feb 2017 issue,*"Exponential Standard Deviation Bands"* and it is coded into afl by @Tomasz here

4 Likes

And also, please help me that I want to use the following EMA of Bollinger band formula to write a stylehistogram indicator in afl ? (for chart pic., see attached picture)

N1:=8;

N2:=20;

AA1:=EMA(C,N1);

AA2:=EMA(C,N2);

MID1:=EMA(C,N2);

TMP1:=STD(C,N2);

TOP1:=MID1+2*TMP1;
BOT1:=MID1-2*TMP1;

VAR0:AA1-AA2,NODRAW;

VAR1:=AA1>TOP1;

VAR2:=AA1<BOT1;

VAR3:=NOT(VAR1) AND NOT(VAR2);

STICKLINE(VAR1,0,VAR0,COLORRED,0);

STICKLINE(VAR2,0,VAR0,COLORGREEN,0);

STICKLINE(VAR3,0,VAR0,COLORYELLOW,0);

EMA8 = EMA(Close, 8);

EMA20 = EMA(Close, 20);

P = C;

period = 20;

width = 2;

myMa = EMA( P, period );

StdDev= width*Stdev( P, period );

bandTop = myMa + StdDev;

bandBot = myMa - StdDev;

//Plot( C, "Price", colorDefault, styleBar );

//Plot( myMa, "EMA", colorLime, styleDashed );

//Plot( bandTop, "EMA BBTop", ColorRed, styleLine );

//Plot( bandBot, "EMA BBBottom", ColorRed, styleLine);

Hist = EMA8-EMA20 ;// ((bandTop+bandBot)/2)

Plot(0,"", colorWhite);

Title = "Histogram " + WriteVal(Hist);

With your disrespectful attitude towards this forum you will **not** get any more help (if you continue like that).

First learn how to **respect** this forum and its (actual) forum contributors.

Right now you absolutely do not bother at all. You only bother for **getting something**. Your last post **proves it**. So better stop denying. Instead please keep quiet and rather listen...

(Please) read forum rules such as in the thread "How to use this site".

I am really tired of such posts as your last one.

And BTW, I took the time to write the alternative bands code in forum editor but **not** you. You just copied the code and removed the rest. Yes, it is just some simple BS code (doesn't matter what it is). Still, I have taken the time to write it for you but it was NOT you having written it to yourself. You would not be here using others then.

You just proved that what you do with simple codes you would also do with more comprehensive ones taking even more time... Just grabbing them and making them yours removing credit to original creators (and in a bad world probably selling them). Because you only care for yourself. Again your last post showing that you totally do not bother at all proves it.

Once again and for the **last time**. Show some respect to actual forum contributors or it will be dead soon if this continues like that because of no one responding anymore.

It is about basic rules of respect here.

Is it totally understood now?

I hope so because I am really tired of repeating (and I am not the only one).

3 Likes

I'm very apologize Sir, I've been tried my best before asking yours, my English not very well, not really understood all of the rules on this forum…… I've clarify that it is my idea and the formula is my programmer writter for me, but we do not know how to write in afl ?

I 'm so sorry to you again, I'll try to write by myself again and thank you for yrs assistant !

Good catch Tomasz, you 100% right. portfoliobuilders link to your code below is the correct answer!

2 Likes