Multi-TimeFrame Candles Overlay for ThinkOrSwim

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

Also noticed these odd little, tiny dots on the O and C lines. Kinda funky.

Yes. There was an error in that last update, when open and close are equal. Now when open and close are equal, they show up properly as a full white line instead of the usual up or down, red or green. (Problem corrected.)

And... I've added an Input for LineWeight.

Code:
# Multi-Time-Frame Candle Overlay version 2.3
# 2020 Paul Townsend
# with code from UseThinkScript.com

input agg = AggregationPeriod.fifteen_min;
input OpenCloseLines = yes;
input HighLowLines = yes;
input HighLowGray = no;
input LineWeight =2;


addlabel(yes,"[" + agg/60000 + "]",color.white);

plot o = open(period = agg);
plot c = close(period = agg);
plot h = high(period = agg);
plot l = low(period = agg);

o.sethiding(!OpenCloseLines);
c.sethiding(!OpenCloseLines);
h.sethiding(!HighLowLines);
l.sethiding(!HighLowLines);

o.setLineWeight(lineweight);
c.setLineWeight(lineweight);
h.setLineWeight(lineweight);
l.setLineWeight(lineweight);

o.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
c.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
AddCloud(c, o, Color.Green, Color.Red);
h.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
l.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);


o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
c.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
So, the question is, how do you get the paint to stay within the boxes?
Hint: you will need to use more than one AddCloud() statement.
Hint: You need to use two AddCloud() functions--one for even MTF periods and one for odd.

I've spent an hour or so on this. Still can't get it to work. How do these two AddCloud() statements differ? I've discovered def variables are not accepted in the color definitions. Though if then else statements are. I'm kind stuck on this one. Maybe... another hint... or some code?
 
Last edited by a moderator:
I've spent an hour or so on this. Still can't get it to work. How do these two AddCloud() statements differ? I've discovered def variables are not accepted in the color definitions. Though if then else statements are. I'm kind stuck on this one. Maybe... another hint... or some code?

The AddCloud() function paints the area between two values.

1) During the times that you want cloud 1 to paint and not cloud 2, set cloud 1 values to some number and cloud 2 values to Double.NaN
2) During the times that you want cloud 2 to paint and not cloud 1, set cloud 1 values to Double.NaN and cloud 2 values to some number
 
Here's a practical example that illustrates the concepts just discussed above

Code:
# Bollinger Band Color SD Clouds Squeeze
# Mobius
# 12.15.2015

input length = 20;
input Dev = 2.0;
input Dev2 = 3.0;

def h = high;
def l = low;
def c = close;
def sDev = StDev(close, length);
def ATR = Average(TrueRange(h, c, l), length);
plot MidL = Average(close, length);
plot LowerB = MidL + (-Dev * sDev);
plot UpperB = MidL + (Dev * sDev);
plot LowerB2 = MidL + (-Dev2 * sDev);
plot UpperB2 = MidL + (Dev2 * sDev);
def Squeeze = UpperB < MidL + (1.5 * ATR);

LowerB.SetDefaultColor(Color.Gray);
LowerB.HideBubble();
UpperB.SetDefaultColor(Color.Gray);
UpperB.HideBubble();
LowerB2.SetDefaultColor(Color.Gray);
LowerB2.HideBubble();
UpperB2.SetDefaultColor(Color.Gray);
UpperB2.HideBubble();
MidL.SetDefaultColor(Color.WHITE);
MidL.HideBubble();

addCloud(if squeeze then UpperB else double.nan, UpperB2, color.white, color.white);
addCloud(UpperB, UpperB2, color.gray, color.gray);

addCloud(if squeeze then LowerB else double.nan, LowerB2, color.white, color.white);
addCloud(LowerB, LowerB2, color.gray, color.gray);

# End Study
 
Thanks for the help on this guys: @RobertPayne @tomsk
Solution: ref definitions can't be used in an AddCloud() statement, but plot definitions can!
So... this is a minor update. None the less, it does look much better.
Really appreciate the community pitching in to help me figure this out!

Code:
# Multi-Time-Frame Candle Overlay version 2.4
# 2020 Paul Townsend
# with code from UseThinkScript.com

input agg = AggregationPeriod.fifteen_min;
input OpenCloseLines = yes;
input HighLowLines = yes;
input HighLowGray = no;
input LineWeight =2;


addlabel(yes,"[" + agg/60000 + "]",color.white);

plot o = open(period = agg);
plot c = close(period = agg);
plot h = high(period = agg);
plot l = low(period = agg);

o.sethiding(!OpenCloseLines);
c.sethiding(!OpenCloseLines);
h.sethiding(!HighLowLines);
l.sethiding(!HighLowLines);

o.setLineWeight(lineweight);
c.setLineWeight(lineweight);
h.setLineWeight(lineweight);
l.setLineWeight(lineweight);

o.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
c.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
h.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
l.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);

def side = if side[1] == 1 then 2 else 1; plot sider = side; sider.hide();
AddCloud( if sider==2 then c else double.nan, o, Color.green, Color.red);
AddCloud( if sider==1 then c else double.nan, o, Color.green, Color.red);

o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
c.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# end
 
Last edited:
@Townsend - Nice work! I just made a minor change to the clouds to match the horizontal line colors
Code:
# Multi-Time-Frame Candle Overlay version 2.4
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2020 - BLT - Modified Addcloud to match horizontal lines

input agg = AggregationPeriod.fifteen_min;
input OpenCloseLines = yes;
input HighLowLines = yes;
input HighLowGray = no;
input LineWeight =2;


addlabel(yes,"[" + agg/60000 + "]",color.white);

plot o = open(period = agg);
plot c = close(period = agg);
plot h = high(period = agg);
plot l = low(period = agg);

o.sethiding(!OpenCloseLines);
c.sethiding(!OpenCloseLines);
h.sethiding(!HighLowLines);
l.sethiding(!HighLowLines);

o.setLineWeight(lineweight);
c.setLineWeight(lineweight);
h.setLineWeight(lineweight);
l.setLineWeight(lineweight);

o.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
c.AssignValueColor(if o==c then color.white else if o > c then Color.red else Color.green);
h.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
l.AssignValueColor(if highlowgray then color.gray else if o==c then color.white else if o > c then Color.red else Color.green);
input addcloud =yes;
def side = if side[1] == 1 then 2 else 1; plot sider = side; sider.hide();
AddCloud( if sider==2 then c else double.nan, o, Color.green, Color.red);
AddCloud( if sider==1 then c else double.nan, o, color.green, Color.red);

o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
c.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# end
 
I like this study going to load it up for Monday. thanks very much. I loaded your study with the new supertrend csa and it is tight, awesome
 
Last edited:
If I'd have known this was here I wouldn't have went through all the trouble making something similar. Lol
Code:
#[email protected]

def NA = Double.NaN;
input Aggregation1 = AggregationPeriod.HOUR;
input Aggregation2 = AggregationPeriod.DAY;

plot HighBand1 = high("Period" = Aggregation1);
plot LowBand1 = low("Period" = Aggregation1);
plot OpenBand1 = open("Period" = Aggregation1);
plot CloseBand1 = close("Period" = Aggregation1);

HighBand1.Hide();
LowBand1.Hide();
OpenBand1.Hide();
CloseBand1.Hide();

plot HighBand2 = high("Period" = Aggregation2);
plot LowBand2 = low("Period" = Aggregation2);
plot OpenBand2 = open("Period" = Aggregation2);
plot CloseBand2 = close("Period" = Aggregation2);

#Aggregation2
AddCloud(if OpenBand2 > CloseBand2 then OpenBand2 else NA, if OpenBand2 > CloseBand2 then CloseBand2 else NA, Color.DARK_RED, Color.DARK_RED);

AddCloud(if OpenBand2 > CloseBand2 then NA else CloseBand2, if OpenBand2 > CloseBand2 then NA else OpenBand2, Color.DARK_GREEN, Color.DARK_GREEN);

AddCloud(if OpenBand2 > CloseBand2 then OpenBand2 else NA, if OpenBand2 > CloseBand2 then HighBand2 else NA, Color.DARK_GRAY,  Color.DARK_GRAY);

AddCloud(if OpenBand2 > CloseBand2 then CloseBand2 else NA, if OpenBand2 > CloseBand2 then LowBand2 else NA, Color.DARK_GRAY, Color.DARK_GRAY);

AddCloud(if CloseBand2 > OpenBand2 then CloseBand2 else NA, if CloseBand2 > OpenBand2 then HighBand2 else NA, Color.DARK_GRAY, Color.DARK_GRAY);

AddCloud(if CloseBand2 > OpenBand2 then OpenBand2 else NA, if CloseBand2 > OpenBand2 then LowBand2 else NA, Color.DARK_GRAY, Color.DARK_GRAY);


#Aggregation1
AddCloud(if OpenBand1 > CloseBand1 then OpenBand1 else NA, if OpenBand1 > CloseBand1 then CloseBand1 else NA, Color.RED, Color.RED);

AddCloud(if OpenBand1 > CloseBand1 then NA else CloseBand1, if OpenBand1 > CloseBand1 then NA else OpenBand1, Color.GREEN, Color.GREEN);

AddCloud(if OpenBand1 > CloseBand1 then OpenBand1 else NA, if OpenBand1 > CloseBand1 then HighBand1 else NA, Color.DARK_GRAY,  Color.DARK_GRAY);

AddCloud(if OpenBand1 > CloseBand1 then CloseBand1 else NA, if OpenBand1 > CloseBand1 then LowBand1 else NA, Color.DARK_GRAY, Color.DARK_GRAY);

AddCloud(if CloseBand1 > OpenBand1 then CloseBand1 else NA, if CloseBand1 > OpenBand1 then HighBand1 else NA, Color.DARK_GRAY, Color.DARK_GRAY);

AddCloud(if CloseBand1 > OpenBand1 then OpenBand1 else NA, if CloseBand1 > OpenBand1 then LowBand1 else NA, Color.DARK_GRAY, Color.DARK_GRAY);


#Hour
HighBand1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighBand1.SetDefaultColor(Color.DARK_GRAY);
LowBand1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowBand1.SetDefaultColor(Color.DARK_GRAY);
OpenBand1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenBand1.SetDefaultColor(Color.GREEN);
CloseBand1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CloseBand1.SetDefaultColor(Color.RED);
#Day
HighBand2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighBand2.SetDefaultColor(Color.DARK_GRAY);
LowBand2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowBand2.SetDefaultColor(Color.DARK_GRAY);
OpenBand2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpenBand2.SetDefaultColor(Color.GREEN);
CloseBand2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CloseBand2.SetDefaultColor(Color.RED);

https://tos.mx/hc22aKz

7tLeUSX.png
 
I was just looking at this and thought i would take a shot the very least getting the variables I think that need to be set up to get the wicks and box around the higher time frame candle. Played around with the AddChart but haven't figured it out yet. As for the math part of finding the number of bars and assigning the bars as the first, middle and last bar in the series is fairly straight forward. I'm guessing the first bar of the lower time frame (i.e. 5 min) you would assign the open value of the aggregate time frame (i.e. 15 min) and the last bar (5 min) to the close value of the aggregate time frame (15min) and then the high low value to the middle bar.

Hope this gets us closer.

Code:
input aggPeriod = AggregationPeriod.FIFTEEN_MIN;

def o = open(period =aggPeriod);
def h = high(period =aggPeriod);
def l = low(period =aggPeriod);
def c = close(period =aggPeriod);

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  aggPeriod / GetAggregationPeriod();
def bn = BarNumber();
# Determine the position of each bar using the remainder with value of 0 = lowerTimeFrameBarCount
def remainder = bn % lowerTimeFrameBarCount;
def bar = if remainder == 0 then lowerTimeFrameBarCount else remainder;
#Find the middle bar in the lower timeframe - odd numbers add 0.5 to plot the wicks on the higher time frame
def midBar = if lowerTimeFrameBarCount % 2 == 0 then lowerTimeFrameBarCount/2 else lowerTimeFrameBarCount/2 + 0.5;

### making stuff up here drawing the wick through the middle candle.
def nan = double.nan;
def hb = if bar == midBar then h else nan;
def lb = if bar == midBar then l else nan;

AddChart(growcolor = color.white,  high = hb, low = lb, open = nan, close = nan, type = ChartType.bar);
 
Last edited:
@RobertPayne In an overlay chart, is it possible to run a script just on the highest time frame only without it running on the lower time frames. Thanks for your time.
 
hey Townsend like the indicator but i use a 3minute chart could you make it highlight a number of candles to show a 6,9,12 etc you would choose the number candles in the edit like a moving avg and it would be red or green or white if it doji. so 3 min chart marking 3 candles to make 9min candle so you edit 3? i hope i am clear on my explanation . thank you so much
 
hey Townsend... could you make it highlight a number of candles to show a 6,9,12 etc... like a moving avg and it would be red or green or white...

Yeah... I've got another indicator very similar to what you're asking about. I'll post it in a new thread this weekend.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
449 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