Multi-TimeFrame Candles Overlay for ThinkOrSwim

Modified the approach here to use charts to draw the side of candle bodies. Also accounted for days where upper aggregation did not start on 1st bar (i.e. barCount = 0) in series. As long as higher time frame is even divisible by lower (i.e. 5min Overlay on 1min chart) overlay seem to work fine. You get odd higher TF candles when this is not the case (i.e. 10m Overlay on 3m chart).

http://tos.mx/MMKvsUQ

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( 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.LIGHT_RED, Color.LIGHT_GREEN, 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.LIGHT_RED, Color.LIGHT_GREEN, 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;

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
 
Last edited:
Should have led with an image. :cool:
MO47L97.png
 
Updated code / shared link above for a better method of determining opening candle of lower timeframe/mid-point candle. Only issue I am aware of is when there are missing candles in the lower timeframe you end up with a skewed cloud that joins to the next cloud. Not sure there is a resolution for that but I'm open to suggestions.
 
Corrected an issue with the code that determined when new cloud would be triggered. Updated links/code for both overlays. Also added an input to control drawing of points at high/lows (I prefer them off so that is the default).
 
Updated code / shared link above for a better method of determining opening candle of lower timeframe/mid-point candle. Only issue I am aware of is when there are missing candles in the lower timeframe you end up with a skewed cloud that joins to the next cloud. Not sure there is a resolution for that but I'm open to suggestions.
Resolved the issue with missing candles and skewed cloud on non "evenly divisible" intervals.
All it took was a little "mod"-ing. Pun intended. :rolleyes:
 
@tickets2themoon First of all, Thanks a bunch for the indicator. Appreciate your work. I may be pushing my luck but is it possible to have only inside candles to show. If it can be modified from settings whether to show only inside bar/ candle and cherry on the top would be to paint the small timeframe candles for bigger timeframe inside bar.
Please consider looking into this. Thanks in advance...
 
@tickets2themoon First of all, Thanks a bunch for the indicator. Appreciate your work. I may be pushing my luck but is it possible to have only inside candles to show. If it can be modified from settings whether to show only inside bar/ candle and cherry on the top would be to paint the small timeframe candles for bigger timeframe inside bar.
Please consider looking into this. Thanks in advance...

This has an input option to limit the overlay candles to just Inside Bars.

The picture is of 30m overlay inside bars only on a 1m chart

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
# update to limit plot to insideBars
#-----------------------------------------------------
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;
 
### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;

input limitplot_to_InsideBars = no;
def insideBar = L > L[1] and H < H[1];

def ubh = if limitplot_to_InsideBars and (insideBar) and up and midBar then H
          else if !limitplot_to_InsideBars and up and midbar then H
          else nan;
def ubc = if limitplot_to_InsideBars and (insideBar) and up and midBar then C
          else if !limitplot_to_InsideBars and up and midbar then C
          else nan;
def ubo = if limitplot_to_InsideBars and (insideBar) and up and midBar then O
          else if !limitplot_to_InsideBars and up and midbar then O
          else nan;
def ubl = if limitplot_to_InsideBars and (insideBar) and up and midBar then L
          else if !limitplot_to_InsideBars and up and midbar then L
          else nan;

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

def djbh = if limitplot_to_InsideBars and (insideBar) and doji and midBar then H
           else if !limitplot_to_InsideBars and doji and midBar then H             
           else nan;
def djbc = if limitplot_to_InsideBars and (insideBar) and doji and midBar then C
           else if !limitplot_to_InsideBars and doji and midBar then C             
           else nan;
def djbo = if limitplot_to_InsideBars and (insideBar) and doji and midBar then O
           else if !limitplot_to_InsideBars and doji and midBar then O             
           else nan;
def djbl = if limitplot_to_InsideBars and (insideBar) and doji and midBar then L
           else if !limitplot_to_InsideBars and doji and midBar then L             
           else nan;

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


input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if Color_Candles_within_MTF_InsideBars and insidebar then color.white else color.current);

AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 2 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 2 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 1 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 1 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and doji)
          then O
          else if !limitplot_to_InsideBars and (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 limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and doji)
          then O
          else if !limitplot_to_InsideBars and (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);

#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 = if limitplot_to_InsideBars and insideBar then ubh else if !limitplot_to_InsideBars then ubh else Double.NaN;
highs.SetPaintingStrategy(PaintingStrategy.POINTS);
highs.SetDefaultColor(Color.GREEN);
plot lhighs = if limitplot_to_InsideBars and insideBar then dbh else if !limitplot_to_InsideBars then dbh else Double.NaN;
lhighs.SetPaintingStrategy(PaintingStrategy.POINTS);
lhighs.SetDefaultColor(Color.RED);
plot lows = if limitplot_to_InsideBars and insideBar then ubl else if !limitplot_to_InsideBars then ubl else Double.NaN;
lows.SetPaintingStrategy(PaintingStrategy.POINTS);
lows.SetDefaultColor(Color.GREEN);
plot llows = if limitplot_to_InsideBars and insideBar then dbl else if !limitplot_to_InsideBars then dbl else Double.NaN;
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
 
Last edited:
@SleepyZ I am wondering if the the candles could be painted different colour instead of the highlighted rectangular shape.
Yes, I added that option to the code below to paint those candles WHITE within MTF Inside Bars.

input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if insidebar then color.white else color.current);

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
# update to limit plot to insideBars
#-----------------------------------------------------
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;
 
### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;

input limitplot_to_InsideBars = no;
def insideBar = L > L[1] and H < H[1];

def ubh = if limitplot_to_InsideBars and (insideBar) and up and midBar then H
          else if !limitplot_to_InsideBars and up and midbar then H
          else nan;
def ubc = if limitplot_to_InsideBars and (insideBar) and up and midBar then C
          else if !limitplot_to_InsideBars and up and midbar then C
          else nan;
def ubo = if limitplot_to_InsideBars and (insideBar) and up and midBar then O
          else if !limitplot_to_InsideBars and up and midbar then O
          else nan;
def ubl = if limitplot_to_InsideBars and (insideBar) and up and midBar then L
          else if !limitplot_to_InsideBars and up and midbar then L
          else nan;

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

def djbh = if limitplot_to_InsideBars and (insideBar) and doji and midBar then H
           else if !limitplot_to_InsideBars and doji and midBar then H             
           else nan;
def djbc = if limitplot_to_InsideBars and (insideBar) and doji and midBar then C
           else if !limitplot_to_InsideBars and doji and midBar then C             
           else nan;
def djbo = if limitplot_to_InsideBars and (insideBar) and doji and midBar then O
           else if !limitplot_to_InsideBars and doji and midBar then O             
           else nan;
def djbl = if limitplot_to_InsideBars and (insideBar) and doji and midBar then L
           else if !limitplot_to_InsideBars and doji and midBar then L             
           else nan;

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


input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if Color_Candles_within_MTF_InsideBars and insidebar then color.white else color.current);

AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 2 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 2 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 1 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 1 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and doji)
          then O
          else if !limitplot_to_InsideBars and (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 limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and doji)
          then O
          else if !limitplot_to_InsideBars and (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);

#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 = if limitplot_to_InsideBars and insideBar then ubh else if !limitplot_to_InsideBars then ubh else Double.NaN;
highs.SetPaintingStrategy(PaintingStrategy.POINTS);
highs.SetDefaultColor(Color.GREEN);
plot lhighs = if limitplot_to_InsideBars and insideBar then dbh else if !limitplot_to_InsideBars then dbh else Double.NaN;
lhighs.SetPaintingStrategy(PaintingStrategy.POINTS);
lhighs.SetDefaultColor(Color.RED);
plot lows = if limitplot_to_InsideBars and insideBar then ubl else if !limitplot_to_InsideBars then ubl else Double.NaN;
lows.SetPaintingStrategy(PaintingStrategy.POINTS);
lows.SetDefaultColor(Color.GREEN);
plot llows = if limitplot_to_InsideBars and insideBar then dbl else if !limitplot_to_InsideBars then dbl else Double.NaN;
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
 
Last edited:
Yes, I added that option to the code below to paint those candles WHITE within MTF Inside Bars.

input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if insidebar then color.white else color.current);
Amazing. Highly appreciate it mate.
 
Amazing. Highly appreciate it mate.
You are welcome! I made one edit to the above as follows where I forgot to include the input into assignpricecolor

input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if Color_Candles_within_MTF_InsideBars and insidebar then color.white else color.current);
 
@SleepyZ Everything works perfectly except I am getting these lines like wicks and broken lines. You can see that in your image as well. I have tried inserting an image but it won't let me from imgur.
 
@SleepyZ Everything works perfectly except I am getting these lines like wicks and broken lines. You can see that in your image as well. I have tried inserting an image but it won't let me from imgur.
Thanks, this should work now. I have replaced all of the above scripts with the following
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
# update to limit plot to insideBars
#-----------------------------------------------------
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;
 
### making stuff up here drawing the wick through the middle candle.
def nan = Double.NaN;
def up = C > O;

input limitplot_to_InsideBars = no;
def insideBar = L > L[1] and H < H[1];

def ubh = if limitplot_to_InsideBars and (insideBar) and up and midBar then H
          else if !limitplot_to_InsideBars and up and midbar then H
          else nan;
def ubc = if limitplot_to_InsideBars and (insideBar) and up and midBar then C
          else if !limitplot_to_InsideBars and up and midbar then C
          else nan;
def ubo = if limitplot_to_InsideBars and (insideBar) and up and midBar then O
          else if !limitplot_to_InsideBars and up and midbar then O
          else nan;
def ubl = if limitplot_to_InsideBars and (insideBar) and up and midBar then L
          else if !limitplot_to_InsideBars and up and midbar then L
          else nan;

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

def djbh = if limitplot_to_InsideBars and (insideBar) and doji and midBar then H
           else if !limitplot_to_InsideBars and doji and midBar then H             
           else nan;
def djbc = if limitplot_to_InsideBars and (insideBar) and doji and midBar then C
           else if !limitplot_to_InsideBars and doji and midBar then C             
           else nan;
def djbo = if limitplot_to_InsideBars and (insideBar) and doji and midBar then O
           else if !limitplot_to_InsideBars and doji and midBar then O             
           else nan;
def djbl = if limitplot_to_InsideBars and (insideBar) and doji and midBar then L
           else if !limitplot_to_InsideBars and doji and midBar then L             
           else nan;

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


input Color_Candles_within_MTF_InsideBars = yes;
assignpriceColor(if Color_Candles_within_MTF_InsideBars and insidebar then color.white else color.current);

AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 2 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 2 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and !doji)
          then O
          else if !limitplot_to_InsideBars and (addcloud and sider == 1 and !doji)
          then O
          else Double.NaN,
          if (addcloud and sider == 1 and !doji) then C else Double.NaN,
          Color.LIGHT_RED, Color.LIGHT_GREEN, yes);
AddCloud( if limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 1 and doji)
          then O
          else if !limitplot_to_InsideBars and (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 limitplot_to_InsideBars and (insideBar) and (addcloud and sider == 2 and doji)
          then O
          else if !limitplot_to_InsideBars and (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);

#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 = if limitplot_to_InsideBars and insideBar then ubh else if !limitplot_to_InsideBars then ubh else Double.NaN;
highs.SetPaintingStrategy(PaintingStrategy.POINTS);
highs.SetDefaultColor(Color.GREEN);
plot lhighs = if limitplot_to_InsideBars and insideBar then dbh else if !limitplot_to_InsideBars then dbh else Double.NaN;
lhighs.SetPaintingStrategy(PaintingStrategy.POINTS);
lhighs.SetDefaultColor(Color.RED);
plot lows = if limitplot_to_InsideBars and insideBar then ubl else if !limitplot_to_InsideBars then ubl else Double.NaN;
lows.SetPaintingStrategy(PaintingStrategy.POINTS);
lows.SetDefaultColor(Color.GREEN);
plot llows = if limitplot_to_InsideBars and insideBar then dbl else if !limitplot_to_InsideBars then dbl else Double.NaN;
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
 
Should have led with an image. :cool:
MO47L97.png

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.

3CT1MN6.png


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);
 
Last edited:
This is so dope! I don't suppose you or someone could make Previous Candle High/Low bubbles for these like the ones here: https://usethinkscript.com/threads/add-chart-bubble-on-previous-candle.3831/post-75543

I made a variation of yours where you can change the color and more importantly transparency of the candles (see under Globals in options). 50% transparency helps a lot!

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 (added Global candle color/transpoarency option)
# 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;
 
DefineGlobalColor("green", Color.green);
DefineGlobalColor("red", 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"), GlobalColor("green"), 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"), GlobalColor("green"), 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;

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


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.


Capture.jpg
Ruby:
#High/low bubbles for the overlay candles

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

input show_bubbles              = no;
input show_last_highs_lows_only = yes;
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastubh and ubh
               else ubh, ubh, astext(ubh), Color.GREEN);
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastdjbh and djbh
               else djbh, djbh, astext(djbh), Color.WHITE);
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastdbh and dbh
               else dbh, dbh, astext(dbh));
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastubh and ubl
               else ubl, ubl, astext(ubl), Color.GREEN, up = no);
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastdjbh and djbl
               else djbl, djbl, astext(djbl), Color.WHITE, up = no);
AddChartBubble(if !show_bubbles then Double.NaN
               else if show_last_highs_lows_only then bn == lastdbh and dbl
               else dbl, dbl, astext(dbl), up = no);
 

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