Is it possible to combine MACD with Bollinger bands?


Hello Pete,

Hope you are doing well. I recently started trading and stumbled upon your videos while I was searching for a way to merge MACD with Bollinger Bands on TOS. I tried to merge them in lower column (below volume) but MACD either extends way above or below Bollinger Bands. Is there a way to keep the MACD lines within Bollinger Bands? I tried to create a new study using in-built script but it didn’t work.

I have attached two images (First image is an example of how I want it to be, while the second one is how its showing up in TOS when I try to merge them together) for your reference.

I am very new to TOS and trying my best to learn. Any help would be appreciated.

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on July 30, 2018 1:54 am
Private answer

Here is one way to achieve this. If you are trying to learn how to do this and want an explanation of the code then let me know and I will provide more details.

Here is the code, with screenshot showing the result:

declare lower;
#---------- MACD Inputs
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
#---------- BB Inputs
input displace = 0;
input length = 20;
input num_Dev_Dn = -2.0;
input num_Dev_up = 2.0;
input bbAverageType = AverageType.Simple;
#---------- MACD Section
def value = MovingAverage(macdAverageType, close, fastLength) - MovingAverage(macdAverageType, close, slowLength);
def avg = MovingAverage(macdAverageType, value, macdLength);
#---------- BB Section
def sDev = stdev(data = avg[-displace], length = length);
plot midLine = MovingAverage(bbAverageType, data = avg[-displace], length = length);
plot lowerBand = midLine + num_Dev_Dn * sDev;
plot upperBand = midLine + num_Dev_up * sDev;

Marked as spam
Posted by (Questions: 37, Answers: 3105)
Answered on July 31, 2018 9:06 am