Previous Day High/Low/Close For ThinkOrSwim

Here is a link to the image shown below.

https://tos.mx/YT96DH3

It contains 3 copies of code to display the Day, Week and Month data.
The labels have been revised to colors based on your request.
The bubbles have been revised to show the Day, Week or Month for each.
The red circled area shows the order of the studies to properly stack and display the labels on your chart.
Make sure you have enough days displayed on your chart to ensure accurate plots.



Here is the separate code to display your label request.



The code in post #151 has also been revised to assist in your request.
Hello @SleepyZ , why the W-PreClose and D-PrevClose move like a price line , in the link that you shared work perfect but if I put it in other chart W-PreClose and D-PrevClose move with the price line ?

thanks
 
Hello @SleepyZ , why the W-PreClose and D-PrevClose move like a price line , in the link that you shared work perfect but if I put it in other chart W-PreClose and D-PrevClose move with the price line ?

thanks

I will need more specific chart information and an image of what you see to be able to assist. I do not see that issue on charts I have viewed in OnDemand.
 
@SleepyZ
Hi Sleepy, I was checking out this script you submitted. Does this work on any timeframe ie, Q, M, W if I change "count"? Thank you!

def ymd = GetYYYYMMDD();
def capture = !IsNaN(close) and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def pd = (HighestAll(dayCount) - dayCount) ;
def ph = if pd==1 and secondsfromTime(0930) == 0
then high
else if pd==1 and secondsTillTime(1600) > 0
then max(high, ph[1])
else ph[1];
plot scan = pd == 0 and secondstillTime(1600) > 0 and close crosses above ph;
 
@SleepyZ
Hi Sleepy, I was checking out this script you submitted. Does this work on any timeframe ie, Q, M, W if I change "count"? Thank you!

def ymd = GetYYYYMMDD();
def capture = !IsNaN(close) and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def pd = (HighestAll(dayCount) - dayCount) ;
def ph = if pd==1 and secondsfromTime(0930) == 0
then high
else if pd==1 and secondsTillTime(1600) > 0
then max(high, ph[1])
else ph[1];
plot scan = pd == 0 and secondstillTime(1600) > 0 and close crosses above ph;

Try this when the market is active as the scanner is not reliable today.

Scan - Currently shows no results at 15min . Not sure it will work. However, see Chart below.
Code:
input mode = { DAY, default WEEK, MONTH};

def ymd;
switch (mode) {
case DAY:
    ymd = GetYYYYMMDD();
case WEEK:
    ymd = GetWeek();
case MONTH:
    ymd = GetMonth();
}

def capture = !IsNaN(close) and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def pd = (HighestAll(dayCount) - dayCount) ;
#pd.setpaintingStrategy(paintingStrategy.VALUES_BELOW);

def ph = if pd[1] == 2 and pd == 1 and SecondsFromTime(0930) == 0
then high
else if pd == 1
then Max(high, ph[1])
else ph[1];
#plot phh=ph;

plot scan = pd == 0 and SecondsTillTime(1600) > 0 and close crosses above ph;
#scan.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

#

Chart - This works on a chart set to 15m and mode set to WEEK. See arrows.
Screenshot 2024-01-15 121937.png
Code:
input mode = {default DAY, WEEK, MONTH};

def ymd;
switch (mode) {
case DAY:
    ymd = GetYYYYMMDD();
case WEEK:
    ymd = GetWeek();
case MONTH:
    ymd = GetMonth();
}

def capture = !IsNaN(close) and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
plot pd = (HighestAll(dayCount) - dayCount) ;
pd.setpaintingStrategy(paintingStrategy.VALUES_BELOW);

def ph = if pd[1] == 2 and pd == 1 and SecondsFromTime(0930) == 0
then high
else if pd == 1
then Max(high, ph[1])
else ph[1];
plot phh=ph;

plot scan = pd == 0 and SecondsTillTime(1600) > 0 and close crosses above ph;
scan.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

#
 
This code shows today's high and low. But I can’t add the high and low prices to this code. Tell me how to display it?

input PlotOverNightExtremes = yes;
def o = open;
def h = high;
def l = low;
def c = close;
def bar = barNumber();
def Intraday = if GetAggregationPeriod() < 86400000 then 1 else 0;
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) + 4 * 60 * 60 * 1000 and getTime() <= RegularTradingEnd(getYYYYMMDD()) + 4 * 60 * 60 * 1000;
def ONhigh = if !RTH and RTH[1] then h else if !RTH and h > ONhigh[1] then h else ONhigh[1];
def ONhighBar = if !RTH and h == ONhigh then BarNumber() else ONhighBar[1];
def ONlow = if !RTH and RTH[1] then l else if RTH then Double.NaN else if !RTH and l < ONlow[1] then l else ONlow[1];
def ONlowBar = if !RTH and l == ONlow then BarNumber() else ONlowBar[1];
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then h else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar) then l else OverNightLow[1];
plot ONH = if Intraday and OverNightHigh then OverNightHigh else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.green);
plot ONL = if Intraday and OverNightLow then OverNightLow else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.LINE);
ONL.SetDefaultColor(Color.red);
ONH.HideBubble();
ONL.HideBubble();
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "L: " + AsPrice(OverNightLow), Color.white, 0);
# End Code
 
This code shows today's high and low. But I can’t add the high and low prices to this code. Tell me how to display it?

input PlotOverNightExtremes = yes;
def o = open;
def h = high;
def l = low;
def c = close;
def bar = barNumber();
def Intraday = if GetAggregationPeriod() < 86400000 then 1 else 0;
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) + 4 * 60 * 60 * 1000 and getTime() <= RegularTradingEnd(getYYYYMMDD()) + 4 * 60 * 60 * 1000;
def ONhigh = if !RTH and RTH[1] then h else if !RTH and h > ONhigh[1] then h else ONhigh[1];
def ONhighBar = if !RTH and h == ONhigh then BarNumber() else ONhighBar[1];
def ONlow = if !RTH and RTH[1] then l else if RTH then Double.NaN else if !RTH and l < ONlow[1] then l else ONlow[1];
def ONlowBar = if !RTH and l == ONlow then BarNumber() else ONlowBar[1];
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then h else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar) then l else OverNightLow[1];
plot ONH = if Intraday and OverNightHigh then OverNightHigh else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.green);
plot ONL = if Intraday and OverNightLow then OverNightLow else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.LINE);
ONL.SetDefaultColor(Color.red);
ONH.HideBubble();
ONL.HideBubble();
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "L: " + AsPrice(OverNightLow), Color.white, 0);
# End Code

The following hs the prices displayed in bubbles at the high/low. The bubble for the low was already in the code, so this shows the high. Just add it to the bottom of your code.

Screenshot 2024-01-31 145241.png
Code:
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "H: " + AsPrice(OverNightHigh), Color.white, 1);
 
This gives you an option to extend the line plots across the whole chart or just in expansion as the original. Added a bubblemover input to handle both plot methods.
Sleepy or anyone, Could this be modified for futures ? Specifically, want to capture the RTH open of ES (9:30am) Tried this version, but doesn't pick it up.

Thanks!
 
Sleepy or anyone, Could this be modified for futures ? Specifically, want to capture the RTH open of ES (9:30am) Tried this version, but doesn't pick it up.

Thanks!


This modifies corrected link to also work on futures and adds Today's Open.

Screenshot 2024-03-20 071710.png

Code:
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures
#[email protected]

#Modified by Sleepyz
#Extended Lines across chart
#Added Today's RTH open
#Added Mode choice between RTHrs v EXTrs Sessions

input mode                      = {default RTHrs, EXTHrs};
input extend_lines_across_chart = yes;
input rthbegin                  = 0930;
input rthend                    = 1600;
input extend                    = 1800;
input agg                       = AggregationPeriod.DAY;
input showOnlyLastPeriod        = no;
input showBubbles               = yes;
input showValuesInBubbles       = yes;

plot currentrthOpen;
plot prevDayClose;
plot prevDayLow;
plot prevDayHigh;

def NA    = Double.NaN;
def bn    = BarNumber();
def exp   = IsNaN(close);
def rth   = SecondsFromTime(rthbegin) > - 0 and SecondsFromTime(rthend) <= 0;
def ymd   = GetYYYYMMDD();
def count = if !IsNaN(close) and ymd != ymd[1] then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count;

################# RTH Open
def rthopen      = if (GetDay() == GetLastDay() or exp) and SecondsFromTime(rthbegin) == 0
                   then open
                   else rthopen[1];
currentrthOpen   = if extend_lines_across_chart == yes
                   then HighestAll(rthopen)
                   else if exp
                   then rthopen
                   else NA;

################# Low
def rthclose = CompoundValue(1, if cond == 1  and SecondsFromTime(rthend) == 0 then close else rthclose[1], low);
def extclose = CompoundValue(1, if cond == 1 and SecondsFromTime(extend) == 0 then close[1] else extclose[1], low);

def hpdclose = if mode == mode.RTHrs and GetDay() == GetLastDay()
               then rthclose[1]
               else if mode == mode.EXTHrs and GetDay() == GetLastDay()
               then  close("period" = agg)[1]
               else hpdclose[1];
prevDayClose = if extend_lines_across_chart == yes
               then HighestAll(hpdclose)
               else if exp
               then hpdclose
               else NA;

################# Low
def rthlow = CompoundValue(1, if cond == 1 and SecondsFromTime(rthbegin) == 0 then low else if cond == 1 and SecondsFromTime(rthend) <= 0 then Min(low, rthlow[1]) else rthlow[1], low);
def extlow = CompoundValue(1, if cond[1] == 2 and cond == 1 then low else if cond == 1 then Min(low, extlow[1]) else extlow[1], low);

def hpdlow = if mode == mode.RTHrs
             then HighestAll(if IsNaN(close[-1]) then rthlow[1] else Double.NaN)
             else if mode == mode.EXTHrs
             then HighestAll(if IsNaN(close[-1]) then extlow[1] else Double.NaN)
             else hpdlow[1];

prevDayLow = if extend_lines_across_chart == yes
             then HighestAll(hpdlow)
             else if exp
             then HighestAll(hpdlow)
             else NA;

################# High
def rthhigh = CompoundValue(1, if cond == 1 and SecondsFromTime(rthbegin) == 0 then high else if cond == 1 and SecondsFromTime(rthend) <= 0 then Max(high, rthhigh[1]) else rthhigh[1], high);
def exthigh = CompoundValue(1, if cond[1] == 2 and cond == 1 then high else if cond == 1 then Max(high, exthigh[1]) else exthigh[1], high);

def hpdhigh  = if mode == mode.RTHrs
               then HighestAll(if IsNaN(close[-1]) then rthhigh[1] else Double.NaN)
               else if mode == mode.EXTHrs
               then HighestAll(if IsNaN(close[-1]) then exthigh[1] else Double.NaN)
               else hpdhigh[1];

prevDayHigh  = if extend_lines_across_chart == yes
               then HighestAll(hpdhigh)
               else if exp
               then HighestAll(hpdhigh)
               else NA;

input bubblemover = 1;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , currentrthOpen[b], if showValuesInBubbles then "RTHOpen $" + currentrthOpen[b] else "RTHOpen", Color.WHITE, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayClose[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPClose $" + prevDayClose[b]
     else "RthPClose $" + prevDayClose[b]
else if mode == mode.RTHrs
then "RthPClose"
else "ExtPClose"), Color.YELLOW, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayLow[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPLow $" + prevDayLow[b]
     else "RthPLoww $" + prevDayLow[b]
else if mode == mode.RTHrs
then "RthPLow"
else "ExtPLow"), Color.RED, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayHigh[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPHigh $" + prevDayHigh[b]
     else "RthPHigh $" + prevDayHigh[b]
else if mode == mode.RTHrs
then "RthPHigh"
else "ExtPHigh"), Color.GREEN, yes);

currentrthOpen.SetDefaultColor(Color.WHITE);
prevDayLow.SetDefaultColor(Color.RED);
prevDayHigh.SetDefaultColor(Color.GREEN);
prevDayClose.SetDefaultColor(Color.YELLOW);
prevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
Last edited:
This modifies corrected link to also work on futures and adds Today's Open.
Sleepy,

This is wonderful. Thank you for all you do. Now that I see it on the chart with extended hours turned on, it looks like it's picking up the levels as of Asia open.

Would it be possible to have an input to provide for the levels to paint for either ETH and/or RTH ?

So as an example, come tomorrow at the cash open, you'll have previous RTH open and current open/ previous high/low of yesterdays rth session and previous close.

with eth turned on, you will see the eth session (18:00 - 9:29) high/lows/open/close. Obviously you can deselect the plots that work so as to not clutter the chart and turn off bubbles and assign custom colors just for ETH (pre-market) levels.

I think the folks who use futures as a gauge intraday would really find this to be useful. And it would allow me to move away from tradingview. lol
 
Sleepy,

This is wonderful. Thank you for all you do. Now that I see it on the chart with extended hours turned on, it looks like it's picking up the levels as of Asia open.

Would it be possible to have an input to provide for the levels to paint for either ETH and/or RTH ?

So as an example, come tomorrow at the cash open, you'll have previous RTH open and current open/ previous high/low of yesterdays rth session and previous close.

with eth turned on, you will see the eth session (18:00 - 9:29) high/lows/open/close. Obviously you can deselect the plots that work so as to not clutter the chart and turn off bubbles and assign custom colors just for ETH (pre-market) levels.

I think the folks who use futures as a gauge intraday would really find this to be useful. And it would allow me to move away from tradingview. lol

This is set to work on /ES related Futures. Use the mode input to select the trading hours,
[Minor correction to names in bubbles when leaving values out of bubbles 3/21 6:43PM ET]

Screenshot 2024-03-21 115232.png

Code:
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures
#[email protected]

#Modified by Sleepyz
#Extended Lines across chart
#Added Today's RTH open
#Added Mode choice between RTHrs v EXTrs Sessions

input mode                      = {default RTHrs, EXTHrs};
input extend_lines_across_chart = yes;
input rthbegin                  = 0930;
input rthend                    = 1600;
input extend                    = 1800;
input agg                       = AggregationPeriod.DAY;
input showOnlyLastPeriod        = no;
input showBubbles               = yes;
input showValuesInBubbles       = yes;

plot currentrthOpen;
plot prevDayClose;
plot prevDayLow;
plot prevDayHigh;

def NA    = Double.NaN;
def bn    = BarNumber();
def exp   = IsNaN(close);
def rth   = SecondsFromTime(rthbegin) > - 0 and SecondsFromTime(rthend) <= 0;
def ymd   = GetYYYYMMDD();
def count = if !IsNaN(close) and ymd != ymd[1] then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count;

################# RTH Open
def rthopen      = if (GetDay() == GetLastDay() or exp) and SecondsFromTime(rthbegin) == 0
                   then open
                   else rthopen[1];
currentrthOpen   = if extend_lines_across_chart == yes
                   then HighestAll(rthopen)
                   else if exp
                   then rthopen
                   else NA;

################# Low
def rthclose = CompoundValue(1, if cond == 1  and SecondsFromTime(rthend) == 0 then close else rthclose[1], low);
def extclose = CompoundValue(1, if cond == 1 and SecondsFromTime(extend) == 0 then close[1] else extclose[1], low);

def hpdclose = if mode == mode.RTHrs and GetDay() == GetLastDay()
               then rthclose[1]
               else if mode == mode.EXTHrs and GetDay() == GetLastDay()
               then  close("period" = agg)[1]
               else hpdclose[1];
prevDayClose = if extend_lines_across_chart == yes
               then HighestAll(hpdclose)
               else if exp
               then hpdclose
               else NA;

################# Low
def rthlow = CompoundValue(1, if cond == 1 and SecondsFromTime(rthbegin) == 0 then low else if cond == 1 and SecondsFromTime(rthend) <= 0 then Min(low, rthlow[1]) else rthlow[1], low);
def extlow = CompoundValue(1, if cond[1] == 2 and cond == 1 then low else if cond == 1 then Min(low, extlow[1]) else extlow[1], low);

def hpdlow = if mode == mode.RTHrs
             then HighestAll(if IsNaN(close[-1]) then rthlow[1] else Double.NaN)
             else if mode == mode.EXTHrs
             then HighestAll(if IsNaN(close[-1]) then extlow[1] else Double.NaN)
             else hpdlow[1];

prevDayLow = if extend_lines_across_chart == yes
             then HighestAll(hpdlow)
             else if exp
             then HighestAll(hpdlow)
             else NA;

################# High
def rthhigh = CompoundValue(1, if cond == 1 and SecondsFromTime(rthbegin) == 0 then high else if cond == 1 and SecondsFromTime(rthend) <= 0 then Max(high, rthhigh[1]) else rthhigh[1], high);
def exthigh = CompoundValue(1, if cond[1] == 2 and cond == 1 then high else if cond == 1 then Max(high, exthigh[1]) else exthigh[1], high);

def hpdhigh  = if mode == mode.RTHrs
               then HighestAll(if IsNaN(close[-1]) then rthhigh[1] else Double.NaN)
               else if mode == mode.EXTHrs
               then HighestAll(if IsNaN(close[-1]) then exthigh[1] else Double.NaN)
               else hpdhigh[1];

prevDayHigh  = if extend_lines_across_chart == yes
               then HighestAll(hpdhigh)
               else if exp
               then HighestAll(hpdhigh)
               else NA;

input bubblemover = 1;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , currentrthOpen[b], if showValuesInBubbles then "RTHOpen $" + currentrthOpen[b] else "RTHOpen", Color.WHITE, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayClose[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPClose $" + prevDayClose[b]
     else "RthPClose $" + prevDayClose[b]
else if mode == mode.RTHrs
then "RthPClose"
else "ExtPClose"), Color.YELLOW, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayLow[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPLow $" + prevDayLow[b]
     else "RthPLoww $" + prevDayLow[b]
else if mode == mode.RTHrs
then "RthPLow"
else "ExtPLow"), Color.RED, yes);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevDayHigh[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ExtPHigh $" + prevDayHigh[b]
     else "RthPHigh $" + prevDayHigh[b]
else if mode == mode.RTHrs
then "RthPHigh"
else "ExtPHigh"), Color.GREEN, yes);

currentrthOpen.SetDefaultColor(Color.WHITE);
prevDayLow.SetDefaultColor(Color.RED);
prevDayHigh.SetDefaultColor(Color.GREEN);
prevDayClose.SetDefaultColor(Color.YELLOW);
prevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
Last edited:
This is set to work on /ES related Futures. Use the mode input to select the trading hours,
[Minot correction to names in bubbles when leaving values out of bubbles 3/21 6:43PM ET]
Hey Sleepy,

Doing some testing and adding the script twice to ES so that I can track RTH and ETH separately and found a slight bug (I think) I have EXT added and deselected show plot/bubble from the open/close and chose to not show bubbles yet they still show ?

Not sure if I'm doing something wrong on my end.

Thanks!

1711070292400.png
1711070308996.png
 
Hey Sleepy,

Doing some testing and adding the script twice to ES so that I can track RTH and ETH separately and found a slight bug (I think) I have EXT added and deselected show plot/bubble from the open/close and chose to not show bubbles yet they still show ?

Not sure if I'm doing something wrong on my end.

Thanks!

View attachment 21399View attachment 21400

Thanks for letting me know! It should now be fixed in above post. Sorry, it apparently never had the showbubbles included in the bubble code.

https://usethinkscript.com/threads/previous-day-high-low-close-for-thinkorswim.3494/post-139643
 
Hey Sleepy,

Doing some testing and adding the script twice to ES so that I can track RTH and ETH separately and found a slight bug (I think) I have EXT added and deselected show plot/bubble from the open/close and chose to not show bubbles yet they still show ?

Not sure if I'm doing something wrong on my end.

Thanks!

View attachment 21399View attachment 21400
Previous Day Closing price for Regular Trading Hours (RTH) is actually 15:59.
Closing bell sounds at 16:00.
16:00 would be beginning of prices (OHLC) for Extended Trading Hours (ETH), just like 09:30 is for RTH.
<If using16:00 is what the requestor desires then ignore my post>

1711126024231.png
 
Thanks for letting me know! It should now be fixed in above post. Sorry, it apparently never had the showbubbles included in the bubble code.

https://usethinkscript.com/threads/previous-day-high-low-close-for-thinkorswim.3494/post-139643
Hey Sleepy,

Back from vacation and I'm noticing that when changing the agg, it doesn't change the values. Not sure if that logic was coded. Would be great to add a new study just for weekly/monthly levels and current Day levels. Happens on /ES just the same.

Also noticed that the /ES EXThrs, still shows the bubble even when it's deselected (both plot and bubble)

Thanks!

1711905493096.png

1711905454580.png
 
Hey Sleepy,

Back from vacation and I'm noticing that when changing the agg, it doesn't change the values. Not sure if that logic was coded. Would be great to add a new study just for weekly/monthly levels and current Day levels. Happens on /ES just the same.

Also noticed that the /ES EXThrs, still shows the bubble even when it's deselected (both plot and bubble)

Thanks!

View attachment 21476
View attachment 21475

1. This allows you to choose
input agg = {default DAY, WEEK, MONTH};
input mode = {default RTHrs, EXTHrs};
2. There is not a function to use for RTHrs only data for futures. This code uses data on the chart being viewed to provide this. So for example, the monthly agg will need a 90d chart agg to provide the data.
3. The bubbles and labels are optional. The bubbles were fixed and made optional in the prior code https://usethinkscript.com/threads/previous-day-high-low-close-for-thinkorswim.3494/post-139676
4. The image shows the RTHrs version with all 3 aggs

Screenshot 2024-04-03 111715.png
Code:
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures_v1
#[email protected]

#Modified by Sleepyz
#Extended Lines across chart
#Added Today's RTH open
#Added Mode choice between RTHrs v EXTrs Sessions

input agg                       = {default DAY, WEEK, MONTH};
input mode                      = {default RTHrs, EXTHrs};
input extend_lines_across_chart = yes;
input rthbegin                  = 0930;
input rthend                    = 1600;
input extend                    = 1800;

input showBubbles               = no;
input showValuesInBubbles       = yes;
input showLabels                = yes;
input showValuesInLabels        = yes;


plot todayrthOpen;
plot prevClose;
plot prevLow;
plot prevHigh;

def NA    = Double.NaN;
def bn    = BarNumber();
def exp   = IsNaN(close);
def rth   = SecondsFromTime(rthbegin) > - 0 and SecondsFromTime(rthend) <= 0;
def start = GetDayOfWeek(GetYYYYMMDD());

def period  =
if agg == agg.MONTH then GetMonth()
else if agg == agg.WEEK then GetWeek()
else GetYYYYMMDD();


def count = if !IsNaN(close) and period != period[1] then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count;

################# RTH Open
def rthopen      = if (GetDay() == GetLastDay() or exp) and SecondsFromTime(rthbegin) == 0
                   then open
                   else rthopen[1];
todayrthOpen     = if extend_lines_across_chart == yes
                   then HighestAll(rthopen)
                   else if exp
                   then rthopen
                   else NA;

################# close
def extclose = close(period = agg)[1];
def rthclose = CompoundValue(1, if cond == 1 and SecondsFromTime(rthend) == 0 then close[1] else rthclose[1], close);

def hpdclose = if mode == mode.RTHrs and GetDay() == GetLastDay()
               then rthclose[1]
               else if mode == mode.EXTHrs and GetDay() == GetLastDay()
               then  close("period" = agg)[1]
               else hpdclose[1];
prevClose    = if extend_lines_across_chart == yes
               then HighestAll(hpdclose)
               else if exp
               then hpdclose
               else NA;

################# Low
def extlow = low(period = agg)[1];

def rthlowday = CompoundValue(1,
                if cond[1] == 2 then Double.NaN
                else if cond == 1 and SecondsFromTime(rthbegin) == 0
                then low
                else if cond >= 1 and rth == 1 and low < rthlowday[1]
                then low else rthlowday[1], low);
def rthlowweek = if cond == 1 then if start[1] != 1 and start == 1 then NA
                 else if start == 1 and SecondsFromTime(0930) == 0 then low
                 else if start >= 1 and rth and low < rthlowweek[1] then low
                 else rthlowweek[1]
                 else NA;
def rthlowmon  = if cond == 1 then if cond[1] == 2 and cond == 1 then NA
                 else if start == 1 and SecondsFromTime(0930) == 0 then low
                 else if start >= 1 and rth and low < rthlowmon[1] then low
                 else rthlowmon[1]
                 else NA;

def hpdlow     = if mode == mode.RTHrs and agg == agg.DAY
                 then HighestAll(if IsNaN(close[-1]) then rthlowday else NA)
                 else if mode == mode.RTHrs and agg == agg.WEEK
                 then LowestAll(if cond == 1 then rthlowweek else NA)
                 else if mode == mode.RTHrs and agg == agg.MONTH
                 then LowestAll(if cond == 1 then rthlowmon else NA)
                 else if mode == mode.EXTHrs
                 then HighestAll(if IsNaN(close[-1]) then extlow else NA)
                 else hpdlow[1];

prevLow         = if extend_lines_across_chart == yes
                  then HighestAll(hpdlow)
                  else if exp
                  then HighestAll(hpdlow)
                  else NA;

################# High
def exthigh     = high(period = agg)[1];
def rthhighday  = CompoundValue(1,
                  if cond == 1 and SecondsFromTime(rthbegin) == 0
                  then high
                  else if cond == 1 and rth
                  then Max(high, rthhighday[1])
                  else rthhighday[1], high);
def rthhighweek = if cond == 1 then
                  if start[1] != 1 and start == 1
                  then Double.NaN
                  else if start == 1 and SecondsFromTime(0930) == 0
                  then high
                  else if start >= 1 and rth and high > rthhighweek[1]
                  then high
                  else rthhighweek[1]
                  else NA;
def rthhighmon  = if cond == 1 then
                  if cond[1] == 2 and cond == 1
                  then Double.NaN
                  else if start == 1 and SecondsFromTime(0930) == 0
                  then high
                  else if start >= 1 and rth and high > rthhighmon[1]
                  then high
                  else rthhighmon[1]
                  else NA;

def hpdhigh  = if mode == mode.RTHrs and agg == agg.DAY
               then HighestAll(if IsNaN(close[-1]) then rthhighday else NA)
               else if mode == mode.RTHrs and agg == agg.WEEK
               then HighestAll(if cond == 1 then rthhighweek else NA)
               else if mode == mode.RTHrs and agg == agg.MONTH
               then HighestAll(if cond == 1 then rthhighmon else NA)
               else if mode == mode.EXTHrs
               then HighestAll(if IsNaN(close[-1]) then exthigh else Double.NaN)
               else hpdhigh[1];

prevHigh     = if extend_lines_across_chart == yes
               then HighestAll(hpdhigh)
               else if exp
               then HighestAll(hpdhigh)
               else NA;


#Labels
AddLabel(showLabels, mode, Color.WHITE);
AddLabel(showLabels, "PREV " + agg, Color.MAGENTA);
AddLabel(showLabels,
if showValuesInLabels then "RO $" + todayrthOpen
else "TO", todayrthOpen.TakeValueColor());
AddLabel(showLabels,
(if showValuesInLabels
then "PH $" + prevHigh
else "PH"), Color.GREEN);
AddLabel(showLabels,
(if showValuesInLabels
then "PL $" + prevLow
else "PL"), Color.RED);
AddLabel(showLabels,
(if showValuesInLabels then "PC $" + prevClose
else "PC"), Color.YELLOW);


#Bubbles
input bubblemover = 1;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , todayrthOpen[b],
if showValuesInBubbles then "TO $" + todayrthOpen[b] else "TO", Color.WHITE, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevClose[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "EC $" + prevClose[b]
     else "RC $" + prevClose[b]
else if mode == mode.RTHrs
then "RC"
else "EC"), Color.YELLOW, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevLow[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "EL $" + prevLow[b]
     else "RL $" + prevLow[b]
else if mode == mode.RTHrs
then "RL"
else "EL"), Color.RED, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevHigh[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "EH $" + prevHigh[b]
     else "RH $" + prevHigh[b]
else if mode == mode.RTHrs
then "RH"
else "EH"), Color.GREEN, yes);

todayrthOpen.SetDefaultColor(Color.WHITE);
prevLow.SetDefaultColor(Color.RED);
prevHigh.SetDefaultColor(Color.GREEN);
prevClose.SetDefaultColor(Color.YELLOW);
prevLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
1. This allows you to choose
input agg = {default DAY, WEEK, MONTH};
input mode = {default RTHrs, EXTHrs};
2. There is not a function to use for RTHrs only data for futures. This code uses data on the chart being viewed to provide this. So for example, the monthly agg will need a 90d chart agg to provide the data.
3. The bubbles and labels are optional. The bubbles were fixed and made optional in the prior code https://usethinkscript.com/threads/previous-day-high-low-close-for-thinkorswim.3494/post-139676
4. The image shows the RTHrs version with all 3 aggs
@SleepyZ

Finally back at my desk to do some testing and noticed that when I add the second study to try and capture the EXT levels, it' doesn't pick them up ?

As an example, today's EXT high low ( from 18:00 to 9:29am) for /ES is
5120.25 - EXT Hi
5081.25 - EXT low

So ideally for every session you would want to see the following levels (Day mode)

RTHhrs
Current Open
Yday close
yday RTH hi
yday rth low

EXThrs (18:00 -9:29am)
Current EXt Hi
Current Ext low
(EXT open and close levels not as necessary, if this helps)

So this levels, and being able to adjust their transparency and line width and color, would be a simple and effective baseline to start each session. More often than not, these levels are interreacted with daily.

1713296366157.png
 
@SleepyZ

Finally back at my desk to do some testing and noticed that when I add the second study to try and capture the EXT levels, it' doesn't pick them up ?

As an example, today's EXT high low ( from 18:00 to 9:29am) for /ES is
5120.25 - EXT Hi
5081.25 - EXT low

So ideally for every session you would want to see the following levels (Day mode)

RTHhrs
Current Open
Yday close
yday RTH hi
yday rth low

EXThrs (18:00 -9:29am)
Current EXt Hi
Current Ext low
(EXT open and close levels not as necessary, if this helps)

So this levels, and being able to adjust their transparency and line width and color, would be a simple and effective baseline to start each session. More often than not, these levels are interreacted with daily.

View attachment 21612

This will give you options for colors at the input screen by using defined global colors.
The mode for extended hours now only works for TODAY's premarket (1800 - 929)
The RTH Open will only display with mode - RTHrs
The image shows both RTHrs and EXThrs

Screenshot 2024-04-17 101808.png
Code:
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures_v1
#[email protected]

#Modified by Sleepyz
#Extended Lines across chart
#Added Today's RTH open
#Added Mode choice between RTHrs v EXTrs Sessions
#Exthrs mode only works on TODAY's Premarket (1800 - 929) for futures

input agg                       = {default DAY, WEEK, MONTH};
input mode                      = {default RTHrs, EXTHrs};
input extend_lines_across_chart = yes;
input rthbegin                  = 0930;
input rthend                    = 1600;
input extend                    = 1800;

input showBubbles               = no;
input showValuesInBubbles       = yes;
input showLabels                = yes;
input showValuesInLabels        = yes;


plot todayrthOpen;
plot prevClose;
plot prevLow;
plot prevHigh;

def NA    = Double.NaN;
def bn    = BarNumber();
def exp   = IsNaN(close);
def rth   = SecondsFromTime(rthbegin) > - 0 and SecondsFromTime(rthend) <= 0;
def start = GetDayOfWeek(GetYYYYMMDD());

def period  =
if agg == agg.MONTH then GetMonth()
else if agg == agg.WEEK then GetWeek()
else GetYYYYMMDD();

def count = if !IsNaN(close) and period != period[1] then count[1] + 1 else count[1];
def cond  = HighestAll(count) - count;

################# RTH Open
def rthopen      = if mode == mode.RTHrs and (GetDay() == GetLastDay() or exp) and SecondsFromTime(rthbegin) == 0
                   then open
                   else rthopen[1];
todayrthOpen     = if extend_lines_across_chart == yes
                   then HighestAll(rthopen)
                   else if exp
                   then rthopen
                   else NA;

################# close
def extclose = close(period = agg)[1];
def rthclose = CompoundValue(1, if cond == 1 and SecondsFromTime(rthend) == 0 then close[1] else rthclose[1], close);

def hpdclose = if mode == mode.RTHrs and GetDay() == GetLastDay()
               then rthclose[1]
               else if mode == mode.EXTHrs and GetDay() == GetLastDay()
               then  close("period" = agg)[1]
               else hpdclose[1];
prevClose    = if extend_lines_across_chart == yes and mode == mode.RTHrs
               then HighestAll(hpdclose)
               else if exp and mode == mode.RTHrs
               then hpdclose
               else NA;

################# Low

def extlowtoday = CompoundValue(1,
                  if cond == 0 and cond[1] == 1
                  then low
                  else if SecondsFromTime(0929) <= 0
                  then Min(low, extlowtoday[1])
                  else extlowtoday[1], low);

def rthlowday   = CompoundValue(1,
                  if cond[1] == 2 then Double.NaN
                  else if cond == 1 and SecondsFromTime(rthbegin) == 0
                  then low
                  else if cond >= 1 and rth == 1 and low < rthlowday[1]
                  then low else rthlowday[1], low);

def rthlowweek = if cond == 1 then if start[1] != 1 and start == 1 then NA
                 else if start == 1 and SecondsFromTime(rthbegin) == 0 then low
                 else if start >= 1 and rth and low < rthlowweek[1] then low
                 else rthlowweek[1]
                 else NA;

def rthlowmon  = if cond == 1 then if cond[1] == 2 and cond == 1 then NA
                 else if start == 1 and SecondsFromTime(rthbegin) == 0 then low
                 else if start >= 1 and rth and low < rthlowmon[1] then low
                 else rthlowmon[1]
                 else NA;

def hpdlow     = if mode == mode.RTHrs and agg == agg.DAY
                 then HighestAll(if IsNaN(close[-1]) then rthlowday else NA)
                 else if mode == mode.RTHrs and agg == agg.WEEK
                 then LowestAll(if cond == 1 then rthlowweek else NA)
                 else if mode == mode.RTHrs and agg == agg.MONTH
                 then LowestAll(if cond == 1 then rthlowmon else NA)
                 else if mode == mode.EXTHrs
                 then HighestAll(if IsNaN(close[-1]) then extlowtoday else NA)
                 else hpdlow[1];

prevLow        = if extend_lines_across_chart == yes
                 then HighestAll(hpdlow)
                 else if exp
                 then HighestAll(hpdlow)
                 else NA;

################# High
def exthightoday = if cond == 0 and cond[1] == 1
                   then high
                   else if SecondsFromTime(0929) <= 0
                   then Max(high, exthightoday[1])
                   else exthightoday[1];
def rthhighday   = CompoundValue(1,
                   if cond == 1 and SecondsFromTime(rthbegin) == 0
                   then high
                   else if cond == 1 and rth
                   then Max(high, rthhighday[1])
                   else rthhighday[1], high);
def rthhighweek = if cond == 1 then
                  if start[1] != 1 and start == 1
                  then Double.NaN
                  else if start == 1 and SecondsFromTime(0930) == 0
                  then high
                  else if start >= 1 and rth and high > rthhighweek[1]
                  then high
                  else rthhighweek[1]
                  else NA;
def rthhighmon  = if cond == 1 then
                  if cond[1] == 2 and cond == 1
                  then Double.NaN
                  else if start == 1 and SecondsFromTime(0930) == 0
                  then high
                  else if start >= 1 and rth and high > rthhighmon[1]
                  then high
                  else rthhighmon[1]
                  else NA;

def hpdhigh  = if mode == mode.RTHrs and agg == agg.DAY
               then HighestAll(if IsNaN(close[-1]) then rthhighday else NA)
               else if mode == mode.RTHrs and agg == agg.WEEK
               then HighestAll(if cond == 1 then rthhighweek else NA)
               else if mode == mode.RTHrs and agg == agg.MONTH
               then HighestAll(if cond == 1 then rthhighmon else NA)
               else if mode == mode.EXTHrs
               then HighestAll(if IsNaN(close[-1]) then exthightoday else Double.NaN)
               else hpdhigh[1];

prevHigh     = if extend_lines_across_chart == yes
               then HighestAll(hpdhigh)
               else if exp
               then HighestAll(hpdhigh)
               else NA;


#Labels
AddLabel(showLabels, mode, Color.WHITE);
AddLabel(showLabels, if mode == mode.EXTHrs then "TODAY's PREMKT" else "PREV " + agg, Color.LIGHT_GRAY);
AddLabel(showLabels and mode == mode.RTHrs,
if showValuesInLabels and mode == mode.RTHrs then "RO $" + todayrthOpen
else "TO", todayrthOpen.TakeValueColor());
AddLabel(showLabels,
(if showValuesInLabels and mode == mode.EXTHrs
then "H $" + exthightoday
else if showValuesInLabels and mode == mode.RTHrs
then "H $" + prevHigh
else "H"), if mode == mode.EXTHrs then GlobalColor("EH") else GlobalColor("PH"));
AddLabel(showLabels,
(if showValuesInLabels and mode == mode.EXTHrs
then "L $" + extlowtoday
else if showValuesInLabels
then "L $" + prevLow
else "L"), if mode == mode.EXTHrs then GlobalColor("EL") else GlobalColor("PL"));
AddLabel(showLabels,
(if showValuesInLabels and mode == mode.RTHrs then "RPC $" + prevClose
else ""), GlobalColor("PC"));


#Bubbles
input bubblemover = 1;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , todayrthOpen[b],
if showValuesInBubbles then "TO $" + todayrthOpen[b] else "TO", GlobalColor("TO"), yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevClose[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then ""
     else "RPC $" + prevClose[b]
else if mode == mode.RTHrs
then "RC"
else ""), GlobalColor("PC"), yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevLow[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ETL $" + prevLow[b]
     else "RPL $" + prevLow[b]
else if mode == mode.RTHrs
then "RPL"
else "ETL"), if mode == mode.EXTHrs then GlobalColor("EL") else GlobalColor("PL"), yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevHigh[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
     then "ETH $" + prevHigh[b]
     else "RPH $" + prevHigh[b]
else if mode == mode.RTHrs
then "RPH"
else "ETH"), if mode == mode.EXTHrs then GlobalColor("EH") else GlobalColor("PH"), yes);

#Colors
DefineGlobalColor("TO", Color.WHITE);
DefineGlobalColor("PL", Color.RED);
DefineGlobalColor("PH", Color.GREEN);
DefineGlobalColor("PC", Color.YELLOW);
DefineGlobalColor("EH", Color.CYAN);
DefineGlobalColor("EL", Color.MAGENTA);

todayrthOpen.SetDefaultColor(GlobalColor("TO"));
prevLow.AssignValueColor(if mode == mode.EXTHrs then GlobalColor("EL") else GlobalColor("PL"));
prevHigh.AssignValueColor(if mode == mode.EXTHrs then GlobalColor("EH") else GlobalColor("PH"));
prevClose.SetDefaultColor(GlobalColor("PC"));
prevLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 

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