technicalindicators icon indicating copy to clipboard operation
technicalindicators copied to clipboard

Bollinger Bands - use EMA?

Open tredondo opened this issue 5 years ago • 5 comments

What type of MA does BB use? I don't see any docs.

I assume it uses SMA? Is there an option to use EMA?

tredondo avatar Apr 05 '20 21:04 tredondo

BB uses SMA, currently it is not possible to use EMA, pull request welcome, similar feature is implemented in MACD, https://github.com/anandanand84/technicalindicators/blob/master/src/moving_averages/MACD.ts#L31

anandanand84 avatar Apr 06 '20 16:04 anandanand84

I tried installing the package but it broke at canvas.

Is there a lightweight way of adding tests? If I just add an option to an indicator, seems like a test should just compare the output to an array.

tredondo avatar Apr 07 '20 15:04 tredondo

@tredondo what OS are you using to do development? I had the same issue as you did getting canvas installed. Currently using node v12.16.3 on macOS Catalina.

I've played around with the packages.json file a little and I think I got it working but can't seem to get things rolling.

Let me know.

Thanks, Flux

djflux avatar May 16 '20 22:05 djflux

@djflux: I was using Ubuntu and I submitted a patch to add EMA support for Bollinger Bands.

Hope it gets merged.

tredondo avatar Aug 06 '20 08:08 tredondo

You can just copy the original script and change SMA to EMA on the 6th line. Or copy and paste the below script to the blank pine editor and save accordingly.

//@version=4 study(shorttitle="BB", title="Bollinger Bands", overlay=true, resolution="") length = input(20, minval=1) src = input(close, title="Source") mult = input(2.0, minval=0.001, maxval=50, title="StdDev") basis = ema(src, length) //<--------------------------------------CHANGED FROM SMA TO EMA dev = mult * stdev(src, length) upper = basis + dev lower = basis - dev offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500) plot(basis, "Basis", color=#FF6D00, offset = offset) p1 = plot(upper, "Upper", color=#2962FF, offset = offset) p2 = plot(lower, "Lower", color=#2962FF, offset = offset) fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

jere-0 avatar Sep 12 '21 05:09 jere-0