Multi-TimeFrame Candles Overlay for ThinkOrSwim

Is there a simple basic MTF overlay for the candles? I dont need mult lines drawn within, or top/bottom wicks cut off, or cloud/ribbons tying them together, just a simple overlay?
YES I have tried a cpl incl Townsends orig etc, Im just looking for something without bells and whistles that simply paints the full MTF candle
 

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

Yeah for sure @Trading51 , even though it is accessible from importing that link.

Code:
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;


#------------------------------------
# ADD CLOUDS
#------------------------------------
input addcloud = yes;
def side = if side[1] == 1 then 2 else 1;
DEF sider = side;
AddCloud( if sider == 2 then O else Double.NaN, if sider == 2 then C else Double.NaN, COLOR.light_Red, COLOR.light_Green);
AddCloud( if sider == 1 then O else Double.NaN, if sider == 1 then C else Double.NaN, COLOR.light_red, COLOR.light_green);

Def newbar = if O != O[1] then 1 else 0;

# Number of bars within the lower timeframe
def lowerTimeFrameBarCount =  Time_Frame / 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;

def openbar = if lowerTimeFrameBarCount % 2 == 0 then LowertimeFrameBarCount else LowerTimeFrameBarCount - 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;
def bb = c > o;



AddChart(if bb then hb else na, if bb then lb else na, if bb then o else na, if bb then c else na, type = ChartType.bar, growcolor = color.light_green );

AddChart( if !bb then hb else na, if !bb then lb else na, if !bb then o else na, if !bb then c else na, type = ChartType.Bar, growColor = color.Light_red);



plot highs = if bb then hb else na;
highs.setpaintingStrategy(PaintingStrategy.POINTS);
highs.setDefaultColor(Color.Green);

plot lhighs = if !bb then hb else na;
lhighs.setpaintingStrategy(paintingstrategy.points);
lhighs.setdefaultColor(Color.Red);

plot lows = if bb then lb else na;
lows.setpaintingStrategy(PaintingStrategy.Points);
lows.setdefaultColor(Color.Green);

plot llows = if !bb then lb else na;
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
How do you make this include the whole bar? I dunno why so many studies are cutting the wicks off?
 
How do you make this include the whole bar? I dunno why so many studies are cutting the wicks off?

This colors the MTF Candle Overlay from High to Low

Screenshot-2023-01-24-163315.png

Ruby:
#CandleOverlay_MTF_Using_VolumeProfile
input ShowTodayOnly = { default "No", "Yes"};
input showbubbles   = yes;
input aggperiod     = {"1 MIN", "2 MIN", "3 MIN", "5 MIN", "10 MIN", "15 MIN", "30 MIN", "1 HOUR", default "DAY", "WEEK", "MONTH", "YEAR"};
input displace      = 0;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);

switch (aggperiod) {
case "1 MIN":
    period = Floor(seconds / 60 + day_number * 24 * 60);
case "2 MIN":
    period = Floor(seconds / 120 + day_number * 24);
case "3 MIN":
    period = Floor(seconds / 180 + day_number * 24);
case "5 MIN":
    period = Floor(seconds / 300 + day_number * 24);
case "10 MIN":
    period = Floor(seconds / 600 + day_number * 24);
case "15 MIN":
    period = Floor(seconds / 900 + day_number * 24);
case "30 MIN":
    period = Floor(seconds / 1800 + day_number * 24);
case "1 HOUR":
    period = Floor(seconds / 3600 + day_number * 24);
case "DAY":
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case "WEEK":
    period = Floor(day_number / 7);
case "MONTH":
    period = Floor(month - First(month));
case "YEAR":
    period = GetYear();
}
def bn = BarNumber();
def na = Double.NaN;
def o  = open(period = aggperiod)[displace];
def c  = close(period = aggperiod)[displace];
def r  = if period != period[1] then 0 else 1;
def b  = if period != period[1] then bn else b[1];
def xb = b;

plot ORH = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else high(period = aggperiod)[displace];
plot ORL = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else  low(period = aggperiod)[displace];

ORH.AssignValueColor(if c > o then Color.GREEN else if c < o then Color.RED else Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetLineWeight(2);

ORL.AssignValueColor(if c > o then Color.GREEN else if c < o then Color.RED else Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetLineWeight(2);


input showcloud = yes;
AddCloud( if showcloud and r and c > o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and r and c < o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and r and c == o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.WHITE, Color.WHITE);

AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c > o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c < o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c == o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.WHITE, Color.WHITE);
 
Last edited:
How do you set it to color all five bars if its set on 5min?

This colors the cloud over the MTF bar's high/low

Screenshot-2023-01-26-123113.png

Ruby:
#CandleOverlay_MTF_Using_VolumeProfile
input ShowTodayOnly = { default "No", "Yes"};
input showbubbles   = yes;
input aggperiod     = {"1 MIN", "2 MIN", "3 MIN", "5 MIN", "10 MIN", "15 MIN", "30 MIN", "1 HOUR", default "DAY", "WEEK", "MONTH", "QUARTER", "YEAR"};
input displace      = 0;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
    def qtr = (GetMonth() - 1 ) % 3;
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);

switch (aggperiod) {
case "1 MIN":
    period = Floor(seconds / 60 + day_number * 24 * 60);
case "2 MIN":
    period = Floor(seconds / 120 + day_number * 24);
case "3 MIN":
    period = Floor(seconds / 180 + day_number * 24);
case "5 MIN":
    period = Floor(seconds / 300 + day_number * 24);
case "10 MIN":
    period = Floor(seconds / 600 + day_number * 24);
case "15 MIN":
    period = Floor(seconds / 900 + day_number * 24);
case "30 MIN":
    period = Floor(seconds / 1800 + day_number * 24);
case "1 HOUR":
    period = Floor(seconds / 3600 + day_number * 24);
case "DAY":
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case "WEEK":
    period = Floor(day_number / 7);
case "MONTH":
    period = Floor(month - First(month));
case QUARTER:
    period = qtr == 0 and qtr[1] != 0;
case "YEAR":
    period = GetYear();
}
def bn = BarNumber();
def na = Double.NaN;
def o  = open(period = aggperiod)[displace];
def c  = close(period = aggperiod)[displace];
def r  = if period != period[1] then 0 else 1;
def b  = if period != period[1] then bn else b[1];
def xb = b;

plot ORH = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else high(period = aggperiod)[displace];
plot ORL = if ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else  low(period = aggperiod)[displace];

ORH.AssignValueColor(if c > o then Color.GREEN else if c < o then Color.RED else Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetLineWeight(2);

ORL.AssignValueColor(if c > o then Color.GREEN else if c < o then Color.RED else Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetLineWeight(2);


input showcloud = yes;
AddCloud( if showcloud and r and c > o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and r and c < o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and r and c == o then ORH else Double.NaN, if r then ORL else Double.NaN,  Color.WHITE, Color.WHITE);

AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c > o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.GREEN, Color.GREEN);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c < o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.RED, Color.RED);
AddCloud( if showcloud and Between(bn, xb - 1, xb + 1) and c == o then ORH else Double.NaN, if Between(bn, xb - 1, xb + 1) then ORL else Double.NaN,  Color.WHITE, Color.WHITE);
 
Last edited:
Regrettably, there is not an opacity option for the cloud function. You can try to use lighter colors than those in the script as one option.
so not even able to change the transparency of the color, like you can when selecting the color in the HSV tab?
 
so not even able to change the transparency of the color, like you can when selecting the color in the HSV tab?
TOS does not provide opacity for clouds. It does for profiles such as volume profile, so they know how. We have made requests for this functionality to TOS Support
 
is it possible for you to edit this script to make it be able to cloud the wicks as well?

# +------------------------------------------------------------+
# | Higher Time Frame Candles |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
def bn = BarNumber();
def lastBar = HighestAll(if !IsNaN(close) then bn else 0);
input higherTimeFrame = AggregationPeriod.HOUR;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
def isUP = xO < xC;
def isDN = xO > xC;
def isDoji = xO == xC;

DefineGlobalColor("border up", Color.white);
DefineGlobalColor("border down", Color.DARK_RED);
DefineGlobalColor("fill up", Color.GRAY);
DefineGlobalColor("fill down", Color.PINK);

def newCandle = xO <> xO[1] and xH <> xH[1] and xL <> xL[1] and xC <> xC[1];
def osc = CompoundValue(1, if newCandle then osc[1] * -1 else osc[1], 1);
def o1 = if osc > 0 and bn <= lastBar then xO else Double.NaN;
def c1 = if osc > 0 and bn <= lastBar then xC else Double.NaN;
def o2 = if osc < 0 and bn <= lastBar then xO else Double.NaN;
def c2 = if osc < 0 and bn <= lastBar then xC else Double.NaN;

def x = if IsNaN(o1) then 0 else 1;
def start = (bn == 1 or x <> x[1]) and bn <= lastBar;
def end = bn == lastBar or start[-1];
AddCloud(o1, c1, GlobalColor("fill down"), GlobalColor("fill up"));
AddCloud(o2, c2, GlobalColor("fill down"), GlobalColor("fill up"));

plot candleOpen = if start or end or IsNaN(close) then Double.NaN else xO;
candleOpen.SetPaintingStrategy(12);
candleOpen.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));
plot candleClose = if start or end or IsNaN(close) then Double.NaN else xC;
candleClose.SetPaintingStrategy(12);
candleClose.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));

def osr = CompoundValue(1, osr[1] + 2, bn - lastBar);
def cnt = if start then 1 else cnt[1] + 1;
def n = htf / GetAggregationPeriod();
def mid = if end then Round(cnt / 2, 0) else 2;
def getMid = fold i = 0 to n with a = 0 while a == 0 do if GetValue(end, -i) == 1 then GetValue(mid, -i) else 0;
input showWicks = yes;
def wick = showWicks and cnt == getMid;
#up candles
def uOt = if isUP and end then xC else Double.NaN;
def uOb = if isUP and end then xO else Double.NaN;
def uHs = if isUP and start then xC else if isUP and wick then xH else Double.NaN;
def uHe = if isUP and end then xC else if isUP and wick then Min(xO, xC) else Double.NaN;
def uLs = if isUP and start then xO else if isUP and wick then Max(xO, xC) else Double.NaN;
def uLe = if isUP and end then xO else if isUP and wick then xL else Double.NaN;
def uCt = if isUP and start then xC else Double.NaN;
def uCb = if isUP and start then xO else Double.NaN;
AddChart(uHs, uLs, uOt, uCt, ChartType.BAR, GlobalColor("border up"));
AddChart(uHs, uLs, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
#down candles
def dOt = if isDN and end then xC else Double.NaN;
def dOb = if isDN and end then xO else Double.NaN;
def dHs = if isDN and start then xC else if isDN and wick then xH else Double.NaN;
def dHe = if isDN and end then xC else if isDN and wick then Min(xO, xC) else Double.NaN;
def dLs = if isDN and start then xO else if isDN and wick then Max(xO, xC) else Double.NaN;
def dLe = if isDN and end then xO else if isDN and wick then xL else Double.NaN;
def dCt = if isDN and start then xC else Double.NaN;
def dCb = if isDN and start then xO else Double.NaN;
AddChart(dHs, dLs, dOt, dCt, ChartType.BAR, GlobalColor("border down"));
AddChart(dHs, dLs, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));

plot upperDot = if wick then xH else Double.NaN;
upperDot.SetPaintingStrategy(PaintingStrategy.POINTS);
upperDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
upperDot.SetLineWeight(2);
plot lowerDot = if wick then xL else Double.NaN;
lowerDot.SetPaintingStrategy(PaintingStrategy.POINTS);
lowerDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
lowerDot.SetLineWeight(2);

#Display Chart Time Frame
input showLabels = yes;

DefineGlobalColor("label color", CreateColor(35, 102, 160));
def nMinutes = GetAggregationPeriod() / 60000;
def Monthly = nMinutes == 43200;
def Weekly = nMinutes == 10080;
def Daily = nMinutes == 1440;
def Intraday = nMinutes < 1440 and nMinutes >= 1;
def nMinutes2 = htf / 60000;
def Monthly2 = nMinutes2 == 43200;
def Weekly2 = nMinutes2 == 10080;
def Daily2 = nMinutes2 == 1440;
def Intraday2 = nMinutes2 < 1440 and nMinutes2 >= 1;

AddLabel(showLabels, GetSymbol(), GlobalColor("label color" ));
AddLabel(showLabels and Monthly, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday, nMinutes + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "with", GlobalColor("label color"));
AddLabel(showLabels and Monthly2, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly2, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily2, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday2, nMinutes2 + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "overlay", GlobalColor("label color"));
 
is it possible for you to edit this script to make it be able to cloud the wicks as well?

# +------------------------------------------------------------+
# | Higher Time Frame Candles |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
def bn = BarNumber();
def lastBar = HighestAll(if !IsNaN(close) then bn else 0);
input higherTimeFrame = AggregationPeriod.HOUR;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
def isUP = xO < xC;
def isDN = xO > xC;
def isDoji = xO == xC;

DefineGlobalColor("border up", Color.white);
DefineGlobalColor("border down", Color.DARK_RED);
DefineGlobalColor("fill up", Color.GRAY);
DefineGlobalColor("fill down", Color.PINK);

def newCandle = xO <> xO[1] and xH <> xH[1] and xL <> xL[1] and xC <> xC[1];
def osc = CompoundValue(1, if newCandle then osc[1] * -1 else osc[1], 1);
def o1 = if osc > 0 and bn <= lastBar then xO else Double.NaN;
def c1 = if osc > 0 and bn <= lastBar then xC else Double.NaN;
def o2 = if osc < 0 and bn <= lastBar then xO else Double.NaN;
def c2 = if osc < 0 and bn <= lastBar then xC else Double.NaN;

def x = if IsNaN(o1) then 0 else 1;
def start = (bn == 1 or x <> x[1]) and bn <= lastBar;
def end = bn == lastBar or start[-1];
AddCloud(o1, c1, GlobalColor("fill down"), GlobalColor("fill up"));
AddCloud(o2, c2, GlobalColor("fill down"), GlobalColor("fill up"));

plot candleOpen = if start or end or IsNaN(close) then Double.NaN else xO;
candleOpen.SetPaintingStrategy(12);
candleOpen.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));
plot candleClose = if start or end or IsNaN(close) then Double.NaN else xC;
candleClose.SetPaintingStrategy(12);
candleClose.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));

def osr = CompoundValue(1, osr[1] + 2, bn - lastBar);
def cnt = if start then 1 else cnt[1] + 1;
def n = htf / GetAggregationPeriod();
def mid = if end then Round(cnt / 2, 0) else 2;
def getMid = fold i = 0 to n with a = 0 while a == 0 do if GetValue(end, -i) == 1 then GetValue(mid, -i) else 0;
input showWicks = yes;
def wick = showWicks and cnt == getMid;
#up candles
def uOt = if isUP and end then xC else Double.NaN;
def uOb = if isUP and end then xO else Double.NaN;
def uHs = if isUP and start then xC else if isUP and wick then xH else Double.NaN;
def uHe = if isUP and end then xC else if isUP and wick then Min(xO, xC) else Double.NaN;
def uLs = if isUP and start then xO else if isUP and wick then Max(xO, xC) else Double.NaN;
def uLe = if isUP and end then xO else if isUP and wick then xL else Double.NaN;
def uCt = if isUP and start then xC else Double.NaN;
def uCb = if isUP and start then xO else Double.NaN;
AddChart(uHs, uLs, uOt, uCt, ChartType.BAR, GlobalColor("border up"));
AddChart(uHs, uLs, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
#down candles
def dOt = if isDN and end then xC else Double.NaN;
def dOb = if isDN and end then xO else Double.NaN;
def dHs = if isDN and start then xC else if isDN and wick then xH else Double.NaN;
def dHe = if isDN and end then xC else if isDN and wick then Min(xO, xC) else Double.NaN;
def dLs = if isDN and start then xO else if isDN and wick then Max(xO, xC) else Double.NaN;
def dLe = if isDN and end then xO else if isDN and wick then xL else Double.NaN;
def dCt = if isDN and start then xC else Double.NaN;
def dCb = if isDN and start then xO else Double.NaN;
AddChart(dHs, dLs, dOt, dCt, ChartType.BAR, GlobalColor("border down"));
AddChart(dHs, dLs, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));

plot upperDot = if wick then xH else Double.NaN;
upperDot.SetPaintingStrategy(PaintingStrategy.POINTS);
upperDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
upperDot.SetLineWeight(2);
plot lowerDot = if wick then xL else Double.NaN;
lowerDot.SetPaintingStrategy(PaintingStrategy.POINTS);
lowerDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
lowerDot.SetLineWeight(2);

#Display Chart Time Frame
input showLabels = yes;

DefineGlobalColor("label color", CreateColor(35, 102, 160));
def nMinutes = GetAggregationPeriod() / 60000;
def Monthly = nMinutes == 43200;
def Weekly = nMinutes == 10080;
def Daily = nMinutes == 1440;
def Intraday = nMinutes < 1440 and nMinutes >= 1;
def nMinutes2 = htf / 60000;
def Monthly2 = nMinutes2 == 43200;
def Weekly2 = nMinutes2 == 10080;
def Daily2 = nMinutes2 == 1440;
def Intraday2 = nMinutes2 < 1440 and nMinutes2 >= 1;

AddLabel(showLabels, GetSymbol(), GlobalColor("label color" ));
AddLabel(showLabels and Monthly, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday, nMinutes + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "with", GlobalColor("label color"));
AddLabel(showLabels and Monthly2, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly2, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily2, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday2, nMinutes2 + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "overlay", GlobalColor("label color"));

This will show clouds between the wicks and the body of the candle. You can change the color to your liking at the global color input screen.

Screenshot-2023-02-24-152359.png
Code:
# +------------------------------------------------------------+
# | Higher Time Frame Candles |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
def bn = BarNumber();
def lastBar = HighestAll(if !IsNaN(close) then bn else 0);
input higherTimeFrame = AggregationPeriod.HOUR;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
def isUP = xO < xC;
def isDN = xO > xC;
def isDoji = xO == xC;



DefineGlobalColor("border up", Color.white);
DefineGlobalColor("border down", Color.DARK_RED);
DefineGlobalColor("fill up", Color.GRAY);
DefineGlobalColor("fill down", Color.PINK);

def newCandle = xO <> xO[1] and xH <> xH[1] and xL <> xL[1] and xC <> xC[1];
def osc = CompoundValue(1, if newCandle then osc[1] * -1 else osc[1], 1);
def o1 = if osc > 0 and bn <= lastBar then xO else Double.NaN;
def c1 = if osc > 0 and bn <= lastBar then xC else Double.NaN;
def o2 = if osc < 0 and bn <= lastBar then xO else Double.NaN;
def c2 = if osc < 0 and bn <= lastBar then xC else Double.NaN;

def x = if IsNaN(o1) then 0 else 1;
def start = (bn == 1 or x <> x[1]) and bn <= lastBar;
def end = bn == lastBar or start[-1];
AddCloud(o1, c1, GlobalColor("fill down"), GlobalColor("fill up"));
AddCloud(o2, c2, GlobalColor("fill down"), GlobalColor("fill up"));

defineglobalColor("Wicks",color.cyan);
addcloud(xH, max(O1, C1), globalColor("Wicks"), globalColor("Wicks"));
addcloud(xH, max(O2, C2), globalColor("Wicks"), globalColor("Wicks"));
addcloud(min(O1, C1), xL, globalColor("Wicks"), globalColor("Wicks"));
addcloud(min(O2, C2), xL, globalColor("Wicks"), globalColor("Wicks"));

plot candleOpen = if start or end or IsNaN(close) then Double.NaN else xO;
candleOpen.SetPaintingStrategy(12);
candleOpen.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));
plot candleClose = if start or end or IsNaN(close) then Double.NaN else xC;
candleClose.SetPaintingStrategy(12);
candleClose.AssignValueColor(if xO < xC then GlobalColor("border up") else GlobalColor("border down"));

def osr = CompoundValue(1, osr[1] + 2, bn - lastBar);
def cnt = if start then 1 else cnt[1] + 1;
def n = htf / GetAggregationPeriod();
def mid = if end then Round(cnt / 2, 0) else 2;
def getMid = fold i = 0 to n with a = 0 while a == 0 do if GetValue(end, -i) == 1 then GetValue(mid, -i) else 0;
input showWicks = yes;
def wick = showWicks and cnt == getMid;
#up candles
def uOt = if isUP and end then xC else Double.NaN;
def uOb = if isUP and end then xO else Double.NaN;
def uHs = if isUP and start then xC else if isUP and wick then xH else Double.NaN;
def uHe = if isUP and end then xC else if isUP and wick then Min(xO, xC) else Double.NaN;
def uLs = if isUP and start then xO else if isUP and wick then Max(xO, xC) else Double.NaN;
def uLe = if isUP and end then xO else if isUP and wick then xL else Double.NaN;
def uCt = if isUP and start then xC else Double.NaN;
def uCb = if isUP and start then xO else Double.NaN;
AddChart(uHs, uLs, uOt, uCt, ChartType.BAR, GlobalColor("border up"));
AddChart(uHs, uLs, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
AddChart(uHe, uLe, uOb, uCb, ChartType.BAR, GlobalColor("border up"));
#down candles
def dOt = if isDN and end then xC else Double.NaN;
def dOb = if isDN and end then xO else Double.NaN;
def dHs = if isDN and start then xC else if isDN and wick then xH else Double.NaN;
def dHe = if isDN and end then xC else if isDN and wick then Min(xO, xC) else Double.NaN;
def dLs = if isDN and start then xO else if isDN and wick then Max(xO, xC) else Double.NaN;
def dLe = if isDN and end then xO else if isDN and wick then xL else Double.NaN;
def dCt = if isDN and start then xC else Double.NaN;
def dCb = if isDN and start then xO else Double.NaN;
AddChart(dHs, dLs, dOt, dCt, ChartType.BAR, GlobalColor("border down"));
AddChart(dHs, dLs, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));
AddChart(dHe, dLe, dOb, dCb, ChartType.BAR, GlobalColor("border down"));

plot upperDot = if wick then xH else Double.NaN;
upperDot.SetPaintingStrategy(PaintingStrategy.POINTS);
upperDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
upperDot.SetLineWeight(3);
plot lowerDot = if wick then xL else Double.NaN;
lowerDot.SetPaintingStrategy(PaintingStrategy.POINTS);
lowerDot.AssignValueColor(if isUP then GlobalColor("border up") else GlobalColor("border down"));
lowerDot.SetLineWeight(3);

#Display Chart Time Frame
input showLabels = yes;

DefineGlobalColor("label color", CreateColor(35, 102, 160));
def nMinutes = GetAggregationPeriod() / 60000;
def Monthly = nMinutes == 43200;
def Weekly = nMinutes == 10080;
def Daily = nMinutes == 1440;
def Intraday = nMinutes < 1440 and nMinutes >= 1;
def nMinutes2 = htf / 60000;
def Monthly2 = nMinutes2 == 43200;
def Weekly2 = nMinutes2 == 10080;
def Daily2 = nMinutes2 == 1440;
def Intraday2 = nMinutes2 < 1440 and nMinutes2 >= 1;

AddLabel(showLabels, GetSymbol(), GlobalColor("label color" ));
AddLabel(showLabels and Monthly, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday, nMinutes + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "with", GlobalColor("label color"));
AddLabel(showLabels and Monthly2, "Monthly", GlobalColor("label color" ));
AddLabel(showLabels and Weekly2, "Weekly", GlobalColor("label color" ));
AddLabel(showLabels and Daily2, "Daily", GlobalColor("label color" ));
AddLabel(showLabels and Intraday2, nMinutes2 + " Minute", GlobalColor("label color" ));
AddLabel(showLabels, "overlay", GlobalColor("label color"));
 
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.
Thanks for the code. Is it possible to overlay 15min candles on a tick chart? Thanks.
 
Thanks for the code. Is it possible to overlay 15min candles on a tick chart? Thanks.
Aggregations cannot be used on tick charts. The tick charts x and y-axis only use data related to price and volume lots. It has no comprehension of intraday time.
Therefore, it is NOT possible to plot based on 15 min while on your current chart is on Tick.
 
This is so dope! I don't suppose you or someone could make Previous Candle High/Low bubbles over the previous 5min candle for these like the ones here: https://usethinkscript.com/threads/previous-candle-high-low-labels-bubbles-for-thinkorswim.10422/

I made a variation of yours where you can change the color and more importantly transparency of the candles, 50% transparency helps a lot!
To change transparency/custom colors: Click on the Options gear, then open Globals (at the bottom), then click a color and choose 'More', then under the HSL tab you will find the transparency option. NOTE: When you change this ToS will go graphically bonkers (bug), just navigate through it (you can dip the screen below your windows toolbar to kind of reset the view), and once set and saved restart ToS to get rid of the funk.

View attachment 12330

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 and Wiinii
# based on STRAT study by Ramon DV. aka Pelonsax
# based on Rob Smith's The STRAT
# Original Candle Overlay concept by Paul Townsend
# Highly modified by Wiinii with help from SleepyZ
# https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/page-6#post-80502
#-----------------------------------------------------
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;
 
DefineGlobalColor("Green_Candle", Color.green);
DefineGlobalColor("Red_Candle", Color.red);

AddCloud( if (addcloud and sider == 2 and !doji) then O else Double.NaN, if (addcloud and sider == 2 and !doji) then C else Double.NaN, GlobalColor("Red_Candle"), GlobalColor("Green_Candle"), yes);
AddCloud( if (addcloud and sider == 1 and !doji) then O else Double.NaN, if (addcloud and sider == 1 and !doji) then C else Double.NaN, GlobalColor("Red_Candle"), GlobalColor("Green_Candle"), yes);
AddCloud( if (addcloud and sider == 1 and doji) then O else Double.NaN, if (addcloud and sider == 1 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, yes);
AddCloud( if (addcloud and sider == 2 and doji) then O else Double.NaN, if (addcloud and sider == 2 and doji) then C else Double.NaN, Color.WHITE, Color.WHITE, 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 GlobalColor("Green_Candle") else GlobalColor("Green_Candle"));

#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.bar, growcolor = GlobalColor("Red_Candle"));

#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 = GlobalColor("Green_Candle"));

#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.bar, growcolor = GlobalColor("Red_Candle"));

#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 = GlobalColor("Green_Candle"));

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

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

plot GC_High = ubh;
GC_High.setpaintingStrategy(PaintingStrategy.POINTS);
GC_High.setDefaultColor(Color.Green);
plot RC_High = dbh;
RC_High.setpaintingStrategy(paintingstrategy.points);
RC_High.setdefaultColor(Color.Red);
plot GC_Low = ubl;
GC_Low.setpaintingStrategy(PaintingStrategy.Points);
GC_Low.setdefaultColor(Color.Green);
plot RC_Low = dbl;
RC_Low.setpaintingStrategy(PaintingStrategy.POINTS);
RC_Low.SetDefaultColor(Color.Red);


#------------------------------------
# ADD LABEL
#------------------------------------
input Show_Label = no;
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);


#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 = no
input show_PRIOR_highs_lows   = yes;
input bubblemoversideways = -2;
input show_LAST_Bubble_only   = yes;

#Current Highs/Lows
def b  = bubblemoversideways;
def b1 = b + 1;
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.LIGHT_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), Color.pink);
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.LIGHT_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), Color.pink, 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.PINK);
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.LIGHT_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.PINK, 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.LIGHT_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);
Love this code! I've tried various versions around this thread and they all have something good and bad, not from a coding standpoint, but from a UI point of view. I was kinda able to figure some of it out but at the end it was futile because of all the editing to be done just to customize options.

I've got a few suggestion to ultimate-fy this. ;) Can we make these all plotable?

1) Cloud / Candle Body
-Ability to turn off cloud separate from border
-Option to make cloud extend to wick ends
-Color Picker

2) Borders
-Choose Left, Right, Top, Bottom On/Off
-Line types
-Color Picker

3) Wick
-Turn wick only on/off
-Line type
-Color Picker


I removed "show_bubbles" as it was redundant being that you already have the "show current high lows" and "show prior high lows" anyways.

Side note: Is there a way to have these in background instead of overlay?
 
This colors the cloud over the MTF bar's high/low
Can I have this same setup but painting Heikin Ashi Candles Colors, The other Heikin Ashi Scripts I found have wicks and I only want the box of high and bottom like this one but showing the color of the heikin ashi candle on that time frame.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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