Bollinger Bands MTF (Multi Time Frame) for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Someone recently asked if it was possible to plot Bollinger Bands from 15m on the 5m chart. The answer is yes, using this indicator.

Example: Displaying the Bollinger Bands of the Hourly chart on the 5m, 15m, or 30m time frame. The indicator is highly configurable and support multi time frame options.

The original version has the simple moving average set to 50 and standard deviation set to 1.0. I modified it so that it is up to date with the Bollinger Bands indicator in ThinkorSwim. You can adjust the values and settings to your liking.




thinkScript Code

Code:
# DG_MTFBollingerBands
# Paints Bollinger Bands from higher time period
# onto current time period
#
# Copyright (c) 2017 Daniel Granville

input timeframe = AggregationPeriod.DAY;
input period = 20;
input std = 2.0;
input moving_average_type = {default SMA, EMA};

def data = close(period = timeframe);
def band = StDev(data, period);

plot MidLine;

switch(moving_average_type) {
    case SMA:
        MidLine = Average(data, period);
    case EMA:
        MidLine = ExpAverage(data, period);
}

plot BBandTop = MidLine + band;

plot BBandBot = MidLine - band;
Credit:
 
Last edited:
H

horserider

Well-known member
VIP
Warehouse
Please can someone explain how this is useful over using 2 BB studies of same time frame with different dev.
 
markos

markos

Well-known member
VIP
Warehouse
Actually, there was at least one study in TASC a while back by Tushar Chande.
It used 4 different Time Frames in BB's plus a few more studies to create a Combined Signal Approach (CSA).
Usefull? Maybe, but I didn't look at it beyond reading about it.
 
S

soary

Member
Hello all, I like the concept of this indicator but need help with it since I'm not a coder but learning. This indicator
# Paints Bollinger Bands from higher time period
# onto current time period
First, I don't see the specific time periods named in the code so I figured it is so one can modify it, but I don't know if instead of the word time I'm supposed to type 1hr, 4hr, day or if it's one period at a time and for example should be AggregationPeriod.1hr;
and since it is BB shouldn't have def or input Bollinger Bands named in the code.
Then, I would like to use it in the opposite direction from which it was created. Instead of
# Paints Bollinger Bands from higher time period
# onto current time period
I would like to have a weekly chart and
# Paints Bollinger Bands from lower time period
# onto current (weekly) time period
so on my current weekly 1Y:Wk chart I would like to have BB from current 1D (day), current 4hr or 1hr time period. Also, I don't understand
plot BBandTop = MidLine + band;
plot BBandBot = MidLine - band;
How does it add/subtract from top/bottom band the 20 ema or sma to 2.0 STD outer bands? If this is possible as a mathematical equation wouldn'the resu;t be more than 2.0 STD for the outer bands? Apologies for my lack of knowledge and thanks in advance.
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@soary If you look at the code, you will see input timeframe = AggregationPeriod.DAY;

That mean the current timeframe that it is pulling the Bollinger Bands from is the daily. Take a look at this page and replace "DAY" with whichever timeframe you want to use: https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod.html

Finally, you can't reverse it. You can have a higher timeframe on a lower timeframe and not the opposite.
 
S

soary

Member
Wonderful, that answers my question for 2 indicators I'm studying.
What's up with the BB outer bands are they more than 2.0 std with this addition?

I don't understand
plot BBandTop = MidLine + band;
plot BBandBot = MidLine - band;
How does it add/subtract from top/bottom band the 20 ema or sma to 2.0 STD outer bands? If this is possible as a mathematical equation wouldn'the resu;t be more than 2.0 STD for the outer bands?
 

Top