Verify Larry McMillan’s Modified Bollinger Bands

dasheasy

New member
I currently have this for the modified Bollinger Bands as pointed out by McMillan from here but the bands do not look like what they should.

Here is some more information from tradingview.

Ruby:
#
# Larry McMillan’s Modified Bollinger Bands
#

input price = close;
input length = 20;
input Num_Dev0 = 3;
input Num_Dev1 = 4.0;
input averageType = AverageType.Simple;

# def sDev = stdev(data = price, length = length);
def closeLog = Log(price / price[1]);
def sDev = stdev(closeLog, length)* Sqrt(length / (length – 1));

plot MidLine = MovingAverage(averageType, data = price, length = length);

plot UpperBand0 = MidLine * Exp(Num_Dev0 * sDev);
plot LowerBand0 = MidLine * Exp(-Num_Dev0 * sDev);
plot UpperBand1 = MidLine * Exp(Num_Dev1 * sDev);
plot LowerBand1 = MidLine * Exp(-Num_Dev1 * sDev);

UpperBand0.SetDefaultColor(GetColor(3));
LowerBand0.SetDefaultColor(GetColor(3));
MidLine.SetDefaultColor(GetColor(1));
UpperBand1.SetDefaultColor(GetColor(5));
LowerBand1.SetDefaultColor(GetColor(0));
 
Last edited:
Try this
Ruby:
def X = stdev((Close - Close[1]) / Close[1],20);
def SMA = simpleMovingAvg(Close,20);
plot Y = SMA + (SMA * (x * 4));
plot Z = SMA - (SMA * (x * 4));
plot A = SMA + (SMA * (x * 3));
plot B = SMA - (SMA * (x * 3));
uEVot5q.png
 
The good doctor is very generous sharing his knowledge.
I have tried EMA too (as well as AMA, KAMA he shared). While EMA is a little better, the bands do not match.

Here I have commented everything I have tried. Different sDev all valid and look good, but alas no match

Ruby:
input price = close;
input length = 20;
input Num_Dev0 = 3;
input Num_Dev1 = 4.0;
input mode = {default EXP, Simple, VOL};

# def sDev = stdev(data = price, length = length);
def closeLog = Log(price / price[1]);
#def closeLog = (price - price[1]) / price[1];

#def sDev = stdev(closeLog, length)* Sqrt(length / (length – 1));
def sDev = StDev(closeLog, length);
#def sDev = IMP_volatilityx() * sqrt(1 / 365.0);

def ma;
switch (mode) {
case EXP:
ma = MovingAverage(averageType.EXPONENTIAL, data=price, length=length);
case Simple: 
ma = MovingAverage(averageType.Simple, data=price, length=length);
case VOL:
ma = (Highest(high, length) + Lowest(low, length)) / 2;
}

plot MidLine = ma;

#plot MidLine = MovingAverage(averageType, data = price, length = length);

plot UpperBand0 = MidLine * Exp(Num_Dev0 * sDev);
plot LowerBand0 = MidLine * Exp(-Num_Dev0 * sDev);
plot UpperBand1 = MidLine * Exp(Num_Dev1 * sDev);
plot LowerBand1 = MidLine * Exp(-Num_Dev1 * sDev);
#plot UpperBand0 = MidLine + MidLine * Num_Dev0 * sDev;
#plot LowerBand0 = MidLine - MidLine * Num_Dev0 * sDev;
#plot UpperBand1 = MidLine + MidLine * Num_Dev1 * sDev;
#plot LowerBand1 = MidLine - MidLine * Num_Dev1 * sDev;

UpperBand0.SetDefaultColor(GetColor(3));
LowerBand0.SetDefaultColor(GetColor(3));
MidLine.SetDefaultColor(GetColor(1));
UpperBand1.SetDefaultColor(GetColor(5));
LowerBand1.SetDefaultColor(GetColor(0));
 
Last edited:
The good doctor is very generous sharing his knowledge.
I have tried EMA too (as well as AMA, KAMA he shared). While EMA is a little better, the bands do not match.

Here I have commented everything I have tried. Different sDev all valid and look good, but alas no match

Ruby:
input price = close;
input length = 20;
input Num_Dev0 = 3;
input Num_Dev1 = 4.0;
input mode = {default EXP, Simple, VOL};

# def sDev = stdev(data = price, length = length);
def closeLog = Log(price / price[1]);
#def closeLog = (price - price[1]) / price[1];

#def sDev = stdev(closeLog, length)* Sqrt(length / (length – 1));
def sDev = StDev(closeLog, length);
#def sDev = IMP_volatilityx() * sqrt(1 / 365.0);

def ma;
switch (mode) {
case EXP:
ma = MovingAverage(averageType.EXPONENTIAL, data=price, length=length);
case Simple:
ma = MovingAverage(averageType.Simple, data=price, length=length);
case VOL:
ma = (Highest(high, length) + Lowest(low, length)) / 2;
}

plot MidLine = ma;

#plot MidLine = MovingAverage(averageType, data = price, length = length);

plot UpperBand0 = MidLine * Exp(Num_Dev0 * sDev);
plot LowerBand0 = MidLine * Exp(-Num_Dev0 * sDev);
plot UpperBand1 = MidLine * Exp(Num_Dev1 * sDev);
plot LowerBand1 = MidLine * Exp(-Num_Dev1 * sDev);
#plot UpperBand0 = MidLine + MidLine * Num_Dev0 * sDev;
#plot LowerBand0 = MidLine - MidLine * Num_Dev0 * sDev;
#plot UpperBand1 = MidLine + MidLine * Num_Dev1 * sDev;
#plot LowerBand1 = MidLine - MidLine * Num_Dev1 * sDev;

UpperBand0.SetDefaultColor(GetColor(3));
LowerBand0.SetDefaultColor(GetColor(3));
MidLine.SetDefaultColor(GetColor(1));
UpperBand1.SetDefaultColor(GetColor(5));
LowerBand1.SetDefaultColor(GetColor(0));
looks good, not perfect as you said but it looks good. i personally kept the upper/lower bands, removed the middle line and use the kama line instead --the one the good doctor shared. works like a charm. i also have the bb squeeze momentum on the lower subgraph1 for confirmation and on the lower subgraph2 a regular linear regression line. better confirmation signals i never had
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
393 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top