Multi-TimeFrame Candles Overlay for ThinkOrSwim

This is not exactly what you requested, but may help. The code below should be added to the bottom of your code. It plots bubbles for highs/lows of the overlay candles with an option to just show the last ones. There are 3 types of bubbles, one for green, red and white in the original code. I left them separated as is.
Very close, I'm not code-saavy enough to work it out from there though. I'm not sure what the red bubbles are (or where they come from in the code), and it seems to show the current candle high/low. I tried to pick it apart to just show the previous candle high/low but couldn't figure it out.
 
Very close, I'm not code-saavy enough to work it out from there though. I'm not sure what the red bubbles are (or where they come from in the code), and it seems to show the current candle high/low. I tried to pick it apart to just show the previous candle high/low but couldn't figure it out.

Here is a version that displays current and/or prior bar's highs/lows of the overlay bars. There is an option to display the last bar only with that data.

Capture.jpg
Ruby:
#-----------------------------------------------------
#
#       S I M P L E
#    C A N D L E      O V E R L A Y
#
# Open line red/green for visualizing FTC
#
# updated by tickets2themoon
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
#
#-----------------------------------------------------
declare upper;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.FIFTEEN_MIN;
def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);
def NA = Double.NaN;

def modTime = GetTime() % Time_Frame;
def aggPeriod = GetAggregationPeriod();

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  Time_Frame / aggPeriod;

# Calculate ms of Middle bar from open on higher timeframe
def halfAgg;
if lowerTimeFrameBarCount % 2 == 0
then {
    halfAgg = (lowerTimeFrameBarCount / 2) * GetAggregationPeriod();
}
else {
    halfAgg = RoundDown(lowerTimeFrameBarCount / 2, 0) * GetAggregationPeriod();
}

# Determine the position of each bar in respect to Higher Time Frame
def barStart = if modTime == 0 then 1 else 0;
def barEnd = if modTime >= (Time_Frame - aggPeriod) then 1 else 0;
#Find the middle bar in the lower timeframe
def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;

def side;
if modTime < modTime[1]
then {
    if side[1] == 1
    then {
        side = 2;
    }
    else {
        side = 1;
    }
} else {
    side = side[1];
}
def sider = side;
def doji = C == O;


AddCloud(data1 = if (addcloud and sider == 2 and !doji) then O else Double.NaN, data2 = if (addcloud and sider == 2 and !doji) then C else Double.NaN, color1 = Color.LIGHT_RED, color2 = Color.LIGHT_GREEN, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 1 and !doji) then O else Double.NaN, data2 = if (addcloud and sider == 1 and !doji) then C else Double.NaN, color1 = Color.LIGHT_RED, color2 = Color.LIGHT_GREEN, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 1 and doji) then O else Double.NaN, data2 = if (addcloud and sider == 1 and doji) then C else Double.NaN, color1 = Color.WHITE, color2 = Color.WHITE, showBorder = yes);
AddCloud(data1 = if (addcloud and sider == 2 and doji) then O else Double.NaN, data2 = if (addcloud and sider == 2 and doji) then C else Double.NaN, color1 = Color.WHITE, color2 = Color.WHITE, showBorder = yes);
#plot barType = midBar;
#plot barType = Sync;
#barType.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#barType.AssignValueColor(color.WHITE);

### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;


def ubh = if up and midBar then H else nan;
def ubc = if up and midBar then C else nan;
def ubo = if up and midBar then O else nan;
def ubl = if up and midBar then L else nan;

def dbh = if !up and !doji and midBar then H else nan;
def dbc = if !up and !doji and midBar then C else nan;
def dbo = if !up and !doji and midBar then O else nan;
def dbl = if !up and !doji and midBar then L else nan;


def djbh = if doji and midBar then H else nan;
def djbc = if doji and midBar then C else nan;
def djbo = if doji and midBar then O else nan;
def djbl = if doji and midBar then L else nan;

#Capture Highs/Lows of Each Overlay Bar---------------------------------------------
def hh = if (up and midBar) or (!up and !doji and midBar) or (doji and midBar) then H else hh[1];
def ll = if (up and midBar) or (!up and !doji and midBar) or (doji and midBar) then L else ll[1];
#-----------------------------------------------------------------------------------

def sideuh = if up and openbar then C else nan;
def sideul = if up and openbar then O else nan;
def sidedh = if !up and !doji and openbar then O else nan;
def sidedl = if !up and !doji and openbar then C else nan;
def sidedjh = if doji and openbar then O else nan;
def sidedjl = if doji and openbar then C else nan;

#Draw Upper Wick Green
AddChart(high = ubh, low = ubc, open = NA, close = NA, type = ChartType.BAR , growcolor = if 1 then Color.LIGHT_GREEN else Color.LIGHT_GREEN);

#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);

#Draw Upper Wick White - Doji
AddChart(high = djbh, low = djbo, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);

#Draw Lower Wick Green
AddChart(high = ubo, low = ubl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);

#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);

#Draw Lower Wick White - Doji
AddChart(high = djbc, low = djbl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);

#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);


plot highs = ubh;
highs.SetPaintingStrategy(PaintingStrategy.POINTS);
highs.SetDefaultColor(Color.GREEN);
plot lhighs = dbh;
lhighs.SetPaintingStrategy(PaintingStrategy.POINTS);
lhighs.SetDefaultColor(Color.RED);
plot lows = ubl;
lows.SetPaintingStrategy(PaintingStrategy.POINTS);
lows.SetDefaultColor(Color.GREEN);
plot llows = dbl;
llows.SetPaintingStrategy(PaintingStrategy.POINTS);
llows.SetDefaultColor(Color.RED);


#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.LIGHT_GRAY);

# end



#High/low bubbles for the overlay candles

def bn = BarNumber();
def lastubh = HighestAll(if IsNaN(ubh[-1]) and !IsNaN(ubh) then bn else Double.NaN);
def lastdbh = HighestAll(if IsNaN(dbh[-1]) and !IsNaN(dbh) then bn else Double.NaN);
def lastdjbh = HighestAll(if IsNaN(djbh[-1]) and !IsNaN(djbh) then bn else Double.NaN);
def lasthigh = Max(lastubh, Max(lastdbh, lastdjbh));

input show_bubbles            = yes;
input show_CURRENT_highs_lows = yes;
input show_PRIOR_highs_lows   = yes;
input show_LAST_Bubble_only   = yes;

#Current Highs/Lows
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA
               else if show_LAST_Bubble_only then bn == lastubh and bn == lasthigh
               else ubh, ubh, "CH " + AsText(ubh), Color.GREEN);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows  then NA
               else if show_LAST_Bubble_only then bn == lastdjbh  and bn == lasthigh
               else djbh, djbh, "CH " + AsText(djbh), Color.WHITE);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows  then NA
               else if show_LAST_Bubble_only then bn == lastdbh  and bn == lasthigh
               else dbh, dbh, "CH " + AsText(dbh));
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows  then NA
               else if show_LAST_Bubble_only then bn == lastubh  and bn == lasthigh
               else ubl, ubl, "CL " + AsText(ubl), Color.GREEN, up = no);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows  then NA
               else if show_LAST_Bubble_only then bn == lastdjbh  and bn == lasthigh
               else djbl, djbl, "CL " + AsText(djbl), Color.WHITE, up = no);
AddChartBubble(if !show_bubbles or !show_CURRENT_highs_lows then NA                 
               else if show_LAST_Bubble_only then bn == lastdbh and bn == lasthigh             
               else dbl, dbl, "CL " + AsText(dbl), up = no);

#Previous High/Low
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA     
               else if show_LAST_Bubble_only then lasthigh == lastdbh and bn == lasthigh
               else dbh, dbh, "PH " + AsText(hh[1]), Color.RED);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA     
               else if show_LAST_Bubble_only then lasthigh == lastubh and bn == lasthigh
               else ubh, ubh, "PH " + AsText(hh[1]), Color.GREEN);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA     
               else if show_LAST_Bubble_only then lasthigh == lastdjbh and bn == lasthigh
               else djbh, djbh, "PH " + AsText(hh[1]), Color.WHITE);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA     
               else if show_LAST_Bubble_only then lasthigh == lastdbh and bn == lasthigh
               else dbl, dbl, "PL " + AsText(ll[1]), Color.RED, no);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA     
               else if show_LAST_Bubble_only then lasthigh == lastubh and bn == lasthigh
               else ubl, ubl, "PL " + AsText(ll[1]), Color.GREEN, no);
AddChartBubble(if !show_bubbles or !show_PRIOR_highs_lows then NA
               else if show_LAST_Bubble_only then lasthigh == lastdjbh and bn == lasthigh               
               else djbl, djbl, "PL " + AsText(ll[1]), Color.WHITE, no);
 
Is there any documentation on how to use these MTF charts. Thank you.
MTF Candle Overlays are generally used to save on real estate.
For example, you have 30 minute candlestick chart chart open and you also want to know what the price action is looking like in the 4hr chart and instead of switching back and forth between those two timeframes, all you need to do is just use the higher timeframe candlestick overlay indicator.
 
MTF Candle Overlays are generally used to save on real estate.
For example, you have 30 minute candlestick chart chart open and you also want to know what the price action is looking like in the 4hr chart and instead of switching back and forth between those two timeframes, all you need to do is just use the higher timeframe candlestick overlay indicator.

Thank you Merry Day. I would usually look at multiple charts and work from there. This is very helpful. Thank you.
 
this idea its really good, I just put this into my Daily chart and it give a great sense on the price direction. Love it!
everything in useThinkScrip is so easy that I cave man can do it!

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

def aggw = AggregationPeriod.WEEK;
def price = close(Period = aggw);
def displace = 0;
def length = 20;

def AvgExp = ExpAverage(price[-displace], length);
def h = high(period = aggw);
def l = low(period = aggw);

plot sUp = if price crosses above AvgExp then h else Double.NaN;
sUp.SetPaintingStrategy(PaintingStrategy.DASHES);
sUp.SetDefaultColor(Color.GREEN);
sUp.SetLineWeight(1);

plot sDn = if price crosses below AvgExp then l else Double.NaN;
sDn.SetPaintingStrategy(PaintingStrategy.DASHES);
sDn.SetDefaultColor(Color.RED);
sDn.SetLineWeight(1);
 
Last edited:
my idea continue and now I add some weekly over band signs into my daily chart, but I have a problem with the dashes, the way they looks. if you look at the picture they goes horizontal on those 5 days and really I would like to put them from the top of the tale of the first candle to the last one and same for the Botton signs when happen. if someone can give an idea where to find more information how to customize this I will appreciate?

Code:
def aggw = AggregationPeriod.WEEK;
def pricew = close(Period = aggw);
def length = 20;
def averageType = AverageType.EXPONENTIAL;
def DevUp = 2.7;
def DevDn = -2.7;

def sDev = StDev(data = pricew[-0], length = length);

def EMA20 = ExpAverage(pricew[-0], length);

def h = high(period = aggw);
def l = low(period = aggw);

plot sUp = if pricew crosses above EMA20 then h else Double.NaN;
sUp.SetPaintingStrategy(PaintingStrategy.DASHES);
sUp.SetDefaultColor(Color.GREEN);
sUp.SetLineWeight(5);

plot sDn = if pricew crosses below EMA20 then l else Double.NaN;
sDn.SetPaintingStrategy(PaintingStrategy.DASHES);
sDn.SetDefaultColor(Color.RED);
sDn.SetLineWeight(5);

def MidLine = MovingAverage(averageType, data = pricew[-0], length = length);
def LowerBand = MidLine + DevDn * sDev;
def UpperBand = MidLine + DevUp * sDev;

# Overband UP signal ##
plot oBand = if pricew > UpperBand then h else Double.NaN;
oBand.SetPaintingStrategy(PaintingStrategy.DASHES);
oBand.SetDefaultColor(Color.WHITE);
oBand.SetLineWeight(1);

# Lowerband DN signal ##
Plot bBand  = if pricew < LowerBand then l else Double.NaN;
bBand.SetPaintingStrategy(PaintingStrategy.DASHES);
bBand.SetDefaultColor(Color.WHITE);
bBand.SetLineWeight(1);

 
Last edited:
my idea continue and now I add some weekly over band signs into my daily chart, but I have a problem with the dashes, the way they looks. if you look at the picture they goes horizontal on those 5 days and really I would like to put them from the top of the tale of the first candle to the last one and same for the Botton signs when happen. if someone can give an idea where to find more information how to customize this I will appreciate?

Code:
def aggw = AggregationPeriod.WEEK;
def pricew = close(Period = aggw);
def length = 20;
def averageType = AverageType.EXPONENTIAL;
def DevUp = 2.7;
def DevDn = -2.7;

def sDev = StDev(data = pricew[-0], length = length);

def EMA20 = ExpAverage(pricew[-0], length);

def h = high(period = aggw);
def l = low(period = aggw);

plot sUp = if pricew crosses above EMA20 then h else Double.NaN;
sUp.SetPaintingStrategy(PaintingStrategy.DASHES);
sUp.SetDefaultColor(Color.GREEN);
sUp.SetLineWeight(5);

plot sDn = if pricew crosses below EMA20 then l else Double.NaN;
sDn.SetPaintingStrategy(PaintingStrategy.DASHES);
sDn.SetDefaultColor(Color.RED);
sDn.SetLineWeight(5);

def MidLine = MovingAverage(averageType, data = pricew[-0], length = length);
def LowerBand = MidLine + DevDn * sDev;
def UpperBand = MidLine + DevUp * sDev;

# Overband UP signal ##
plot oBand = if pricew > UpperBand then h else Double.NaN;
oBand.SetPaintingStrategy(PaintingStrategy.DASHES);
oBand.SetDefaultColor(Color.WHITE);
oBand.SetLineWeight(1);

# Lowerband DN signal ##
Plot bBand  = if pricew < LowerBand then l else Double.NaN;
bBand.SetPaintingStrategy(PaintingStrategy.DASHES);
bBand.SetDefaultColor(Color.WHITE);
bBand.SetLineWeight(1);


See if reversing the plot location of the oBand and bBand produce what you requested

Screenshot-2021-12-06-073225.jpg
Ruby:
def aggw = AggregationPeriod.WEEK;
def pricew = close(Period = aggw);
def length = 20;
def averageType = AverageType.EXPONENTIAL;
def DevUp = 2.7;
def DevDn = -2.7;

def sDev = StDev(data = pricew[-0], length = length);

def EMA20 = ExpAverage(pricew[-0], length);

def h = high(period = aggw);
def l = low(period = aggw);

plot sUp = if pricew crosses above EMA20 then l else Double.NaN;
sUp.SetPaintingStrategy(PaintingStrategy.DASHES);
sUp.SetDefaultColor(Color.GREEN);
sUp.SetLineWeight(5);

plot sDn = if pricew crosses below EMA20 then h else Double.NaN;
sDn.SetPaintingStrategy(PaintingStrategy.DASHES);
sDn.SetDefaultColor(Color.RED);
sDn.SetLineWeight(5);

def MidLine = MovingAverage(averageType, data = pricew[-0], length = length);
def LowerBand = MidLine + DevDn * sDev;
def UpperBand = MidLine + DevUp * sDev;

# Overband UP signal ##
plot oBand = if pricew > UpperBand then h else Double.NaN;
oBand.SetPaintingStrategy(PaintingStrategy.DASHES);
oBand.SetDefaultColor(Color.WHITE);
oBand.SetLineWeight(1);

# Lowerband DN signal ##
Plot bBand  = if pricew < LowerBand then l else Double.NaN;
bBand.SetPaintingStrategy(PaintingStrategy.DASHES);
bBand.SetDefaultColor(Color.WHITE);
bBand.SetLineWeight(1);
 
See if reversing the plot location of the oBand and bBand produce what you requested
Hi SleepyZ, yes I saw that I just have to change the high and low position thanks. Im stock in 3 little details in my chart and I would like to see if you can give again a hand to finish customizing the way my chart look

1) I have a column that display me the days remaining in my contract but display the days like this 40.0 and I want to see if I can remove the .0
This is code that I get from tos and I don't know if I can use a type of round number to do what I look
Code:
plot days = getdaystoexpiration()-1;

2)this is almost the same in quiestion 1, my RSI work fine but display to many digit something like this 50.45654, I would like to know if I can round to 2 digit after the dot
Code:
def RSI = 50 * (changeRatio + 1);

3)if Its a way to display in a watchlist column the qty of contract that I have on each companies?
 
Last edited:
Hi SleepyZ, yes I saw that I just have to change the high and low position thanks. Im stock in 3 little details in my chart and I would like to see if you can give again a hand to finish customizing the way my chart look

1) I have a column that display me the days remaining in my contract but display the days like this 40.0 and I want to see if I can remove the .0
This is code that I get from tos and I don't know if I can use a type of round number to do what I look
Code:
plot days = getdaystoexpiration()-1;

2)this is almost the same in quiestion 1, my RSI work fine but display to many digit something like this 50.45654, I would like to know if I can round to 2 digit after the dot
Code:
def RSI = 50 * (changeRatio + 1);

3)if Its a way to display in a watchlist column the qty of contract that I have on each companies?
Code:
def RSI = round(50 * (changeRatio + 1), 2) ;
 
Is there an easy way to adjust the width of the wicks? I would like to make them a little wider.
Thinkscript does not provide us any means to be interactive with the platform-controlled elements or any ThinkOrSwim modules...
 
Here is a version that displays current and/or prior bar's highs/lows of the overlay bars. There is an option to display the last bar only with that data.
Is it possible to have the candle overlay be one big square for the time period chosen and not have any wicks? For example - on a 5 min chart have 30 min overlay with all 6 candles in one 30 min box and no wicks?
 
Is it possible to have the candle overlay be one big square for the time period chosen and not have any wicks? For example - on a 5 min chart have 30 min overlay with all 6 candles in one 30 min box and no wicks?

The following script was modified to put a box around the input time_frame parameter from highs and lows only

Capture.jpg
Code:
#-----------------------------------------------------
#
#       S I M P L E
#    C A N D L E      O V E R L A Y
#
# Open line red/green for visualizing FTC
#
# updated by tickets2themoon
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
#
#-----------------------------------------------------
# Modified by sleepyz to put a box around time_frame high/low

DECLARE UPPER;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.thirty_MIN;
def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);
def NA = double.Nan;

def modTime = GetTime() % Time_Frame;
def aggPeriod = GetAggregationPeriod();

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  Time_Frame / aggPeriod;

# Calculate ms of Middle bar from open on higher timeframe
def halfAgg;
if lowerTimeFrameBarCount % 2 == 0 then {
    halfAgg = (lowerTimeFrameBarCount/2) * GetAggregationPeriod();
}
else {
    halfAgg = RoundDown(lowerTimeFrameBarCount/2,0) * GetAggregationPeriod();
}

# Determine the position of each bar in respect to Higher Time Frame
def barStart = if modTime == 0 then 1 else 0;
def barEnd = if modTime >= (Time_Frame - aggPeriod) then 1 else 0;
#Find the middle bar in the lower timeframe
def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;

def side;
if modTime < modTime[1] then{
    if side[1] == 1 then{
        side = 2;
    }
    else{
        side = 1;
    }
}else{
    side = side[1];
}
DEF sider = side;
def doji = C==O;

### making stuff up here drawing the wick through the middle candle.
def nan = double.nan;
def up = c > o;


def ubh = if up and midBar then h else nan;
def ubc = if up and midBar then h else nan;
def ubo = if up and midBar then l else nan;
def ubl = if up and midBar then l else nan;

def dbh = if !up and !doji and midBar then h else nan;
def dbc = if !up and !doji and midBar then h else nan;
def dbo = if !up and !doji and midBar then l else nan;
def dbl = if !up and !doji and midBar then l else nan;

def djbh = if doji and midBar then h else nan;
def djbc = if doji and midBar then h else nan;
def djbo = if doji and midBar then l else nan;
def djbl = if doji and midBar then l else nan;

def sideuh = if up and openbar then h else nan;
def sideul = if up and openbar then l else nan;
def sidedh = if !up and !doji and openbar then h else nan;
def sidedl = if !up and !doji and openbar then l else nan;
def sidedjh = if doji and openbar then h else nan;
def sidedjl = if doji and openbar then l else nan;



#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_GREEN);

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.bar, growcolor = color.LIGHT_RED);

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = na, close = na, type = ChartType.bar, growcolor = color.WHITE);


plot highs = h;
highs.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
highs.assignvalueColor(if o>c then color.red else color.green);

plot lows = l;
lows.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
lows.assignvalueColor(if o>c then color.red else color.green);



#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.light_Gray);

# end
 
The following script was modified to put a box around the input time_frame parameter from highs and lows only
SleepyZ: Thanks this is fantastic! Is it possible to have the green/red clouds for the high's and low's of the box? If not, it's fine the way it is.
 
SleepyZ: Thanks this is fantastic! Is it possible to have the green/red clouds for the high's and low's of the box? If not, it's fine the way it is.

Here is addition of an optional cloud color for the boxes

Capture.jpg

Ruby:
#-----------------------------------------------------
#
#       S I M P L E
#    C A N D L E      O V E R L A Y
#
# Open line red/green for visualizing FTC
#
# updated by tickets2themoon
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
#
#-----------------------------------------------------
# Modified by sleepyz to put a box around time_frame high/low

declare upper;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.THIRTY_MIN;
def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);
def NA = Double.NaN;

def modTime = GetTime() % Time_Frame;
def aggPeriod = GetAggregationPeriod();

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  Time_Frame / aggPeriod;

# Calculate ms of Middle bar from open on higher timeframe
def halfAgg;
if lowerTimeFrameBarCount % 2 == 0
then {
    halfAgg = (lowerTimeFrameBarCount / 2) * GetAggregationPeriod();
}
else {
    halfAgg = RoundDown(lowerTimeFrameBarCount / 2, 0) * GetAggregationPeriod();
}

# Determine the position of each bar in respect to Higher Time Frame
def barStart = if modTime == 0 then 1 else 0;
def barEnd = if modTime >= (Time_Frame - aggPeriod) then 1 else 0;
#Find the middle bar in the lower timeframe
def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;

def side;
if modTime < modTime[1]
then {
    if side[1] == 1
    then {
        side = 2;
    }
    else {
        side = 1;
    }
} else {
    side = side[1];
}
def sider = side;
def doji = C == O;

### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;


def ubh = if up and midBar then H else nan;
def ubc = if up and midBar then H else nan;
def ubo = if up and midBar then L else nan;
def ubl = if up and midBar then L else nan;

def dbh = if !up and !doji and midBar then H else nan;
def dbc = if !up and !doji and midBar then H else nan;
def dbo = if !up and !doji and midBar then L else nan;
def dbl = if !up and !doji and midBar then L else nan;

def djbh = if doji and midBar then H else nan;
def djbc = if doji and midBar then H else nan;
def djbo = if doji and midBar then L else nan;
def djbl = if doji and midBar then L else nan;

def sideuh = if up and openbar then H else nan;
def sideul = if up and openbar then L else nan;
def sidedh = if !up and !doji and openbar then H else nan;
def sidedl = if !up and !doji and openbar then L else nan;
def sidedjh = if doji and openbar then H else nan;
def sidedjl = if doji and openbar then L else nan;



#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);


plot highs = H;
highs.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
highs.AssignValueColor(if O > C then Color.RED else Color.GREEN);

plot lows = L;
lows.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lows.AssignValueColor(if O > C then Color.RED else Color.GREEN);

input show_cloud = yes;
DefineGlobalColor("Up", Color.LIGHT_GREEN);
DefineGlobalColor("Dn", Color.LIGHT_RED);
AddCloud(if !show_cloud or sider[1] != sider[0] then Double.NaN else if O < C then H else Double.NaN, L, GlobalColor("Up"), GlobalColor("Up"));
AddCloud(if !show_cloud or sider[1] != sider[0] then Double.NaN else if O > C then H else Double.NaN, L, GlobalColor("Dn"), GlobalColor("Dn"));
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O < C then H else Double.NaN, L, GlobalColor("Up"), GlobalColor("Up"));
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O > C then H else Double.NaN, L, GlobalColor("Dn"), GlobalColor("Dn"));

#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.LIGHT_GRAY);

# end
 
Last edited:
Here is addition of an optional cloud color for the boxes

Capture.jpg
Ruby:
#-----------------------------------------------------
#
#       S I M P L E
#    C A N D L E      O V E R L A Y
#
# Open line red/green for visualizing FTC
#
# updated by tickets2themoon
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
#
#-----------------------------------------------------
# Modified by sleepyz to put a box around time_frame high/low

declare upper;
#------------------------------------
# MTF SECTION
#------------------------------------
input Time_Frame = AggregationPeriod.THIRTY_MIN;
def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);
def NA = Double.NaN;

def modTime = GetTime() % Time_Frame;
def aggPeriod = GetAggregationPeriod();

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  Time_Frame / aggPeriod;

# Calculate ms of Middle bar from open on higher timeframe
def halfAgg;
if lowerTimeFrameBarCount % 2 == 0
then {
    halfAgg = (lowerTimeFrameBarCount / 2) * GetAggregationPeriod();
}
else {
    halfAgg = RoundDown(lowerTimeFrameBarCount / 2, 0) * GetAggregationPeriod();
}

# Determine the position of each bar in respect to Higher Time Frame
def barStart = if modTime == 0 then 1 else 0;
def barEnd = if modTime >= (Time_Frame - aggPeriod) then 1 else 0;
#Find the middle bar in the lower timeframe
def midBar = if modTime == halfAgg then 1 else 0;
#If start or end of bar - used to draw side border of candle body
def openbar = if barStart or barEnd then 1 else 0;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;

def side;
if modTime < modTime[1]
then {
    if side[1] == 1
    then {
        side = 2;
    }
    else {
        side = 1;
    }
} else {
    side = side[1];
}
def sider = side;
def doji = C == O;

### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;


def ubh = if up and midBar then H else nan;
def ubc = if up and midBar then H else nan;
def ubo = if up and midBar then L else nan;
def ubl = if up and midBar then L else nan;

def dbh = if !up and !doji and midBar then H else nan;
def dbc = if !up and !doji and midBar then H else nan;
def dbo = if !up and !doji and midBar then L else nan;
def dbl = if !up and !doji and midBar then L else nan;

def djbh = if doji and midBar then H else nan;
def djbc = if doji and midBar then H else nan;
def djbo = if doji and midBar then L else nan;
def djbl = if doji and midBar then L else nan;

def sideuh = if up and openbar then H else nan;
def sideul = if up and openbar then L else nan;
def sidedh = if !up and !doji and openbar then H else nan;
def sidedl = if !up and !doji and openbar then L else nan;
def sidedjh = if doji and openbar then H else nan;
def sidedjl = if doji and openbar then L else nan;



#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_GREEN);

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.LIGHT_RED);

#Draw Side of Body White
AddChart(high = sidedjh, low = sidedjl, open = NA, close = NA, type = ChartType.BAR, growcolor = Color.WHITE);


plot highs = H;
highs.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
highs.AssignValueColor(if O > C then Color.RED else Color.GREEN);

plot lows = L;
lows.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lows.AssignValueColor(if O > C then Color.RED else Color.GREEN);

input show_cloud = yes;
DefineGlobalColor("Up", Color.LIGHT_GREEN);
DefineGlobalColor("Dn", Color.LIGHT_RED);
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O < C then H else Double.NaN, L, GlobalColor("Up"), GlobalColor("Up"));
AddCloud(if !show_cloud or sider != sider[-1] then Double.NaN else if O > C then H else Double.NaN, L, GlobalColor("Dn"), GlobalColor("Dn"));

#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = yes;
AddLabel(Show_Label, Concat(if Time_Frame < 3600000 then Time_Frame / 60000 + "m" else if Time_Frame < 86400000 then Time_Frame / 3600000 + "h" else if Time_Frame < 604800000 then Time_Frame / 86400000 + "D" else if Time_Frame < 2592000000 then Time_Frame / 604800000 + "Wk" else if Time_Frame < 31536000000 then Time_Frame / 2592000000 + "Mo" else Time_Frame / 31536000000 + "Yr", if Time_Frame then " CANDLES" else ""), Color.LIGHT_GRAY);

# end
SleepyZ - Thank you!!!
 
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
Can you please add 8hr time frame too ? ?Thanks
 
Regrettably, the aggregations used in the script are limited to what preset one's TOS provides. It does not allow custom aggregations at this time like the 8hr you requested.
hey SleepyZ Im looking for this indicator to start the agg period during RTH even with the after hours and pre market sessions showing.. as is, the hour candles draw the closing price line at 7am, 8am etc.. Hoping for them to plot on the half hours! Thanks in advance
 

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
171 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