Previous Day High/Low/Close For ThinkOrSwim

Hey @SleepyZ

So when EXThrs is selected, the TO line reports 0 ? I think if possible even with RTH or EXT selected, it should always plot the current rth open (TO). Hoping you can adjust that.

Also, turning off the plot doesn't seem to remove it. In addition, would love to be able to change the colors of the ETH and ETL, if possible.

Thanks!!

View attachment 21665

As mentioned above the RTHopen only appears in the code when you are using RTHrs mode to avoid it duplicating when both modes are on the same chart. I assumed you always used both modes on the same chart.

1. The following allows you to control the display of the rthropen at input showrthrsopenplot = yes;.
2. So if you are loading both modes on one chart, set the one of the loads input showrthrsopenplot = no
3. In the following you can change the colors of all lines/bubbles at the same place, at the input screen, global colors.
4. When you are using the script in EXThrs mode, change the colors at the input screen below or if you want to universally change it, then do it in the fulll code v1a below under the #colors section
Screenshot 2024-04-22 095458.png
Code:
#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);

Full Revised code v1a
Code:
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures_v1a
#[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 showrthrsopenplot         = yes;
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 and mode == mode.RTHrs
               then HighestAll(hpdclose)
               else if exp and mode == mode.RTHrs
               then hpdclose
               else NA;

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

def extlowtoday = if cond[1] == 1 and cond == 0
                  then low
                  else if cond == 0 and GetTime() < RegularTradingStart(GetYYYYMMDD())
                  then  Min(low, extlowtoday[1])
                  else extlowtoday[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(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 hpdlow
                 else if exp
                 then HighestAll(hpdlow)
                 else NA;

################# High
def exthightoday = if cond == 0 and cond[1] == 1
                   then high
                   else if cond==0 and GetTime() < RegularTradingStart(GetYYYYMMDD())
                   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(rthbegin) == 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(rthbegin) == 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 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 showrthrsopenplot,
if showValuesInLabels 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 showrthrsopenplot 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.SetHiding(!showrthrsopenplot);
todayrthOpen.AssignValueColor(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.AssignValueColor(GlobalColor("PC"));
prevLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
Last edited:

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

As mentioned above the RTHopen only appears in the code when you are using RTHrs mode to avoid it duplicating when both modes are on the same chart. I assumed you always used both modes on the same chart.

1. The following allows you to control the display of the rthropen at input showrthrsopenplot = yes;.
2. So if you are loading both modes on one chart, set the one of the loads input showrthrsopenplot = no
3. In the following you can change the colors of all lines/bubbles at the same place, at the input screen, global colors.
4. When you are using the script in EXThrs mode, change the colors at the input screen below or if you want to universally change it, then do it in the fulll code v1a below under the #colors section



Full Revised code v1a
Thanks @SleepyZ

Not sure what happened, but the ETL line doesn't seem to pickup the lows from 18:00 with the updated code? See screenshot

Thanks man!!

1713883742445.png
 
That worked @SleepyZ

On a separate but related note, would it be possible (or not too much work) to code the indicator to provide at least 3-7 days of previous levels and follow this "stair-step" pattern as shown with the pink arrows? I'm using a code posted by @Svanoy for some other levels and it has that feature, which when zooming out can be helpful for analysis (especially on higher timeframes)

Thanks for your time and awesome help. Truly appreciated.

H

1713965845485.png
 
That worked @SleepyZ

On a separate but related note, would it be possible (or not too much work) to code the indicator to provide at least 3-7 days of previous levels and follow this "stair-step" pattern as shown with the pink arrows? I'm using a code posted by @Svanoy for some other levels and it has that feature, which when zooming out can be helpful for analysis (especially on higher timeframes)

Thanks for your time and awesome help. Truly appreciated.

See if this works.

Screenshot 2024-04-24 132038.png
Code:
#Premarket_HL_Futures_ExtendedHrs_using_ProfileHL
input start = 1800;
input end   = 0929;
input bubblemover      = 0;
input showPriorbubbles = yes;
input showLastbubbles  = yes;
input extendlines      = yes;

def sec1    = SecondsFromTime(start);
def sec2    = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
              (sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
              (sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
                  if isTime1[1] == 0 and isTime1 == 1
                  then 1
                  else if isTime2
                  then 0
                  else aftermarket[1], 0);

def bars   = 100000;
def bn     = BarNumber();
def na     = Double.NaN;

def period = bn - 1;
def count  = CompoundValue(1,
             if aftermarket and period != period[1]
             then (count[1] + period - period[1]) % bars
             else count[1], 0);
def cond   = count < count[1] + period - period[1];

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

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

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow  = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

#Colors
DefineGlobalColor("H", Color.ORANGE);
DefineGlobalColor("L", Color.ORANGE);
DefineGlobalColor("C", Color.WHITE);

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
def  eclose = if sec1 == 0 then close[1] else eclose[1];
plot crange = eclose;
hrange.AssignValueColor(GlobalColor("H"));
lrange.AssignValueColor(GlobalColor("L"));
crange.AssignValueColor(GlobalColor("C"));

#Bubbles - Prior Days
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), hrange[bubblemover + 1], "PH", hrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), lrange[bubblemover + 1], "PL", lrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), crange[bubblemover + 1], "PC", crange.TakeValueColor());

#Bubbles - Last Plot
AddChartBubble(showLastbubbles and IsNaN(hrange[bubblemover]) and  !IsNaN(hrange[bubblemover + 1]), hrange[bubblemover + 1], "TH", hrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(hrange[bubblemover]) and  !IsNaN(hrange[bubblemover + 1]), lrange[bubblemover + 1], "TL", lrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(hrange[bubblemover]) and  !IsNaN(hrange[bubblemover + 1]), crange[bubblemover + 1], "PC", crange.TakeValueColor());
 
Last edited:
I like these versions of Previous Day High Low and Close and modified it a bit to suit my charting. I like to offset the Previous Close but keep the Highs and Lows on my chart as they might be pivot points? Here is a picture of it on my BestTradingChartSetup:


My modified code is:

##AsGood_PreviousDayHighLowClose
#Thanks to Welkin forceIndex Offset Close.

input aggregationPeriod = AggregationPeriod.DAY;
def yesterday_high = high(period = aggregationPeriod)[1];

plot static = yesterday_high;
static.AssignValueColor(color.White);
static.SetPaintingStrategy(PaintingStrategy.DASHES);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());

plot static1 = Yesterday_High;
static1.AssignValueColor(color.White);

input bubblemover = 4;
def b = bubblemover;
def limit1 = !IsNaN(close[b+1]) and IsNaN(close [4] );

AddChartBubble(limit1, static[b+1], "PrevDayHigh", Color.RED);

def NA = Double.NaN;

input agg = AggregationPeriod.DAY;

input showBubbles = yes;
input showValuesInBubbles = yes;
input spaceBetween = 1;

plot prevDayClose;

def exp = IsNaN(close[spaceBetween]);

prevDayClose = if exp then close("period"=agg)[1] else NA;

AddChartBubble(showBubbles, if IsNaN(prevDayClose[1]) and !IsNaN(prevDayClose) then prevDayClose else NA, if showValuesInBubbles then "PrevDayClose $"+prevDayClose else "PrevDayClose", Color.YELLOW, yes);
prevDayClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

input spacerText = "-----";
defineGlobalColor("Spacer Color", color.black);
AddLabel(yes, spacerText, GlobalColor("Spacer Color"));


def yesterday_low = low(period = aggregationPeriod)[1];

plot static2 = yesterday_low;
static2.AssignValueColor(color.White);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());


static2.AssignValueColor(color.White);
static2.SetPaintingStrategy(PaintingStrategy.DASHES);


def b1 = bubblemover;
def limit12= !IsNaN(close[b+1]) and IsNaN(close );

AddChartBubble(limit2, static2[b+1], "PrevDayLow", Color.Green);
 
I like these versions of Previous Day High Low and Close and modified it a bit to suit my charting. I like to offset the Previous Close but keep the Highs and Lows on my chart as they might be pivot points? Here is a picture of it on my BestTradingChartSetup:


My modified code is:

##AsGood_PreviousDayHighLowClose
#Thanks to Welkin forceIndex Offset Close.

input aggregationPeriod = AggregationPeriod.DAY;
def yesterday_high = high(period = aggregationPeriod)[1];

plot static = yesterday_high;
static.AssignValueColor(color.White);
static.SetPaintingStrategy(PaintingStrategy.DASHES);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());

plot static1 = Yesterday_High;
static1.AssignValueColor(color.White);

input bubblemover = 4;
def b = bubblemover;
def limit1 = !IsNaN(close[b+1]) and IsNaN(close [4] );

AddChartBubble(limit1, static[b+1], "PrevDayHigh", Color.RED);

def NA = Double.NaN;

input agg = AggregationPeriod.DAY;

input showBubbles = yes;
input showValuesInBubbles = yes;
input spaceBetween = 1;

plot prevDayClose;

def exp = IsNaN(close[spaceBetween]);

prevDayClose = if exp then close("period"=agg)[1] else NA;

AddChartBubble(showBubbles, if IsNaN(prevDayClose[1]) and !IsNaN(prevDayClose) then prevDayClose else NA, if showValuesInBubbles then "PrevDayClose $"+prevDayClose else "PrevDayClose", Color.YELLOW, yes);
prevDayClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

input spacerText = "-----";
defineGlobalColor("Spacer Color", color.black);
AddLabel(yes, spacerText, GlobalColor("Spacer Color"));


def yesterday_low = low(period = aggregationPeriod)[1];

plot static2 = yesterday_low;
static2.AssignValueColor(color.White);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());


static2.AssignValueColor(color.White);
static2.SetPaintingStrategy(PaintingStrategy.DASHES);


def b1 = bubblemover;
def limit12= !IsNaN(close[b+1]) and IsNaN(close );

AddChartBubble(limit2, static2[b+1], "PrevDayLow", Color.Green);
Thanks for sharing. I'd like being able to see those bubbles in the chart as I zoom into a lowertime frame for futures. I'd love to be able to add the current RTH open to this, so I'll try to somehow add it.
 
See if this works.
@SleepyZ This is awesome in its simplicity, exactly what I wanted and hope others find it really helpful.

One thing and I think we can close this one out is if you can remove or adjust the code to truly hide the PC. It logs the close from 18-00 to 9:29, which I don't personally use. However,in case you or someone else wants to use it, unchecking them in the settings doesn't hide it from the chart. See screenshot.

I'll use your other code to just log the RTH open. I need that and will look to make the colors for other levels set to a transparency of 0 so they aren't visible on the chart.

Ideally being able to see Prev day high, low, current rth open (in a separate script) presented in this stair-step way would be the final implementation of day levels that I would need and probably the most useful.

Appreciate you man.

H

1714073697947.png
 
Last edited:
@SleepyZ This is awesome in its simplicity, exactly what I wanted and hope others find it really helpful.

One thing and I think we can close this one out is if you can remove or adjust the code to truly hide the PC. It logs the close from 18-00 to 9:29, which I don't personally use. However,in case you or someone else wants to use it, unchecking them in the settings doesn't hide it from the chart. See screenshot.

I'll use your other code to just log the RTH open. I need that and will look to make the colors for other levels set to a transparency of 0 so they aren't visible on the chart.

Ideally being able to see Prev day high, low, current rth open (in a separate script) presented in this stair-step way would be the final implementation of day levels that I would need and probably the most useful.

Appreciate you man.

H

View attachment 21694

When you unplot a line, TOS has a glitch where it does not remove the bubble. So one way is for you would have to comment (#) the addchartbubble in your code to remove the bubble.

The RTH Open was added in place of the close in both the following RTH and ETH versions.

The same code was used to make the RTH version by just changing the inputs from 1800-0929 to 0930-1615

RTH version
#Premarket_HL_Futures_ExtendedHrs_using_ProfileHL_RTH

input showrthopen_plot = yes;
input start = 0930;
input end = 1615;
input rthstart = 0930;
input rthend = 1615;
input bubblemover = 0;
input showPriorbubbles = yes;
input showLastbubbles = yes;
input extendlines = yes;

def sec1 = SecondsFromTime(start);
def sec2 = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
(sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
(sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
if isTime1[1] == 0 and isTime1 == 1
then 1
else if isTime2
then 0
else aftermarket[1], 0);

def bars = 100000;
def bn = BarNumber();
def na = Double.NaN;

def period = bn - 1;
def count = CompoundValue(1,
if aftermarket and period != period[1]
then (count[1] + period - period[1]) % bars
else count[1], 0);
def cond = count < count[1] + period - period[1];

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

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

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

#Colors
DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);
DefineGlobalColor("O", Color.WHITE);

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
def ropen = if showrthopen_plot and SecondsFromTime(rthstart) == 0 then open else ropen[1];
plot orange = ropen;
hrange.AssignValueColor(GlobalColor("H"));
lrange.AssignValueColor(GlobalColor("L"));
orange.AssignValueColor(GlobalColor("O"));

#Bubbles - Prior Days
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), hrange[bubblemover + 1], "RH", hrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), lrange[bubblemover + 1], "RL", lrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), orange[bubblemover + 1], "RO", orange.TakeValueColor());

#Bubbles - Last Plot
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), hrange[bubblemover + 1], "RTH", hrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), lrange[bubblemover + 1], "RTL", lrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), orange[bubblemover + 1], "RTO", orange.TakeValueColor());

#
ETH version
#Premarket_HL_Futures_ExtendedHrs_using_ProfileHL_ETH

input showrthopen_plot = yes;
input start = 1800;
input end = 0929;
input rthstart = 0930;
input rthend = 1615;
input bubblemover = 0;
input showPriorbubbles = yes;
input showLastbubbles = yes;
input extendlines = yes;

def sec1 = SecondsFromTime(start);
def sec2 = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
(sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
(sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
if isTime1[1] == 0 and isTime1 == 1
then 1
else if isTime2
then 0
else aftermarket[1], 0);

def bars = 100000;
def bn = BarNumber();
def na = Double.NaN;

def period = bn - 1;
def count = CompoundValue(1,
if aftermarket and period != period[1]
then (count[1] + period - period[1]) % bars
else count[1], 0);
def cond = count < count[1] + period - period[1];

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

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

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

#Colors
DefineGlobalColor("H", Color.ORANGE);
DefineGlobalColor("L", Color.ORANGE);
DefineGlobalColor("O", Color.WHITE);

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
def ropen = if showrthopen_plot and SecondsFromTime(rthstart) == 0 then open else ropen[1];
plot orange = ropen;
hrange.AssignValueColor(GlobalColor("H"));
lrange.AssignValueColor(GlobalColor("L"));
orange.AssignValueColor(GlobalColor("O"));

#Bubbles - Prior Days
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), hrange[bubblemover + 1], "EH", hrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), lrange[bubblemover + 1], "EL", lrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), orange[bubblemover + 1], "RO", orange.TakeValueColor());

#Bubbles - Last Plot
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), hrange[bubblemover + 1], "ETH", hrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), lrange[bubblemover + 1], "ETL", lrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), orange[bubblemover + 1], "RTO", orange.TakeValueColor());

#
 
Last edited:
Thanks for sharing. I'd like being able to see those bubbles in the chart as I zoom into a lowertime frame for futures. I'd love to be able to add the current RTH open to this, so I'll try to somehow add it.
I think they will show on all Stocks/Futures/ETFs - just remember the lower the time frame the more the ebb and flow (more trades/less duration overall which is why I trade a 5 min chart - I used to trade ticks/1 min)..)
 
I think they will show on all Stocks/Futures/ETFs - just remember the lower the time frame the more the ebb and flow (more trades/less duration overall which is why I trade a 5 min chart - I used to trade ticks/1 min)..)
Thanks!

Yes, I meant to say that when I drop down to a 5min and zoom in, I'd like to see the bubbles within that view instead of just the lines, like how you have it. In other words, relying on line color is ok, but seeing the bubbles within the zoomed in view is helpful visually to confirm which exact level is being displayed.
 
Thanks!

Yes, I meant to say that when I drop down to a 5min and zoom in, I'd like to see the bubbles within that view instead of just the lines, like how you have it. In other words, relying on line color is ok, but seeing the bubbles within the zoomed in view is clean
I probably use larger bubbles than you do and don't need to zoom in - I also don't have a lot of charts on a single screen - I have TOS open on two computers with a single on each (helps calm my nerves)
 
When you unplot a line, TOS has a glitch where it does not remove the bubble. So one way is for you would have to comment (#) the addchartbubble in your code to remove the bubble.

The RTH Open was added in place of the close in both the following RTH and ETH versions.

The same code was used to make the RTH version by just changing the inputs from 1800-0929 to 0930-1615


RTH version

ETH version
Love this @SleepyZ

The last request is to re-insert that code where you had the ability to show/hide the open. Since I'd be running both on the same chart, would like the ability to turn off the open on one of the indicators.
1714167954915.png
 
Last edited:
Thanks @SleepyZ

Not sure what happened, but the EH/EL levels for today are not reflecting correctly. My guess is it's picking up from the ETH session from Thursday to Friday.
1714397830295.png


Also,

Ideally when using RTH levels, the previous RTH Hi/Low should not move when the new rth session begins. This green level should stay in the same spot representing friday's RTH hi, as it did throughout the eth session. once the RTH session opened, it followed that new high, as shown here (same is true for previous rth low-red line)
1714398281835.png


That could be added as something like "current day high" and tracks the HOD of the rth session. But the previous RTH hi/low should stay unmoved when the new rth session opens.


Thanks!
 
Last edited:
I like these versions of Previous Day High Low and Close and modified it a bit to suit my charting. I like to offset the Previous Close but keep the Highs and Lows on my chart as they might be pivot points? Here is a picture of it on my BestTradingChartSetup:


My modified code is:

##AsGood_PreviousDayHighLowClose
#Thanks to Welkin forceIndex Offset Close.

input aggregationPeriod = AggregationPeriod.DAY;
def yesterday_high = high(period = aggregationPeriod)[1];

plot static = yesterday_high;
static.AssignValueColor(color.White);
static.SetPaintingStrategy(PaintingStrategy.DASHES);

def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());

plot static1 = Yesterday_High;
static1.AssignValueColor(color.White);

input bubblemover = 4;
def b = bubblemover;
def limit1 = !IsNaN(close[b+1]) and IsNaN(close [4] );

AddChartBubble(limit1, static[b+1], "PrevDayHigh", Color.RED);

def NA = Double.NaN;

input agg = AggregationPeriod.DAY;

input showBubbles = yes;
input showValuesInBubbles = yes;
input spaceBetween = 1;

plot prevDayClose;

def exp = IsNaN(close[spaceBetween]);

prevDayClose = if exp then close("period"=agg)[1] else NA;

AddChartBubble(showBubbles, if IsNaN(prevDayClose[1]) and !IsNaN(prevDayClose) then prevDayClose else NA, if showValuesInBubbles then "PrevDayClose $"+prevDayClose else "PrevDayClose", Color.YELLOW, yes);
prevDayClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

input spacerText = "-----";
defineGlobalColor("Spacer Color", color.black);
AddLabel(yes, spacerText, GlobalColor("Spacer Color"));


def yesterday_low = low(period = aggregationPeriod)[1];

plot static2 = yesterday_low;
static2.AssignValueColor(color.White);

def limit2 = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());


static2.AssignValueColor(color.White);
static2.SetPaintingStrategy(PaintingStrategy.DASHES);


def b1 = bubblemover;
def limit12= !IsNaN(close[b+1]) and IsNaN(close );

AddChartBubble(limit2, static2[b+1], "PrevDayLow", Color.Green);
Have used this today and really like the feature of the bubbles staying within view throughout the day as shown here. This is what i mentioned previously about my execution charts are "zoomed" in. So if bubbles are static, I'd have to zoom out to find out which line color represents which level. With this feature, the bubbles move along with the candles throughout the day - very helpful.



1714416501584.png
 
Last edited:
Thanks @SleepyZ

Not sure what happened, but the EH/EL levels for today are not reflecting correctly. My guess is it's picking up from the ETH session from Thursday to Friday.
View attachment 21720

Also,

Ideally when using RTH levels, the previous RTH Hi/Low should not move when the new rth session begins. This green level should stay in the same spot representing friday's RTH hi, as it did throughout the eth session. once the RTH session opened, it followed that new high, as shown here (same is true for previous rth low-red line) View attachment 21721

That could be added as something like "current day high" and tracks the HOD of the rth session. But the previous RTH hi/low should stay unmoved when the new rth session opens.


Thanks!

Although the ExtHrs Low worked on the other days using the volumeprofile method, it did not for Sun/Monday. So the following workaround seems to fix that. I used the volumeprofile so that you could see the developing horizontal line throughout the premarket. Most other methods seem to plot the horizontal line after the close of the ccurrent premarket period.

As far as extending the lines from the previous day into the next day cannot be done with the above code. It is one continuous line changing at the start of rthr session. To do your request would be writting another code.

Screenshot 2024-04-29 131048.png
Code:
#Premarket_HL_Futures_ExtendedHrs_using_ProfileHL_ETH

input showrthopen_plot = yes;
input start = 1800;
input end = 0929;
input rthstart = 0930;
input rthend = 1615;
input bubblemover = 0;
input showPriorbubbles = yes;
input showLastbubbles = yes;
input extendlines = yes;

def sec1 = SecondsFromTime(start);
def sec2 = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
(sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
(sec2 < sec2[1] and sec2 > 0) ;

def aftermarket = CompoundValue(1,
if isTime1[1] == 0 and isTime1 == 1
then 1
else if isTime2
then 0
else aftermarket[1], 0);

def bars = 100000;
def bn = BarNumber();
def na = Double.NaN;

def period = bn - 1;
def count  = CompoundValue(1,
if aftermarket and period != period[1]
then (count[1] + period - period[1]) % bars
else count[1], 0);
def cond = count < count[1] + period - period[1];

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

#ExtGigh
def hProfile = if aftermarket and IsNaN(vol.GetHighest())
then hProfile[1]
else if period != period[1]
then vol.GetHighest()
else hProfile[1];

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;

#ExtLow

#Monday workaround
def extlowtoday = if IsNaN(close) then extlowtoday[1] else if cond[1] == 1 and cond == 0
                  then low
                  else if cond == 0 and GetTime() < RegularTradingStart(GetYYYYMMDD())
                  then  Min(low, extlowtoday[1])
                  else extlowtoday[1];
def ymd         = GetYYYYMMDD();
def ct1         = if !IsNaN(close) and ymd != ymd[1] then ct1[1] + 11 else ct1[1];
def cond1      = HighestAll(ct1) - ct1;
def mondaylow  = if cond1 > 0
                 then na
                 else HighestAll(if IsNaN(close[-1]) then extlowtoday else na);

def lProfile = if cond[1] == 1 and cond
then low
else if period != period[1]
then vol.GetLowest()
else lProfile[1];

def ProfileLow = if cond1 == 0 then mondaylow else if cond > 0 and extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

#Colors
DefineGlobalColor("H", Color.ORANGE);
DefineGlobalColor("L", Color.ORANGE);
DefineGlobalColor("O", Color.WHITE);

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
def ropen = if showrthopen_plot and SecondsFromTime(rthstart) == 0 then open else ropen[1];
plot orange = ropen;
hrange.AssignValueColor(GlobalColor("H"));
lrange.AssignValueColor(GlobalColor("L"));
orange.AssignValueColor(GlobalColor("O"));

#Bubbles - Prior Days
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), hrange[bubblemover + 1], "EH", hrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), lrange[bubblemover + 1], "EL", lrange.TakeValueColor());
AddChartBubble(showPriorbubbles and hrange[bubblemover] != (hrange[bubblemover + 1]), orange[bubblemover + 1], "RO", orange.TakeValueColor());

#Bubbles - Last Plot
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), hrange[bubblemover + 1], "ETH", hrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), lrange[bubblemover + 1], "ETL", lrange.TakeValueColor());
AddChartBubble(showLastbubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]), orange[bubblemover + 1], "RTO", orange.TakeValueColor());

#
 
Although the ExtHrs Low worked on the other days using the volumeprofile method, it did not for Sun/Monday. So the following workaround seems to fix that. I used the volumeprofile so that you could see the developing horizontal line throughout the premarket. Most other methods seem to plot the horizontal line after the close of the ccurrent premarket period.

As far as extending the lines from the previous day into the next day cannot be done with the above code. It is one continuous line changing at the start of rthr session. To do your request would be writting another code.
Thanks @SleepyZ for your time and assistance with the amazing work you do daily.

I’ll use this to just focus on eth. I’ll scan through this thread to add and attempt to adjust a study to fit all rth criteria. I doubt it since I’m awful at coding, but will give it a shot. Thanks!
 
Thanks @SleepyZ for your time and assistance with the amazing work you do daily.

I’ll use this to just focus on eth. I’ll scan through this thread to add and attempt to adjust a study to fit all rth criteria. I doubt it since I’m awful at coding, but will give it a shot. Thanks!

Here are 4 days hi/lo extended to the right edge using the script function.
To create more days back then use the logic of the 4

Screenshot 2024-04-29 154813.png
Code:
#Example_RTHrsHL_intraday_ndays
#

script hl {

    input lookback = 0;
    input rthbegin = 0930;
    input rthend   = 1615;

    def n   = lookback;
    def na  = Double.NaN;
    def h   = high;
    def l   = low;
    def bn  = BarNumber();
    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 thisDay  = (HighestAll(dayCount) - dayCount) ;

    def rth      = SecondsFromTime(rthbegin) >= 0 and SecondsFromTime(rthend) < 0;
    def hh       = if thisDay == n and SecondsFromTime(rthbegin) == 0
                   then h
                   else if thisDay == n and  rth and h > hh[1]
                   then h
                   else hh[1];
    def hhigh    = if thisDay == n and h == hh then BarNumber() else na;
    def hhnan    = if IsNaN(hh) then hhnan[1] else hh;

    plot hhplot  = if BarNumber() >= HighestAll(hhigh) then (hhnan) else na;

    def ll       = if thisDay == n and SecondsFromTime(rthbegin) == 0
                   then l
                   else if thisDay == n and  rth and l < ll[1]
                   then l else ll[1];
    def llow  = if thisDay == n and l == ll then BarNumber() else na;
    def llnan = if IsNaN(ll) then llnan[1] else ll;

    plot llplot = if BarNumber() >= HighestAll(llow) then (llnan) else na;
}


plot H0 = hl(0).hhplot;
plot L0 = hl(0).llplot;
plot H1 = hl(1).hhplot;
plot L1 = hl(1).llplot;
plot H2 = hl(2).hhplot;
plot L2 = hl(2).llplot;
plot H3 = hl(3).hhplot;
plot L3 = hl(3).llplot;

DefineGlobalColor("H", Color.GREEN);
DefineGlobalColor("L", Color.RED);
H0.SetDefaultColor(GlobalColor("H"));
L0.SetDefaultColor(GlobalColor("L"));
H1.SetDefaultColor(GlobalColor("H"));
L1.SetDefaultColor(GlobalColor("L"));
H2.SetDefaultColor(GlobalColor("H"));
L2.SetDefaultColor(GlobalColor("L"));
H3.SetDefaultColor(GlobalColor("H"));
L3.SetDefaultColor(GlobalColor("L"));


input showbubbles = yes;
input bubblemover = 3;
def   bn    = BarNumber();
def   mover = showbubbles and bn == HighestAll(bn - bubblemover);
AddChartBubble(mover , H0, "H0", H0.TakeValueColor());
AddChartBubble(mover , H1, "H1", H1.TakeValueColor());
AddChartBubble(mover , H2, "H2", H2.TakeValueColor());
AddChartBubble(mover , H3, "H3", H3.TakeValueColor());

AddChartBubble(mover , L0, "L0", L0.TakeValueColor());
AddChartBubble(mover , L1, "L1", L1.TakeValueColor());
AddChartBubble(mover , L2, "L2", L2.TakeValueColor());
AddChartBubble(mover , L3, "L3", L3.TakeValueColor());

#
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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