Previous Day High and Low Breakout Indicator for ThinkorSwim


New member
@divinci01 Since you just want to plot and scan for the previous day's high and low, here is the script for that (taken from post #1)

# 5 min opening range
# Robert Payne
#Plot opening range high / low
input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];


Add it as a separate indicator and then setup your scanner to something like this:


Hi @BenTen,
is the aggregate for this is only on DAY??? i tried to change it to 2 min, I get an error.
Thank you


New member

Facing a problem with making TOS save yesterdays RTH High and Low when Extended Trading Hours are ON.

Need this as a part for my pre-market scanner.

Using thin piece of code and its not working.

Any help is highly appreciated!!!

def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
                 GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def yHighRTH = if !RTH then yHighRTH[1] else if RTH and high > yHighRTH[1] then high else yHighRTH[1]; #yesterday's high

Hi here is what I figured out to scan on PM for yesterday High break Out, same for low, just adjust it. In order to use it put this on the scanner on an intraday aggregation, like 10 min with ext hours.

def yRTH =if gettime()>regularTradingStart(GetYYYYMMDD()[1]) and gettime()<regularTradingEnd(GetYYYYMMDD()[1]) then 1 else 0;

def yh= if yrth[1]==0 and yrth==1 then high else
       if  yrth and high>yh[1] then  high else yh[1];

plot H =if close>yh then 1 else 0;


New member
2019 Donor
Modified the amounts to BH & BL
addlabel(1, if HiBrokeAmt then "BH " else if LoBrokeAmt then "BL " else "IN",;
assignbackgroundcolor(if HiBrokeAmt then color.dark_green
else if LoBrokeAmt then color.dark_red
else color.dark_Orange);


New member
Hey Guys: Is it possible for this indicator to just to provide RTH ( Regular Trading Hours ) previous day HIGH/LOW/MID points as lines drawn for the entire chart. I see that this indicator considers extended trading hours for high/low. I just want RTH. Appreciate your help.


New member
Everyday at EOD i manually plot OHLC & POC, VAH, VAL, i would like to find a Auto plot for all these levels.

i also manually plot first 5' open bar high, low for reference thru out the day. a auto plot would be really cool.


New member
Hi Ben,
I copied the code for scan price crossing yesterday high. I used the daily Aggregation but I am not getting anything.
Thanks for your help


Staff member
@zap You can try this in your scanner:

close crosses above high("period" = AggregationPeriod.DAY)[1]



New member
I'm trying to create a script that plots a cloud showing the previous day's high down to the previous days high. The problem I'm running into is the script includes data from extended hours so sometimes the cloud is inaccurate because its too high. I've tried a few different inputs to fix it but nothing seems to change it. I've searched through here quite a bit and haven't been able to find anything, any help is appreciated. Code below.

def newDay = GetDay() <> GetDay()[1];

rec dailyHigh = if newDay then high else if high > dailyHigh[1] then high else dailyHigh[1];
def previousClose = close(period = AggregationPeriod.DAY)[1];
rec previousHigh = if newDay then dailyHigh[1] else previousHigh[1];
plot priorDayHigh = previousHigh;
plot priorDayClose = previousClose;

addcloud (priordayHigh, priordayclose,,, yes);


Staff member

includes data from extended hours

You would need to disable extended hours from your chart settings. Other than that, I'm not sure if there's any other solution.

Here is a different version that plots the same thing. Maybe you can try it and see if it will work with extended hours.

input aggregationPeriod = AggregationPeriod.DAY;
def prev_high = high(period = aggregationPeriod)[1];
def prev_close = close(period = aggregationPeriod)[1];

plot ph = prev_high;
plot pc = prev_close;

AddCloud(ph, pc,,;
Last edited:


New member
Thanks Ben, I had to change one part of the code, line 2. I changed it from "open(period..." to "high(period..."

That seems to be working, thank you!


New member
I am plotting highs and lows as follows:

plot DailyHigh = low;
plot DailyLow = high;

However, I want this to plot only for candlesticks that have completed. So if the current candlestick is still forming, don't plot these values.

How would I do this?

I figured it out:

plot DailyHigh = if GetLastDay() <> GetDay()    then high    else Double.Nan;
plot DailyLow = if GetLastDay() <> GetDay()    then low    else Double.Nan;


Well-known member
Ok thanks. Not getting stocks cross but I am seeing stock way above yesterday high like jd,pdd,tndm. Hi BenTen, Why the scan is not showing price crossing yesterday high ?

Crossing doesn't work very well for price on ThinkorSwim, crossing scans for a linear consecutive sequential pattern.... because of this price doesn't always work this way, lets say for AMZN….the price might go from 3254.36 and next closing price is 3254.48 (not to mention the spread of the high and low of a candle), it will miss the scan. the crossing input is more meant for studies like moving averages, linear regression, and so on. You are better off defining "crossing yesterday's high " as " closing low is below yesterdays high and closing high is above yesterdays high" ... this will define the closing candle's low and closing candle's high which means the entire closing candle "crossing/moving /passing" though yesterday's high.


Plot scan = low < high[1] and high > high[1];
Last edited:


New member
I am using the pre-market high and low with fibs I see here I turned off the fibs but how can I add yesterday high and low? saves me alot of time to chart


New member
Found this script in the thinkScript lounge. Hopefully it's what you're looking for:

#This custom column plots the high or low break compared to the previous day's. Green is a high break. Red is a low break. Pink is a hi and low break with the hi break amt shown.
#Title = Broke, Revision 9/25/13
#Revised:  12:03 PM 9/25/2013

def HiBroke = If (close > high[1] ,1,0);
def LoBroke = If (close  < low[1] ,1,0);
def BothBroke = If (HiBroke && LoBroke, 1,0);
def HiBrokeAmt = If HiBroke then (close - high[1] ) else double.nan;
def LoBrokeAmt = If LoBroke then (low[1] - close) else double.nan;

Addlabel(1,  if HiBroke && !LoBroke then round(HiBrokeAmt,2)
else if !HiBroke && LoBroke then round(LoBrokeAmt,2)
else  if HiBroke && LoBroke then  round(HiBrokeAmt,2)
else 0, color.yellow);

AssignBackgroundColor(if HiBroke then color.Dark_green
else if LoBroke then color.Light_red
else if HiBroke && LoBroke then
else color.current);

@BenTen Will this show which stocks are breaking the previous day's high or low during premarket hours, or just intraday?

Similar threads