Multi-TimeFrame Candles Overlay for ThinkOrSwim

Is it possible to have and indicator show for higher time frame like a 30 min but show it on a 5 min where i will be trading mostly.
Example .. trying to show the 30 min support/resistance zone script on a 5 minute chart and not have the indicator adjust for five minute chart

Thanks in advance
 
Is it possible to have and indicator show for higher time frame like a 30 min but show it on a 5 min where i will be trading mostly.
Example .. trying to show the 30 min support/resistance zone script on a 5 minute chart and not have the indicator adjust for five minute chart

Thanks in advance
If you are referring to the above post #60, on a 5 min chart, set input numberofbars to 6 to equate to a 30 minute overlay. The script header has an explanation about this.
 
Here are the following modifications to the candlestick chart overlay script:


Tick Chart
range.jpg

Range Chart
range.jpg

Here is an update to the modification above:

Added sides to overlay candles and a psuedo buying/selling volume bubbles option for each overlay candle, based upon the formula commoningly used for this, as TOS does provide for actual amounts; buying (close-low)/(high-low) * volume
selling (high-close)/(high-low)* volume


The overlay should work on all chart types. You can create custom timeframes on time based charts beyond the preset TOS aggregationperiods.
Hi SleepyZ,

Could you please explain more I would like to use Aggregation period: Range like 500 pips or 750 pips.

Thank you for help.

Paras
 
Here is the MTF candlestick indicator for ThinkorSwim. This indicator will overlay higher time frame candles onto your chart.

@Utajiri asked for this. It's pretty simple. Here is a 5 minute DUST chart (3x short gold & silver) with 30 minute boxes overlaid. These 30 minute boxes correspond to the 30 minute red/green and open/close candles.

WeMc2NB.png


Code:
input agg = AggregationPeriod.FOUR_HOURS;
plot o = open(period = agg);
plot c = close(period = agg);
o.AssignValueColor(if o > c then Color.Red else Color.Green);
o.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
c.AssignValueColor(if o > c then Color.Red else Color.Green);
c.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddCloud(c, o, Color.Green, Color.Red);

Edit: Link to most current version.
Hi Townsend,

Can we use Aggregation Type: Tick or Range instead of Time. If so. Please give me some ideas.

Thank you for help.

Paras
 
Hi SleepyZ,

Could you please explain more I would like to use Aggregation period: Range like 500 pips or 750 pips.

Thank you for help.

Paras
You could try taking your lower chart setting, for example, 10 ticks, and divide that into 500 ticks, and set input numberofbars = 50;
 
Here is an update to the modification above:

Added sides to overlay candles and a psuedo buying/selling volume bubbles option for each overlay candle, based upon the formula commoningly used for this, as TOS does provide for actual amounts; buying (close-low)/(high-low) * volume
selling (high-close)/(high-low)* volume


The overlay should work on all chart types. You can create custom timeframes on time based charts beyond the preset TOS aggregationperiods.

Thank you @SleepyZ.

I made a minor change to the cloud for this code where it is displayed from the low to high of the timeframe....whereas the original code uses open-close for the cloud.

I like to have the low-high lines to show me the bottom-top of the cloud/timeframe, but I would like the cloud COLOR to be based on whether the closed below the open (bearish/red) or closed above the open (bullish/green).

The problem that I have having is that while I use the low-high for the cloud, I would like the cloud to be colored using the open-close logic. This tells me if the timeframe was bearish or bullish...which the low-high cloud COLOR is misleading in this.

Can you please help with me with this part of the code?

I used the original code, here it is...with the original cloud color code commented out and mine added as the last two lines.

Thank you in advance!!!






# 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);

AddCloud( if sider==2 then h else double.nan, l, Color.light_green, Color.red);
AddCloud( if sider==1 then h else double.nan, l, Color.light_green, Color.red);



# end
 
Thank you @SleepyZ.

I made a minor change to the cloud for this code where it is displayed from the low to high of the timeframe....whereas the original code uses open-close for the cloud.

I like to have the low-high lines to show me the bottom-top of the cloud/timeframe, but I would like the cloud COLOR to be based on whether the closed below the open (bearish/red) or closed above the open (bullish/green).

The problem that I have having is that while I use the low-high for the cloud, I would like the cloud to be colored using the open-close logic. This tells me if the timeframe was bearish or bullish...which the low-high cloud COLOR is misleading in this.

Can you please help with me with this part of the code?

I used the original code, here it is...with the original cloud color code commented out and mine added as the last two lines.

Thank you in advance!!!






# 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);

AddCloud( if sider==2 then h else double.nan, l, Color.light_green, Color.red);
AddCloud( if sider==1 then h else double.nan, l, Color.light_green, Color.red);



# end


I might have gotten lucky because I played around with this some more and the cloud colors are correct.

The code might not be the best, but here it is:

AddCloud( if o>c then h else double.nan, l, Color.red, Color.red);
AddCloud( if c>o then h else double.nan, l, Color.light_green, Color.light_green);
 
Thank you @SleepyZ.

I made a minor change to the cloud for this code where it is displayed from the low to high of the timeframe....whereas the original code uses open-close for the cloud.

I like to have the low-high lines to show me the bottom-top of the cloud/timeframe, but I would like the cloud COLOR to be based on whether the closed below the open (bearish/red) or closed above the open (bullish/green).

The problem that I have having is that while I use the low-high for the cloud, I would like the cloud to be colored using the open-close logic. This tells me if the timeframe was bearish or bullish...which the low-high cloud COLOR is misleading in this.

Can you please help with me with this part of the code?

I used the original code, here it is...with the original cloud color code commented out and mine added as the last two lines.

Thank you in advance!!!






# 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);

AddCloud( if sider==2 then h else double.nan, l, Color.light_green, Color.red);
AddCloud( if sider==1 then h else double.nan, l, Color.light_green, Color.red);



# end
See if this helps (Your code works, but does not keep the separation of clouds between candles in Townsend's code)

Code:
AddCloud( if sider==2 and o>c then h else double.nan, l, Color.red, Color.red);
AddCloud( if sider==2 and o<c then h else double.nan, l, Color.light_green, Color.light_green);
AddCloud( if sider==1 and o>c then h else double.nan, l, Color.red, Color.red);
AddCloud( if sider==1 and o<c then h else double.nan, l, Color.light_green, Color.light_green);
 
See if this helps (KevingSammy's code works, but does not keep the separation of candles in Townsend's code)


Thank you, Sleepy!


I tagged a few of the excellent coders I've read posts from, and tried a few others but their accounts didn't work.

I was wondering if you can please help me with two additional things that I would like to include:

I use 10 minute candles, so let's assume that's the timeframe for these examples.

1) when 10 minute MTF sequence closes, if the first candle in the new sequence closes below the high AND close of the previous 10 minutes then make an arrow or color the candle red. This is a bearish sentiment, imo

2) when a 10 minute MTF sequence closes, if any of the candles in the next sequence have a 9ema close above the high OR close of the previous 10 minutes, then make an arrow or color the candle green. This is a bullish sentiment, imo.


@SleepyZ @bperott7 @rad14733 @BenTen @horserider @markos
 
Thank you, Sleepy!


I tagged a few of the excellent coders I've read posts from, and tried a few others but their accounts didn't work.

I was wondering if you can please help me with two additional things that I would like to include:

I use 10 minute candles, so let's assume that's the timeframe for these examples.

1) when 10 minute MTF sequence closes, if the first candle in the new sequence closes below the high AND close of the previous 10 minutes then make an arrow or color the candle red. This is a bearish sentiment, imo

2) when a 10 minute MTF sequence closes, if any of the candles in the next sequence have a 9ema close above the high OR close of the previous 10 minutes, then make an arrow or color the candle green. This is a bullish sentiment, imo.


@SleepyZ @bperott7 @rad14733 @BenTen @horserider @markos
If you could provide a chart image depicting what at least #1 above looks like, I may be able to help with both. It would help to know what chart timeframe you are using with the 10 minute MTF, what is a sequence change (assume you mean color change) and which candle is the next candle in the new sequence ( mtf candle or chart timeframe candle).
 
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!
Modified to paint high/low/open/close lines with Heiken Ashi coloring, cloud retains original coloring.
Also changed high/low to plot with dots instead of lines.
# Multi-Time-Frame Candle Overlay version 2.4.210717
# 2020 Paul Townsend modified by theLEMband
# with code from UseThinkScript.com
########
# version 2.4.210717
# Heiken Ashi Colors
# Plot High & Low as dots instead of lines
########

input agg = AggregationPeriod.FIVE_MIN;
input OpenCloseLines = yes;
input HighLowLines = yes;
# HA cut# input HighLowGray = no;
input LineWeight = 2;
#inputs for HA Color
input heiken_ashi_length = 1; # 1= normal HeikinAshi-Ashi
input averageType = AverageType.SIMPLE;

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);

# HA cut# o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
# HA cut# c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
# HA cut# h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
# HA cut# l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
#============begin HA Color
def haClose = (open(period=agg) + high(period=agg) + low(period=agg) + close(period=agg) ) / 4;
def haOpen = (haOpen[1] + haClose[1]) / 2;

def avgOpen = MovingAverage(averageType, haOpen, heiken_ashi_length);
def avgClose = MovingAverage(averageType, haClose, heiken_ashi_length);

o.AssignvalueColor(if avgOpen < avgClose then color.green else
if avgOpen > avgClose then color.red else color.white);
c.AssignvalueColor(if avgOpen < avgClose then color.green else
if avgOpen > avgClose then color.red else color.white);
h.AssignvalueColor(if avgOpen < avgClose then color.green else
if avgOpen > avgClose then color.red else color.white);
l.AssignvalueColor(if avgOpen < avgClose then color.green else
if avgOpen > avgClose then color.red else color.white);
#============end HA color

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);
h.SetStyle(Curve.POINTS);
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l.SetStyle(Curve.POINTS);

# end
 
Modified to paint high/low/open/close lines with Heiken Ashi coloring, cloud retains original coloring.
Also changed high/low to plot with dots instead of lines.

This looks great, @theLEMband.
Adding @SleepyZ and @rad14733 for their great insight as well.


Could you help me with one piece of additional code - for when the 9ema is above the high or close of last 5 minute aggregation period?
I am using the 1 minute chart.

I tried using aggregation period as well as input bars_away, but without any success.
For example, I tried this:
def input bars_away = 5;
def input bars_count = yes;


Thank you!
 
Last edited:
Could you help me with one piece of additional code - for when the 9ema is above the high or close of last 5 minute aggregation period?
I am using the 1 minute chart.

I tried using aggregation period as well as input bars_away, but without any success.
For example, I tried this:
def input bars_away = 5;
def input bars_count = yes;


Thank you!
Sorry, no idea on that.
 
a few days ago i made a study to find open, high, low, close for a higher time frame.
https://usethinkscript.com/threads/tos-scan-multiple-aggregation-calculating-ohlc.7403/
i got to looking at it and thought i could change it to show higher time frame candles. i got it to show the wicks pretty easy, but drawing shading and lines during the current time period took me awhile.
i searched and found this post, so am adding it to the collection.

MTF candle overlay
this is an upper chart study that draws colored shading (green, red, white) to represent bigger time frame candles, by drawing a body and wicks.
example, draw 30 minute candles, on a 5minute chart, (spanning 6 bars).

enter the desired minutes for the longer time period. any number greater than 1.
it is not restricted by the built in time frames.
you can choose 78 and see 5 candles over a day. ( 78 x 5 = 390 minutes , a trading day).
it finds the open, high, low, close for each time period.

the current (last) time period draws rectangles as each candle appears and moves. i have noticed that sometimes the lines or shading freeze and lag behind from where they should be. there are no wicks on the current period until the last candle appears.

as candles appear, the bar count and total bars are displayed above and below the last candle.
a vertical line can be drawn in the future , to show when the current time period will end.
it uses RGB colors.
it displays a label, if the user time period number isn't a multiple of the chart minutes. it won't draw anything if this happens.
if open is within 0.005 of close, then a white line is drawn for the body.

in other versions, the body clouds are joined by a diagonal edge. this is from using 1 cloud to draw the rectangles.
i used 2 sets of everything, for even and odd periods, so lines and clouds are separate, from period to period. this results in vertical edges on the body clouds. i know there are ways to combine some plots and choose colors and types, but i was focused on making this functional. and sometimes trying to improve something ends up breaking it.

it doesn't reset each day. so if a day has less bars than normal, the periods could be shifted into the next day.

there are more notes commented in the study.
look at the ticker /ES to test it, it trades most of the day. load it on a 5 minute chart, with the default 30, then wait 5+? seconds for everything to draw, before zooming in.

go here to look up RGB color numbers
https://www.w3schools.com/colors/colors_picker.asp

there are several addlabel()'s that draw black spaces, to shift the yellow label onto the next row. may want to disable them.

Ruby:
# bigaggcandles_01
# ---------------------------------
# halcyonguy
# 21-08-04
# ---------------------------------
# draw colored shading (green, red, white) to represent bigger time frame candles, including wicks
#  ex. draw 30minute candles, on a 5minute chart. 6 bars per period.
#  period number is in minutes, (any number > 1)
#   (valid if user time is a multiple of chart time, ex. 15/1, 18/3, 30/5, 45/5,...)

# label to display the quantity of period bars per time period
# recommend turning off after hours
# if open is within 0.005 of close, then a white line is drawn for the body
#
# inputs,
#   number for time period , minutes
#   show candle shading
#   lines for open/high/low/close levels
#   enter RGB color numbers for up(130,255,130) and down(255,130,130) colors
#   last period,
#     bar count, vertical line, OC lines,
#     shading, HL bubbles, OC bubbles,
#
# go here to look up RGB color numbers  https://www.w3schools.com/colors/colors_picker.asp
# ---------------------------------

def bn = BarNumber();
def na = Double.NaN;
#  last bar, on right adge of chart
#def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
#  last bar with price data
def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbarbn) then 1 else 0;

def chartagg = GetAggregationPeriod();
def chartmin = (chartagg / 1000) / 60;

input bigcandlemin = 30; #hint bigcandlemin: "Enter a number of minutes for the longer time period candles"
input show_shading = yes;
input show_OHLC_lines = no;


# body color
# up color - green
input up_body_RGB_color_0to255 = yes; #hint up_body_RGB_color_0to255: "a dummy variable, to explain the number range for RGB colors, 0 to 255"
#  default RGB colors, red-green-blue,  light green (130,255,130)   light red (255,130,130)
#  alt colors , slightly darker, medium green (60,255,60)   medium red (255,60,60)
#  alt colors ,  green (0,255,0)   red (255,0,0)
input up_color_red_num = 130;
def ured = up_color_red_num;
input up_color_green_num = 255;
def ugrn = up_color_green_num;
input up_color_blue_num = 130;
def ublu = up_color_blue_num;
DefineGlobalColor( "upshade1" , CreateColor(ured,ugrn,ublu));
input down_body_RGB_color_0to255 = yes;
# down color - red
input down_color_red_num = 255;
def dred = down_color_red_num;
input down_color_green_num = 130;
def dgrn = down_color_green_num;
input down_color_blue_num = 130;
def dblu = down_color_blue_num;
DefineGlobalColor( "downshade1" , CreateColor(dred,dgrn,dblu));
#  use
# GlobalColor("upshade1")
# GlobalColor("downshade1")

# bigbar , refers to the group of bars that make up a bigger agg candle
# is chartmin a multiple of bigcandlemin?
def bigmulti = (bigcandlemin / chartmin) == floor(bigcandlemin / chartmin);
def bigbar2 = if (!bigmulti or bigcandlemin <= chartmin) then 1 else (bigcandlemin / chartmin);

# add offset -1 to bar#. want 2nd 30min period start to be on bar31, not 30
def bnoff = -1;
# find first bar in a group of bigbar bars
def bigbarfirst = ((bn + bnoff) / bigbar2) == Floor((bn + bnoff) / bigbar2);
def bigbarfirstbn = if bigbarfirst then bn else bigbarfirstbn[1];
def bigbar = bigbar2;

addlabel(bigmulti, GetSymbol() + "  " + Getmonth() + "/" + getdayofmonth(GetYyyyMmDd()), color.yellow);
addlabel(bigmulti, bigcandlemin + " min period / " + bigbar + " bars, on a " + chartmin + " min chart" , color.yellow);
addlabel(!bigmulti, "<<<<<<<<<<  bigcandlemin " + bigcandlemin + " is not a multiple of chart time " + chartmin + ". nothing drawn  >>>>>>>>>>", color.cyan);


# -----------------------------
# find the bars for the wicks
#   bigbar , qty of bars in a period
#   bigbarfirst , first bar in period
def bigbarqtyeven = (bigbar / 2) == Floor(bigbar / 2);
def bigbarhalf = floor(bigbar/2);
def mid = bigbarfirst[bigbarhalf - 1];

# this defines the middle 2 or 3 bars for the wicks
def wick;
if bigbarqtyeven then {
  wick = bigbarfirst[bigbarhalf - 1] or bigbarfirst[bigbarhalf - 0];
} else {
  wick = bigbarfirst[bigbarhalf + 1] or bigbarfirst[bigbarhalf - 0] or bigbarfirst[bigbarhalf - 1];
};

# --------------------------------


# --------------------------------

# count bars in each period
def perbarcnt = if bigbarfirst then 1 else perbarcnt[1] + 1;
# count bar groups
def bigbarcnt = if bigbarfirst then bigbarcnt[1] + 1 else bigbarcnt[1];
# determine odd/even, to alternate between groups, so lines and clouds are not continious
def bigbareven = (bigbarcnt/2) == Floor(bigbarcnt/2);

# if the first bar in a period,
# offset to a future bar, then use highest and lowest to look back and find...
#  highest in bigbar period
def hi2 = if bigbarfirst then Highest(high[-(bigbar-1)], bigbar) else hi2[1];
#  lowest in bigbar period
def lo2 = if bigbarfirst then lowest(low[-(bigbar-1)], bigbar) else lo2[1];

# -------------------------


#  OHLC  levels per period
# =======================================================
def bighi = round(hi2,3);
def biglo = round(lo2,3);
def bigopen = if bigbarfirst then open else bigopen[1];
def bigclose = if bigbarfirst then close[-(bigbar-1)] else bigclose[1];
# =======================================================


# big candle body stats
#   min open/close diff to define doji, white body , 0.005
def mindiff = 0.005;
def bodygrn = (bigclose >= (bigopen + mindiff));
def bodyred = (bigclose <= (bigopen - mindiff));
def bodywht = (!bodygrn and !bodyred);
def bodytop = max(bigopen, bigclose);
def bodybot = min(bigopen, bigclose);

# --------------------------
#  lines - high
plot hilvla = if bigbareven and show_OHLC_lines then bighi else na;
plot hilvlb = if !bigbareven and show_OHLC_lines then bighi else na;
hilvla.setdefaultcolor(color.gray);
hilvlb.setdefaultcolor(color.gray);
hilvla.hidebubble();
hilvlb.hidebubble();
#  lines - low
plot lolvla = if bigbareven and show_OHLC_lines then biglo else na;
plot lolvlb = if !bigbareven and show_OHLC_lines then biglo else na;
lolvla.setdefaultcolor(color.gray);
lolvlb.setdefaultcolor(color.gray);
lolvla.hidebubble();
lolvlb.hidebubble();
# ----------------------------
#  lines - body top , open/close
plot bodytopa = if bigbareven and show_OHLC_lines then bodytop else na;
plot bodytopb = if !bigbareven and show_OHLC_lines then bodytop else na;
bodytopa.setdefaultcolor(color.gray);
bodytopb.setdefaultcolor(color.gray);
bodytopa.hidebubble();
bodytopb.hidebubble();
#  lines - body bot , open/close
plot bodybota = if bigbareven and show_OHLC_lines then bodybot else na;
plot bodybotb = if !bigbareven and show_OHLC_lines then bodybot else na;
bodybota.setdefaultcolor(color.gray);
bodybotb.setdefaultcolor(color.gray);
bodybota.hidebubble();
bodybotb.hidebubble();

# ---------------------------------

# doji candle
# open/close same ,  white line for body
plot bodywhteven4 = if show_shading and bigbareven and bodywht then bigclose else na;
bodywhteven4.setdefaultcolor(color.white);
bodywhteven4.setlineweight(2);
bodywhteven4.hidebubble();

plot bodywhtodd4 = if show_shading and !bigbareven and bodywht then bigclose else na;
bodywhtodd4.setdefaultcolor(color.white);
bodywhtodd4.setlineweight(2);
bodywhtodd4.hidebubble();

# white wicks
def wickwhtevenhi = if (show_shading and bigbareven and bodywht and wick) then bighi else na;
def wickwhtevenlo = if (show_shading and bigbareven and bodywht and wick) then biglo else na;
addcloud(wickwhtevenhi, wickwhtevenlo, color.white, color.white);

def wickwhtoddhi = if (show_shading and !bigbareven and bodywht and wick) then bighi else na;
def wickwhtoddlo = if (show_shading and !bigbareven and bodywht and wick) then biglo else na;
addcloud(wickwhtoddhi, wickwhtoddlo, color.white, color.white);

# --------------------------
# body color - even period
def bodytopeven4 = if show_shading and bigbareven then bigclose else na;
def bodyboteven4 = if show_shading and bigbareven then bigopen else na;
addcloud(bodytopeven4, bodyboteven4, GlobalColor("upshade1"), GlobalColor("downshade1"));
# body color - odd period
def bodytopodd4 = if show_shading and !bigbareven then bigclose else na;
def bodybotodd4 = if show_shading and !bigbareven then bigopen else na;
addcloud(bodytopodd4, bodybotodd4, GlobalColor("upshade1"), GlobalColor("downshade1"));
# --------------------------


# --------------------------
# wick color - green - even
def grnevenbodytop = if (show_shading and bigbareven and bodygrn and wick) then bodytop else na;
def grnevenbodybot = if (show_shading and bigbareven and bodygrn and wick) then bodybot else na;
# upper wick
addcloud(bighi, grnevenbodytop, GlobalColor("upshade1"), GlobalColor("upshade1"));
# lower wick
addcloud(grnevenbodybot, biglo, GlobalColor("upshade1"), GlobalColor("upshade1"));

# wick color - green - odd
def grnoddbodytop = if (show_shading and !bigbareven and bodygrn and wick) then bodytop else na;
def grnoddbodybot = if (show_shading and !bigbareven and bodygrn and wick) then bodybot else na;
# upper wick
addcloud(bighi, grnoddbodytop, GlobalColor("upshade1"), GlobalColor("upshade1"));
# lower wick
addcloud(grnoddbodybot, biglo, GlobalColor("upshade1"), GlobalColor("upshade1"));

# -------------------------
# wick color - red - even
def redevenbodytop = if (show_shading and bigbareven and bodyred and wick) then bodytop else na;
def redevenbodybot = if (show_shading and bigbareven and bodyred and wick) then bodybot else na;
# upper wick
addcloud(bighi, redevenbodytop, GlobalColor("downshade1"), GlobalColor("downshade1"));
# lower wick
addcloud(redevenbodybot, biglo, GlobalColor("downshade1"), GlobalColor("downshade1"));

# wick color - red - odd
def redoddbodytop = if (show_shading and !bigbareven and bodyred and wick) then bodytop else na;
def redoddbodybot = if (show_shading and !bigbareven and bodyred and wick) then bodybot else na;
# upper wick
addcloud(bighi, redoddbodytop, GlobalColor("downshade1"), GlobalColor("downshade1"));
# lower wick
addcloud(redoddbodybot, biglo, GlobalColor("downshade1"), GlobalColor("downshade1"));


# ----------------------------------
#  last period stuff

input period_bar_count_on_last_candle = yes;
def sbc = period_bar_count_on_last_candle;

# plot period bar count above last bar
plot q1 = if (sbc and lastbar and (perbarcnt <> bigbar)) then perbarcnt else na;
q1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
q1.SetDefaultColor(Color.white);
q1.hidebubble();

# plot period total bar count below last bar
plot q2 = if (sbc and lastbar and (perbarcnt <> bigbar)) then bigbar else na;
q2.SetPaintingStrategy(PaintingStrategy.VALUES_below);
q2.SetDefaultColor(Color.white);
q2.hidebubble();

input vert_line_on_last_period = yes;
def sl = vert_line_on_last_period;

def currlastbar = bigbarfirst[bigbar - 1];

def showlastvert = if (!isnan(bigopen) and isnan(bigclose)) then currlastbar else na;
# add offest so line is after the bar instead of in front of it
addverticalline(sl and showlastvert[1], "LAST BAR", color.LIGHT_gray, Curve.MEDIUM_DASH);

# -------------

def showlastvertbn = if showlastvert then bn else 0;
def currlastbarbn = highestall(showlastvertbn);
# define time for the last period
def lastper = if (isnan(bigclose) and bn >= bigbarfirstbn and bn <= currlastbarbn) then 1 else 0;
# plot line at open for current period

input open_close_lines_on_last_period = yes;
def lastperopen = if lastper then bigopen else na;
plot gg = if open_close_lines_on_last_period  then lastperopen else na;
gg.setdefaultcolor(color.gray);

# find close of last period
def lastperclose = if lastper then (HighestAll( if (!isnan(close[0]) and isnan(close[-1]), close, 0))) else na;
plot ccls = if open_close_lines_on_last_period then lastperclose else na;
ccls.setdefaultcolor(color.gray);

input shading_on_last_period = yes;
def currtop = if shading_on_last_period then lastperclose else na;
addcloud(currtop, lastperopen, GlobalColor("upshade1"), GlobalColor("downshade1"));

# ----------------------------------
# ----------------------------------
# test data ------------------------

# show barnumbers
#AddChartBubble(1, hi2, bn , Color.MAGENTA, yes);

# test - count of periods
#addchartbubble(1, low, bigbarcnt, color.cyan, no);

# plot a bubble under last bar , with period bar count / total bars
#addchartbubble(1, low*0.995, q1 + "\n" + q2, color.yellow, no);

input show_high_low_price_bubbles = no;
AddChartBubble(show_high_low_price_bubbles and mid and bigmulti, bighi, bighi, Color.gray, yes);
AddChartBubble(show_high_low_price_bubbles and mid and bigmulti, biglo, biglo, Color.gray, no);

input show_open_close_price_bubbles = no;
AddChartBubble(show_open_close_price_bubbles and bigbarfirst and bigmulti, bodytop, bodytop, Color.gray, yes);
AddChartBubble(show_open_close_price_bubbles and bigbarfirst and bigmulti, bodybot, bodybot, Color.gray, no);

input show_OHLC_bubbles = no;
AddChartBubble(show_OHLC_bubbles and bigbarfirst and bigmulti, lo2, "O " + bigopen + "\nH " + bighi + "\nL " + biglo + "\nC " + bigclose , Color.MAGENTA, no);

#input show_label_stats = yes;
# this shows n/a errors for current bars
#Addlabel(show_label_stats and bigmulti, "O " + bigopen + " H " + bighi + " L " + biglo + " C" + bigclose , Color.yellow);

#addchartbubble(1,low*0.995, bigbarfirstbn + "\n" + currlastbarbn + "\n" + currlastbar + "\n" + lastper + "\n" + lastbarbn + "\n" + lastbar, color.cyan, no);
#


inputs
8JKcBWH.jpg


DBX 78agg - 2min chart
yaLBqtx.jpg


OHLC price bubbles
S8FsfzA.jpg


last period
bar counts on last candle. vertical line for end of period. hal_agg hal_wide
eGZGcgN.jpg
 
Last edited:
Very nice, great job.

As for the other method you might have seen in other threads; the type where the bar is outlined and the wicks match the outline... The body is a single cloud, the top and bottom outline are the 'show border' parameter from the cloud. The left outline, right outline, and both wicks are drawn using the forgotten AddChart() function. However, in order to paint the vertical lines, you just use the high and low parameters, with the open and close parameters set to double.nan. Edit: Obligatory reminder, addchart() is a derelict function and will crash tos if used incorrectly.
 
Last edited:
Very nice, great job.

As for the other method you might have seen in other threads; the type where the bar is outlined and the wicks match the outline... The body is a single cloud, the top and bottom outline are the 'show border' parameter from the cloud. The left outline, right outline, and both wicks are drawn using the forgotten AddChart() function. However, in order to paint the vertical lines, you just use the high and low parameters, with the open and close parameters set to double.nan. Edit: Obligatory reminder, addchart() is a derelict function and will crash tos if used incorrectly.
thank you. i know about addchart. using addchart probably would make the code simpler, not needing odd/even sections. guess i'm just leary of using undocumented functions, that might stop working some day. i chose to draw the candles with clouds, because i like the look of wide wicks with wider candle bodies. i thought about scaling the wicks to be even wider, but didn't. i like experimenting to see how things can be done differently. sometimes usable code snippets come out of it.
 
You might be able calculate it using GetTime() but it would only be an estimate. At best I could draw a line at at least a minute or more since the last line. At worst, it wouldn't work at all, I am not even sure if those related functions even work on tick charts. Personally, I haven't use a tick chart in many years, so I would have to experiment with it, but I do not have the time at the moment.
 
You might be able calculate it using GetTime() but it would only be an estimate. At best I could draw a line at at least a minute or more since the last line. At worst, it wouldn't work at all, I am not even sure if those related functions even work on tick charts. Personally, I haven't use a tick chart in many years, so I would have to experiment with it, but I do not have the time at the moment.
All good. Thank you.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
245 Online
Create Post

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