Multi-TimeFrame Candles Overlay for ThinkOrSwim

hey SleepyZ Im looking for this indicator to start the agg period during RTH even with the after hours and pre market sessions showing.. as is, the hour candles draw the closing price line at 7am, 8am etc.. Hoping for them to plot on the half hours! Thanks in advance

Sorry, it does not look like one can have that timeframe you want with the current code, except if you turn off the extended hours.
 
Can we alter this (albeit amazing) code so that we can customize when the candle starts and ends? I want to break the daily trading session into three parts (Open, Lunch, Afternoon) and see them as candles. I realize it might be easiest to write one study then copy it and make 3 separate studies with different times. So with that spirit in mind, I would like to customize the candle overlay to cover the first half of the daily range 930am-1200pm EST.

I've looked at Pelonsax's code a few times but can't seem to figure out how to change it from drawing from an aggregation period to specific time inputs. Any thoughts/help is appreciated.
 
Can we alter this (albeit amazing) code so that we can customize when the candle starts and ends? I want to break the daily trading session into three parts (Open, Lunch, Afternoon) and see them as candles. I realize it might be easiest to write one study then copy it and make 3 separate studies with different times. So with that spirit in mind, I would like to customize the candle overlay to cover the first half of the daily range 930am-1200pm EST.

I've looked at Pelonsax's code a few times but can't seem to figure out how to change it from drawing from an aggregation period to specific time inputs. Any thoughts/help is appreciated.
IMO, this would be easiest to achieve is you use the @SleepyZ version from this post above and modify the condition code for the profile to be something like this:

input RTH_Start = 0930;
input Second_Start = 1100;
input Third_Start = 1330;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(RTH_Start) == 0 or SecondsFromTime(Second_Start) == 0 or SecondsFromTime(Third_Start) == 0;
 
IMO, this would be easiest to achieve is you use the @SleepyZ version from this post above and modify the condition code for the profile to be something like this:

input RTH_Start = 0930;
input Second_Start = 1100;
input Third_Start = 1330;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(RTH_Start) == 0 or SecondsFromTime(Second_Start) == 0 or SecondsFromTime(Third_Start) == 0;

Thank you but I guess I'm still confused on how to get it to use a timeframe (ie 930-1100) vs an aggregation period. When you say modify the condition, I interpreted that as replacing the part of the code for aggregationperiod and replacing it with these inputs, but I get an error (no such function) when I do that.
 
Thank you but I guess I'm still confused on how to get it to use a timeframe (ie 930-1100) vs an aggregation period. When you say modify the condition, I interpreted that as replacing the part of the code for aggregationperiod and replacing it with these inputs, but I get an error (no such function) when I do that.
Okay, I took a crack at this. I've created 5 different times of the day to break-up these candles. By default, 09:30-11:00, 11:00-13:30, 13:30-18:00, 18:00-02:00 and 02:00-09:30. I've also borrowed some code from the Daily Candle Overlay indicator I shared awhile back to display the aggregated periods as a single candle vs the cloud across the entire range. YMMV.

It will look something like this:

U4xoRuI.png


Ruby:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 2;


#TOS VolumeProfile used to determine high/low and break per numberofbars
input RTH_Start = 0930;
input Second_Start = 1100;
input Third_Start = 1330;
input Globex_Start = 1800;
input Euro_Start = 0200;
#input valueAreaPercent = 70;
#input opacity = 15;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(RTH_Start) == 0 or SecondsFromTime(Second_Start) == 0 or SecondsFromTime(Third_Start) == 0 or SecondsFromTime(Globex_Start) == 0 or SecondsFromTime(Euro_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();


def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);

plot o = o1;
plot c = if p==highestall(x) then c2 else c1[1];
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();
def isUp = o < c;

def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond and isUp then h else NAN;
def candleLow = if showBigCandle and cond and isUp then l else NAN;
def candleOpen = if showBigCandle and cond and isUp then o else NAN;
def candleClose = if showBigCandle and cond and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);


# end

Note, there is definitely a way simpler way of achieving this same idea. I just really like this concept of using the volume profile code to aggregate candles.
 
Okay, I took a crack at this. I've created 5 different times of the day to break-up these candles. By default, 09:30-11:00, 11:00-13:30, 13:30-18:00, 18:00-02:00 and 02:00-09:30. I've also borrowed some code from the Daily Candle Overlay indicator I shared awhile back to display the aggregated periods as a single candle vs the cloud across the entire range. YMMV.

It will look something like this:

U4xoRuI.png


Ruby:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 2;


#TOS VolumeProfile used to determine high/low and break per numberofbars
input RTH_Start = 0930;
input Second_Start = 1100;
input Third_Start = 1330;
input Globex_Start = 1800;
input Euro_Start = 0200;
#input valueAreaPercent = 70;
#input opacity = 15;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(RTH_Start) == 0 or SecondsFromTime(Second_Start) == 0 or SecondsFromTime(Third_Start) == 0 or SecondsFromTime(Globex_Start) == 0 or SecondsFromTime(Euro_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();


def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);

plot o = o1;
plot c = if p==highestall(x) then c2 else c1[1];
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();
def isUp = o < c;

def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond and isUp then h else NAN;
def candleLow = if showBigCandle and cond and isUp then l else NAN;
def candleOpen = if showBigCandle and cond and isUp then o else NAN;
def candleClose = if showBigCandle and cond and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);


# end

Note, there is definitely a way simpler way of achieving this same idea. I just really like this concept of using the volume profile code to aggregate candles.
Thanks Tony - I tinkered with your code a little bit and was able to tailor the zones more to the times I look at. Thanks a ton. This gets pretty darn close to what I was looking for. I'm noticing a couple things aren't showing up that I would like and I haven't been able to get them to show up. If you can help me out I'd appreciate it:

1) When I turn on "Addcloud" in the study's controls, I get a cloud on the most current zone that's forming, and then all the previous zones get a thin cloud on their open, but I don't see a close. If I turn on "OpenCloseLines" then I get all four lines stacking at on the open of each zone (see image). I'm not sure why they don't show up on the open/close?

2) Some of the zones show up with the wrong color. In other words they show up red when the direction of the move should print a green candle, and vice versa. Not a big deal since you added the option to gray all the zones, but would make for a nice visual. I've added a couple red arrows on examples where you can see what I mean. There are also some that show up white, presumably reserved for doji, when they aren't dojis. Again, see red arrows in this Image (Sorry, I couldn't get it to post. I've read the posting images on the site FAQ but have still never gotten it to work.)

Code:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method

# 07.01.2022 - Cribbage - Relabeled Tony's time zones and added some for personal preference. Original included in #
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 2;


#TOS VolumeProfile used to determine high/low and break per numberofbars

#Cribbage start - altered times
input NYO_Start = 0930;  #NYV Open
input NYL_Start = 1200;  #NYC Lunch
input NYA_Start = 1300;  #NYC Afternoon
input Asia_Start = 1900; #Asia
input Midnight = 0000;   #Midnight Open
input LO_Start = 0200;   #London Open
input LD_Start = 0500;   #London Day
#Cribbage end

#Original times from Tony
#input RTH_Start = 0930;
#input Second_Start = 1100;
#input Third_Start = 1330;
#input Globex_Start = 1800;
#input Euro_Start = 0200;  
#input valueAreaPercent = 70;
#input opacity = 15;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(NYO_Start) == 0 or SecondsFromTime(NYL_Start) == 0 or SecondsFromTime(NYA_Start) == 0 or SecondsFromTime(Asia_Start) == 0 or SecondsFromTime(Midnight) == 0 or SecondsFromTime(LO_Start) == 0 or SecondsFromTime(LD_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();


def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);

plot o = o1;
plot c = if p==highestall(x) then c2 else c1[1];
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();
def isUp = o < c;

def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond and isUp then h else NAN;
def candleLow = if showBigCandle and cond and isUp then l else NAN;
def candleOpen = if showBigCandle and cond and isUp then o else NAN;
def candleClose = if showBigCandle and cond and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);


# end
 
Last edited:
Thanks Tony - I tinkered with your code a little bit and was able to tailor the zones more to the times I look at. Thanks a ton. This gets pretty darn close to what I was looking for. I'm noticing a couple things aren't showing up that I would like and I haven't been able to get them to show up. If you can help me out I'd appreciate it:

1) When I turn on "Addcloud" in the study's controls, I get a cloud on the most current zone that's forming, and then all the previous zones get a thin cloud on their open, but I don't see a close. If I turn on "OpenCloseLines" then I get all four lines stacking at on the open of each zone (see image). I'm not sure why they don't show up on the open/close?

2) Some of the zones show up with the wrong color. In other words they show up red when the direction of the move should print a green candle, and vice versa. Not a big deal since you added the option to gray all the zones, but would make for a nice visual. I've added a couple red arrows on examples where you can see what I mean. There are also some that show up white, presumably reserved for doji, when they aren't dojis. Again, see red arrows in this Image (Sorry, I couldn't get it to post. I've read the posting images on the site FAQ but have still never gotten it to work.)

Code:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method

# 07.01.2022 - Cribbage - Relabeled Tony's time zones and added some for personal preference. Original included in #
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 2;


#TOS VolumeProfile used to determine high/low and break per numberofbars

#Cribbage start - altered times
input NYO_Start = 0930;  #NYV Open
input NYL_Start = 1200;  #NYC Lunch
input NYA_Start = 1300;  #NYC Afternoon
input Asia_Start = 1900; #Asia
input Midnight = 0000;   #Midnight Open
input LO_Start = 0200;   #London Open
input LD_Start = 0500;   #London Day
#Cribbage end

#Original times from Tony
#input RTH_Start = 0930;
#input Second_Start = 1100;
#input Third_Start = 1330;
#input Globex_Start = 1800;
#input Euro_Start = 0200; 
#input valueAreaPercent = 70;
#input opacity = 15;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(NYO_Start) == 0 or SecondsFromTime(NYL_Start) == 0 or SecondsFromTime(NYA_Start) == 0 or SecondsFromTime(Asia_Start) == 0 or SecondsFromTime(Midnight) == 0 or SecondsFromTime(LO_Start) == 0 or SecondsFromTime(LD_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();


def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);

plot o = o1;
plot c = if p==highestall(x) then c2 else c1[1];
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();
def isUp = o < c;

def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond and isUp then h else NAN;
def candleLow = if showBigCandle and cond and isUp then l else NAN;
def candleOpen = if showBigCandle and cond and isUp then o else NAN;
def candleClose = if showBigCandle and cond and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);


# end
Hmm. It is not properly calculating the close of the period. I didn't notice that the original code had this line that looks forward:

plot c = if p==highestall(x) then c2 else GetValue(c1[1], - numberofbars);

So what we need to figure out is how many candles in the future our next cond 'change' will be. I have a very ugly solution for it but will look around to see if I can find something cleaner. If not, will post what I have...
 
Hmm. It is not properly calculating the close of the period. I didn't notice that the original code had this line that looks forward:

plot c = if p==highestall(x) then c2 else GetValue(c1[1], - numberofbars);

So what we need to figure out is how many candles in the future our next cond 'change' will be. I have a very ugly solution for it but will look around to see if I can find something cleaner. If not, will post what I have..
Thanks Tony - I tinkered with your code a little bit and was able to tailor the zones more to the times I look at. Thanks a ton. This gets pretty darn close to what I was looking for. I'm noticing a couple things aren't showing up that I would like and I haven't been able to get them to show up. If you can help me out I'd appreciate it:

1) When I turn on "Addcloud" in the study's controls, I get a cloud on the most current zone that's forming, and then all the previous zones get a thin cloud on their open, but I don't see a close. If I turn on "OpenCloseLines" then I get all four lines stacking at on the open of each zone (see image). I'm not sure why they don't show up on the open/close?

2) Some of the zones show up with the wrong color. In other words they show up red when the direction of the move should print a green candle, and vice versa. Not a big deal since you added the option to gray all the zones, but would make for a nice visual. I've added a couple red arrows on examples where you can see what I mean. There are also some that show up white, presumably reserved for doji, when they aren't dojis. Again, see red arrows in this Image (Sorry, I couldn't get it to post. I've read the posting images on the site FAQ but have still never gotten it to work.)

Code:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method

# 07.01.2022 - Cribbage - Relabeled Tony's time zones and added some for personal preference. Original included in #
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 2;


#TOS VolumeProfile used to determine high/low and break per numberofbars

#Cribbage start - altered times
input NYO_Start = 0930;  #NYV Open
input NYL_Start = 1200;  #NYC Lunch
input NYA_Start = 1300;  #NYC Afternoon
input Asia_Start = 1900; #Asia
input Midnight = 0000;   #Midnight Open
input LO_Start = 0200;   #London Open
input LD_Start = 0500;   #London Day
#Cribbage end

#Original times from Tony
#input RTH_Start = 0930;
#input Second_Start = 1100;
#input Third_Start = 1330;
#input Globex_Start = 1800;
#input Euro_Start = 0200;
#input valueAreaPercent = 70;
#input opacity = 15;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(NYO_Start) == 0 or SecondsFromTime(NYL_Start) == 0 or SecondsFromTime(NYA_Start) == 0 or SecondsFromTime(Asia_Start) == 0 or SecondsFromTime(Midnight) == 0 or SecondsFromTime(LO_Start) == 0 or SecondsFromTime(LD_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();


def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);

plot o = o1;
plot c = if p==highestall(x) then c2 else c1[1];
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();
def isUp = o < c;

def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond and isUp then h else NAN;
def candleLow = if showBigCandle and cond and isUp then l else NAN;
def candleOpen = if showBigCandle and cond and isUp then o else NAN;
def candleClose = if showBigCandle and cond and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);


# end
I must say, it is very interesting looking at the sessions as you have split them up and what price does there. Thanks for sharing!

4ru7mnS.png


I've posted a question on how to find our closing value by looking forward for the next 'cond' flip. If anyone has thoughts on how to solve that, we should be ready. In the image above, I've added some verticals to more easily see 'which session' you are in.
 
I must say, it is very interesting looking at the sessions as you have split them up and what price does there. Thanks for sharing!

4ru7mnS.png

Thanks to @Joshua and @halcyonguy for pointing me in the right direction on a forward looking fold. This should now properly calculate the candles for any time-based chart for each of the zones. The optional zone labels are included as in the image above.

Ruby:
# Multi-Time-Frame Candle Overlay version 2.4a
# 2020 Paul Townsend
# with code from UseThinkScript.com
# 01.25.2021 - BLT - Modified Addcloud to match horizontal lines

# 04.20.2021 - Sleepyz - Added Bar method instead of aggregationperiod method to create overlay candles. Used TOS VolumeProfile() code to make the candles.

# 06.30.2022 - @tony_futures - Changed Bar method to aggregate 5 different times of day
# for example, price will aggregate a single candle from RTH_Start to Second_Start and then a second candle from Second_Start to Third_Start
# In addition, @tony_futures also included an optional second way to display the aggregated candles using the AddChart method

# 07.01.2022 - Cribbage - Relabeled Tony's time zones and added some for personal preference.
# 07.03.2022 - @tony_futures - Improved the tracking of close on each zone and added an optional vertical line to denote the zones
 
#input numberofbars   = 10;
input OpenCloseLines = yes;
input HighLowLines   = yes;
input HighLowGray    = no;
input LineWeight     = 1;


#TOS VolumeProfile used to determine high/low and break per numberofbars

#Cribbage start - altered times
input NYO_Start = 0930;  #NYV Open
input NYL_Start = 1200;  #NYC Lunch
input NYA_Start = 1300;  #NYC Afternoon
input Asia_Start = 1900; #Asia
input Midnight = 0000;   #Midnight Open
input LO_Start = 0200;   #London Open
input LD_Start = 0500;   #London Day

def isNYOpen = secondsFromTime(NYO_Start) == 0;
def isNYLunch = secondsFromTime(NYL_Start) == 0;
def isNYAfternoon = secondsFromTime(NYA_Start) == 0;
def isAsia = secondsFromTime(Asia_Start) == 0;
def isMidnight = secondsFromTime(Midnight) == 0;
def isLOpen = secondsFromTime(LO_Start) == 0;
def isLDpen = secondsFromTime(LD_Start) == 0;

def yyyymmdd = GetYYYYMMDD();
def period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % 1 else count[1], 0);
def cond = SecondsFromTime(NYO_Start) == 0 or SecondsFromTime(NYL_Start) == 0 or SecondsFromTime(NYA_Start) == 0 or SecondsFromTime(Asia_Start) == 0 or SecondsFromTime(Midnight) == 0 or SecondsFromTime(LO_Start) == 0 or SecondsFromTime(LD_Start) == 0;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = PricePerRow.AUTOMATIC, "value area percent" = 0);

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())  then lProfile[1] else vol.GetLowest();
def mins = getAggregationPeriod()/(1000*60);
def maxMinutes = 300;
def maxLook = maxMinutes/mins;
def bn = barNumber();

def nextFlipBN = fold k = 1 to maxLook
with q = Double.NaN
  while isNaN(q) do
if getvalue(cond, -k) then GetValue(bn,-k)
else Double.NaN ;

def nextFlip = nextFlipBN - bn;

def p = if cond then p[1] + 1 else p[1];
def x = if !IsNaN(close) and IsNaN(close[-1]) then p else Double.NaN;

def o1 = if p != p[1]  then open else o1[1];
def c1 = if p != p[-1] then close else c1[1];
def c2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);


plot o = o1;
plot c = if p==highestall(x) then c2 else GetValue(c1[1], - nextFlip);
plot h = if p>highestall(x) then double.nan else hProfile;
plot l = if p>highestall(x) then double.nan else lProfile;
def isUp = o < c;

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

o.SetLineWeight(LineWeight);
c.SetLineWeight(LineWeight);
h.SetLineWeight(LineWeight);
l.SetLineWeight(LineWeight);

o.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
c.AssignValueColor(if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
h.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);
l.AssignValueColor(if HighLowGray then Color.GRAY else if o == c then Color.WHITE else if o > c then Color.RED else Color.GREEN);

input addcloud = yes;
def side = if p[-1] != p then 2 else 1;
plot sider = side;
sider.Hide();
AddCloud( if addcloud and sider == 2 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider == 1 then c else Double.NaN, o, Color.GREEN, Color.RED);
AddCloud( if addcloud and sider!=sider[-1] then c else Double.NaN, o, Color.GREEN, Color.RED);

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

o.hidebubble();
c.hidebubble();
h.hidebubble();
l.hidebubble();


def NAN = Double.NaN;
input showBigCandle = yes;
def candleHigh = if showBigCandle and cond[1] and isUp then h else NAN;
def candleLow = if showBigCandle and cond[1] and isUp then l else NAN;
def candleOpen = if showBigCandle and cond[1] and isUp then o else NAN;
def candleClose = if showBigCandle and cond[1] and isUp then c else NAN;
def candleHigh2 = if showBigCandle and cond[1] and !isUp then h else NAN;
def candleLow2 = if showBigCandle and cond[1] and !isUp then l else NAN;
def candleOpen2 = if showBigCandle and cond[1] and !isUp then o else NAN;
def candleClose2 = if showBigCandle and cond[1] and !isUp then c else NAN;

AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, Color.GREEN);
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, Color.RED);

input showVerticals = yes;
AddVerticalLine(showVerticals and isNYOpen,"NY Open", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isNYLunch,"Lunch", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isNYAfternoon,"NY Aft", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isAsia,"Asia", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isMidnight,"Midnight", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isLOpen,"London Open", Color.GRAY, curve.POINTS);
AddVerticalLine(showVerticals and isLDpen,"London Day", Color.GRAY, curve.POINTS);
# end
 
I added Heikin Ashi Candle as well with adjusted colors. look good now.

f4gfRid.png


CSS:
#-----------------------------------------------------
#
#       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
# Added HeikinAshi Candels by Sam4COK @ Samer800 - 08/2022
#-----------------------------------------------------
DECLARE UPPER;
#------------------------------------
# MTF SECTION
#------------------------------------
input candleType = { Default "CandleStick", "HeikinAshi"};
input Time_Frame = AggregationPeriod.FIFTEEN_MIN;
input addcloud = yes;

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

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 (candleType == candleType.Candlestick and addcloud and sider == 2 and !doji) then O else na, if (addcloud and sider == 2 and !doji) then C else na, CreateColor(236,64,122), CreateColor(2,160,174), yes);
AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 1 and !doji) then O else na, if (addcloud and sider == 1 and !doji) then C else na, CreateColor(236,64,122), CreateColor(2,160,174), yes);
AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 1 and doji) then O else na, if (addcloud and sider == 1 and doji) then C else na, Color.WHITE, Color.WHITE, yes);
AddCloud( if (candleType == candleType.Candlestick and addcloud and sider == 2 and doji) then O else na, if (addcloud and sider == 2 and doji) then C else na, Color.WHITE, Color.WHITE, yes);

### making stuff up here drawing the wick through the middle candle.

def up = c > o;
def ubh; def ubc; def ubo; def ubl;
if candleType == candleType.Candlestick and up and midBar then {
ubh = h;
ubc = c;
ubo = o;
ubl = l;} else {
ubh = na;
ubc = na;
ubo = na;
ubl = na;}

def dbh; def dbc; def dbo; def dbl;
if candleType == candleType.Candlestick and !up and !doji and midBar then {
dbh = h;
dbc = c;
dbo = o;
dbl = l;} else {
dbh = na;
dbc = na;
dbo = na;
dbl = na;}

def djbh; def djbc; def djbo; def djbl;
if candleType == candleType.Candlestick and doji and midBar then {
djbh = h;
djbc = c;
djbo = o;
djbl = l;} else {
djbh = na;
djbc = na;
djbo = na;
djbl = na;}

def sideuh = if candleType == candleType.Candlestick and up and openbar then C else na;
def sideul = if candleType == candleType.Candlestick and up and openbar then O else na;
def sidedh = if candleType == candleType.Candlestick and !up and !doji and openbar then O else na;
def sidedl = if candleType == candleType.Candlestick and !up and !doji and openbar then C else na;
def sidedjh = if candleType == candleType.Candlestick and doji and openbar then O else na;
def sidedjl = if candleType == candleType.Candlestick and doji and openbar then C else na;

#Draw Upper Wick Green
AddChart(high = ubh, low = ubc, open = na, close = na, type = ChartType.BAR , growcolor = CreateColor(2,160,174));

#Draw Upper Wick Red
AddChart(high = dbh, low = dbo, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122));

#Draw Lower Wick Green
AddChart(high = ubo, low = ubl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174));

#Draw Lower Wick Red
AddChart(high = dbc, low = dbl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122));

#Draw Side of Body Green
AddChart(high = sideuh, low = sideul, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174));

#Draw Side of Body Red
AddChart(high = sidedh, low = sidedl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(236,64,122));

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

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

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


#plot highs = if o==l then na else ubh;
#highs.setpaintingStrategy(PaintingStrategy.POINTS);
#highs.setDefaultColor(CreateColor(2,160,174));
#plot lhighs = if o==h then na else dbh;
#lhighs.setpaintingStrategy(paintingstrategy.points);
#lhighs.setdefaultColor(Color.DARK_RED);
#plot lows = if o==l then na else ubl;
#lows.setpaintingStrategy(PaintingStrategy.Points);
#lows.setdefaultColor(CreateColor(236,64,122));
#plot llows = if o==h then na else dbl;
#llows.setpaintingStrategy(PaintingStrategy.POINTS);
#llows.SetDefaultColor(Color.DARK_RED);

########

def haOpen;
def haHigh;
def haLow;
def haClose;

haClose = (o + h + l + c) / 4;
haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
haHigh = Max(Max(h, haOpen), haClose);
haLow = Min(Min(l, haOpen), haClose);

def hh1r = if haClose > haOpen then 1 else if haClose < haOpen then -1 else 0;
def HUp = hh1r > 0;
def Hdoji = haClose==haOpen;

def haO = haOpen;
def haC = haClose;
# Plot UP candle

def UpO;
def UpH;
def UpL;
def UpC;

if HUp and midbar and candleType == candleType.HeikinAshi
then {
    UpO = haOpen ;
    UpH = haHigh ;
    UpL = haLow ;
    UpC = haClose;
} else
{
    UpO = na;
    UpH = na;
    UpL = na;
    UpC = na;
}
# Plot DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if !HUp and !Hdoji and midBar and candleType == candleType.HeikinAshi
then {
    DnO = haOpen ;
    DnH = haHigh ;
    DnL = haLow ;
    DnC = haClose;
} else
{
    DnO = na;
    DnH = na;
    DnL = na;
    DnC = na;
}

def Hdjbh; def Hdjbc; def Hdjbo; def Hdjbl;
if candleType == candleType."HeikinAshi" and Hdoji and midBar then {
Hdjbh = haHigh;
Hdjbc = haClose;
Hdjbo = haOpen;
Hdjbl = haLow;} else {
Hdjbh = na;
Hdjbc = na;
Hdjbo = na;
Hdjbl = na;}

def Hsideuh = if candleType == candleType.HeikinAshi and HUp and openbar then haClose else na;
def Hsideul = if candleType == candleType.HeikinAshi and HUp and openbar then haOpen else na;
def Hsidedh = if candleType == candleType.HeikinAshi and !HUp and !Hdoji and openbar then haOpen else na;
def Hsidedl = if candleType == candleType.HeikinAshi and !HUp and !Hdoji and openbar then haClose else na;
def Hsidedjh = if candleType == candleType.HeikinAshi and Hdoji and openbar then haOpen else na;
def Hsidedjl = if candleType == candleType.HeikinAshi and Hdoji and openbar then haClose else na;
# Plot the new Chart

#Draw Upper Wick Green
AddChart(high = UpH, low = UpC, open = na, close = na, type = ChartType.BAR , growcolor = CreateColor(2,160,174));

#Draw Upper Wick Red
AddChart(high = DnH, low = DnO, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192));

#Draw Lower Wick Green
AddChart(high = Upo, low = Upl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174));

#Draw Lower Wick Red
AddChart(high = Dnc, low = Dnl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192));

#Draw Side of Body Green
AddChart(high = hsideuh, low = hsideul, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(2,160,174));

#Draw Side of Body Red
AddChart(high = hsidedh, low = hsidedl, open = na, close = na, type = ChartType.BAR, growcolor = CreateColor(192,0,192));

#Draw Upper Wick White - Doji
AddChart(high = Hdjbh, low = Hdjbo, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE);

#Draw Lower Wick White - Doji
AddChart(high = hdjbc, low = hdjbl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE);

#Draw Side of Body White
AddChart(high = hsidedjh, low = hsidedjl, open = na, close = na, type = ChartType.BAR, growcolor = color.WHITE);


AddCloud(if (candleType ==  candleType.HeikinAshi and addcloud and sider == 2 and !hdoji) then haO else na, if (addcloud and sider == 2 and !hdoji) then haC else na, CreateColor(192,0,192), CreateColor(2,160,174), yes);
AddCloud( if (candleType ==  candleType.HeikinAshi and addcloud and sider == 1 and !hdoji) then haO else na, if (addcloud and sider == 1 and !hdoji) then haC else na, CreateColor(192,0,192), CreateColor(2,160,174), yes);
AddCloud( if (candleType ==  candleType.HeikinAshi and addcloud and sider == 1 and hdoji) then haO else na, if (addcloud and sider == 1 and hdoji) then haC else na, Color.WHITE, Color.WHITE, yes);
AddCloud( if (candleType ==  candleType.HeikinAshi and addcloud and sider == 2 and hdoji) then haO else na, if (addcloud and sider == 2 and hdoji) then haC else na, Color.WHITE, Color.WHITE, yes);


#plot Hahighs = if haOpen==haHigh then na else uph;
#hahighs.setpaintingStrategy(PaintingStrategy.POINTS);
#hahighs.setDefaultColor(Color.Green);
#plot halhighs = if haOpen==haHigh then na else dnh;
#halhighs.setpaintingStrategy(paintingstrategy.points);
#halhighs.setdefaultColor(Color.Red);
#plot halows = if haOpen==haLow then na else upl;
#halows.setpaintingStrategy(PaintingStrategy.Points);
#halows.setdefaultColor(Color.Green);
#plot hallows = if haOpen==haLow then na else dnl;
#hallows.setpaintingStrategy(PaintingStrategy.POINTS);
#hallows.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  candleType else ""), Color.light_Gray);

# end
 
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
Hello, I attempted using your code and the transparency setting does not pop up under globals or anywhere else in the options. Is it possible you could re-add it?
 
I see that you added the high low bubbles and those are working, transparency setting is still not there! High low bubbles are pretty valuable to my strat so thanks for that! Lower transparency would make this study killer
Go to colors, then More, then HSL tab and use the transparency there. Note it will likely go all funk when you do, so just set it, save it, restart ToS.
 
Should have led with an image. :cool:
MO47L97.png
Hello all,
Is there anyway to change the opacity of the wicks and open/close bar? I've tried everything I can, adding or changing some scripts but the only thing I could make it worked so far is changing the color of the wicks and OC bars. 😆
Thanks in advance.
 
Here is a version that displays current and/or prior bar's highs/lows of the overlay bars. There is an option to display the last bar only with that data.

Ok, I've created a new and better version, and updated this post with it: https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/post-80502

I have ONE request, using my code can you please make the PC H/L bubbles hover above/below the previous 5min candle instead of the current one? For example, I made this script where the price does that for regular candles using bubblemover, but I don't know how to do it to this thing.
 
Hello all,
Is there anyway to change the opacity of the wicks and open/close bar? I've tried everything I can, adding or changing some scripts but the only thing I could make it worked so far is changing the color of the wicks and OC bars. 😆
Thanks in advance.
My new version does that, see my last post above.
 
My new version does that, see my last post above.
Thank you very much. The code allows me to adjust the cloud and wick opacity but not the open/close bars'.
Is there a way to completely remove the open/close bar, and see only the candle body cloud?
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
443 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top