Previous Day High and Low Breakout Indicator for ThinkorSwim

I'm trying to build a scanner that will scan stock that is above Yesterday's High.

Aggregation: 1m [Including Extended-Hours trading session]
Code:
def Price = close;

def day = AggregationPeriod.DAY;
def YestHigh = high(period = day)[1];

plot scan = Price > YestHigh;
Secondary period not allowed: Day.

What would be the work around for this? I will be using this in the premarket.
 
@Robby Luca

PREVIOUS ALL DAY HIGH INCLUDING EXTENDED and PREMARKET HOURS
recommended aggregation should be 1 minute
MANUALLY CHANGE THE DATE TO THE PREVIOUS DAYS DATE
Code:
#PREV ALL DAY HIGH INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#MANUALLY CHANGE THE DATE TO THE PREVIOUS DAYS DATE
#format is YEAR MONTH DAY YYYYMMDD
input date = 20210301;
def PREV_ALL_DAY_HIGH = HighestAll(if  GetYYYYMMDD()== 20210301 then high else 0);
AddLabel (yes, "Prev All Day High " +  (PREV_ALL_DAY_HIGH)  );

for the scan just change
Code:
AddLabel (yes, "Prev All Day High " +  (PREV_ALL_DAY_HIGH)  );
to
Code:
plot scan = PREV_ALL_DAY_HIGH < close;

if you found this post useful remember to leave a thumbs up!
 
@BenTen or anyone else who may know,

I am looking for a custom ThinkScript study similar to the above, but I need help with a script which plots the previous days High, Low, and Close as horizontal lines on any intraday chart on the ToS mobile app (I use the 3 min chart on my phone). Has anyone done this before for ToS mobile? I already got this set up for the Desktop ToS platform but unable to get a script working for mobile. Thank you so much if you can help me make this possible!
 
@BenTen or anyone else who may know,

I am looking for a custom ThinkScript study similar to the above, but I need help with a script which plots the previous days High, Low, and Close as horizontal lines on any intraday chart on the ToS mobile app (I use the 3 min chart on my phone). Has anyone done this before for ToS mobile? I already got this set up for the Desktop ToS platform but unable to get a script working for mobile. Thank you so much if you can help me make this possible!
There's an indicator called DailyHighLow in TOS already. Can plot highs and lows.
And this is the code to plot prev day close line. Not sure how it works on mobile to be honest.
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PrevDayClose = Double.NaN; } else { PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length); }
 
@BenTen

It looks like it doesn't work, are there any other column studies you have handy that do?

- AAPL and MARA gapping above previous HOD, column didn't know:

eI965kd.png

MhvEBvN.png


- PDD gapping above previous HOD, column says gapping down:

O7MWOyk.png
it APPEARS there are no gaps from previous day high to the current day on the charts your posted. however since you failed to screenshot the entire chart i may be wrong. If you are asking a question relating to price and time, for future reference the price and time would be helpful in the screenshot. One of the most strangest things people do is reference price and time on a chart and show just one of the two making the chart essentially just random bars and lines with nothing to reference to.
 
it APPEARS there are no gaps from previous day high to the current day on the charts your posted. however since you failed to screenshot the entire chart i may be wrong. If you are asking a question relating to price and time, for future reference the price and time would be helpful in the screenshot. One of the most strangest things people do is reference price and time on a chart and show just one of the two making the chart essentially just random bars and lines with nothing to reference to.

Thanks for the feedback, you have a great point and I will do that in the future. However, in the screenshot, you can still see in PDD for example that the pre-market this morning is far above the previous day's high which is marked by a yellow line. Therefore, the study isn't working correctly, because it should show that PDD is gapping up this morning. Can you help?
 
So this is a perfect setup for what I am trying to catch, but I'm not able to catch it... 1min candle Breakout over previous DAY high, over average volume, and my HiLowBreakout study alerted. But it doesn't. Here is the code for the HiLow study:

def CurrentDay = GetDay() == GetLastDay();
def previousHigh = if CurrentDay then high(period = AggregationPeriod.Day)[1] else Double.NaN;
def previousLow = if CurrentDay then low(period = AggregationPeriod.Day)[1] else Double.NaN;
plot scan = high crosses above previousHigh;

I need to have that study populate a watchlist. I can see that it happened, but I'm limited by the conflicting DAY/1min difference. It seems if the study triggers and plots a value of (1) versus (0), there should be a way to populate based on that...?
IhKPqmn.png
Realtime watchlist populates like below. So the high of the DAY crossed, technically. I need the high of the 1min to populate.

XprCorN.png
HELP, please!!


it plots 1 or 0 because it means the condition you set is true or fales. 1 is true and 0 is false.

you stated:
"1min candle Breakout over previous DAY high, over average volume, and my HiLowBreakout study alerted. But it doesn't. Here is the code for the HiLow study:"

there is already a study with a post somewhere on here for price goes above previous day high. You high low break out when the condition is met you want for it you have to make sure it equals true

so then you are going to want both to be true. however since you fail to find the and post the 2 codes you need/are using then its impossible to help you all the way. but here is the theory of what you will have to do.

plot both conditions are true ( equal to 1, im my example below greater than 0 which 1 is greater than 0)
plot scan = highlow>0 and breakprevday > 0;
 
High From XYZ days ago INCLUDING EXT HOURS (This will work for previous day high as well)
BY XeoNoX via usethikscript.com
Recommended aggregation should be 1 minute
Days and time are according to USA Eastern (NewYork) time
Change input Days_Ago to your desired days ago

Code:
#High From XYZ days ago INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#Days and time are according to USA Eastern (NewYork) time
#Change input Days_Ago to your desired days ago
Input Days_Ago = 2;
def lastDate = HighestAll( if GetDay() == GetLastDay() and GetYear() == GetLastYear() then GetYYYYMMDD() else Double.NaN );
def today = if GetYYYYMMDD() < lastDate then GetYYYYMMDD() else lastDate;
def priorday = if CountTradingDays(today, LastDate ) == Days_Ago then yes else no;
def PREV_ALL_DAY_HIGH = HighestAll(if  priorday then high else 0);
AddLabel (yes, "High From " + Days_ago + " Days ago: " +  (PREV_ALL_DAY_HIGH)  );


I9r436P.jpg
 
Hi,

I have the following code, which will give me the low value and the high value of each candle between 4-5 pm, and then grabs the highest of the highs and the lowest of the lows depending on the day aggregation. However, I only want it to consider the most recent day between 4-5pm when calculating this high and low. How can i fix this code such that the behavior of the ahHigh and ahLow is as it would be on a 1D aggregation, IE only show the previous days high and low between 4-5pm

Code:
#====================================
# Get final hour of trading data
#====================================
input CloseTime = 1700;
input DurationHours = 1;

def durationSec = DurationHours * 60 * 60;
def secondsRemained = SecondsTillTime(closeTime);

# Get high for after hours, four to five
plot fourToFiveHigh = if secondsRemained >= 0 and secondsRemained <= durationSec then high else double.NaN;

# Get low for after hours, four to five
plot fourToFiveLow = if secondsRemained >= 0 and secondsRemained <= durationSec then low else double.NaN;


#===============================
# Get Final Hour High and Low
#===============================

def ahHigh = HighestAll(fourToFiveHigh);
def ahLow = LowestAll(fourToFiveLow);

addLabel(yes, ahHigh);
addLabel(yes, ahLow);
 
---

EDIT: I solved this problem but am trying to compare previous highs against today's open and keep today's "open" static rather than always looking back to previous days' opens. Is there a way to do this?
 
Last edited:
I took this indicator from Robert and tweaked it a little to my need. Originally it plots the 5 min opening range breakout. However, I took that out and only keep the previous day high and low. Then I add some customizations to it to make the breakout or breakdown more noticeable.

Here is what it looks like:

3DOqpxq.png


When the price is within the previous day high and low range then you would see the color of the regular candle. When it's outside of the range then red candles become gray and green candles become white.

thinkScript Code

Rich (BB code):
# 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;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes 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];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);

#Plot pivot
plot Pivot = if ShowTodayOnly and !Today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.YELLOW);
Pivot.SetLineWeight(2);

#Plot 10 day high / low
plot TenHigh = if ShowTodayOnly and !Today then Double.NaN else Highest(high(period = "day" )[1], 10);
plot TenLow = if ShowTodayOnly and !Today then Double.NaN else Lowest(low(period = "day" )[1], 10);

TenHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenHigh.SetDefaultColor(Color.UPTICK);
TenHigh.SetLineWeight(3);
TenLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenLow.SetDefaultColor(Color.DOWNTICK);
TenLow.SetLineWeight(3);

AssignPriceColor(if close >= Yhigh then Color.GREEN
  else if close <= Ylow then Color.RED
  else Color.CURRENT);

AssignPriceColor(if close > Yhigh and open < close then Color.White
  else if close > YHIGH and open > close then Color.Gray
  else if close < Ylow and open < close then Color.White
  else if close < Ylow and open > close then Color.Gray
  else Color.CURRENT);

Shareable Link

https://tos.mx/tbjMgb

Previous Intradays High, Low, Mean

Code:
# Previous Intradays High, Low, Mean
# Mobius
# V01.12.2017 Desktop and Mobile
# Revised original code that uses SecondsFromTime() and SecondsTillTime(). Code now uses RegularTradingStart() and RegularTradingEnd() to bracket RTH. Works in Mobile Apps

def bar = barNumber();
def h = high;
def l = low;
def c = close;
def firstBar = if getTime() crosses above RegularTradingStart(GetYYYYMMDD()) and
                  !isNaN(close)
               then bar
               else double.nan;
def lastBar = if getTime() crosses above RegularTradingEnd(GetYYYYMMDD()) and
                 !isNaN(close)
              then bar
              else double.nan;
addVerticalLine(bar == HighestAll(firstBar), "first bar", color.cyan, curve.short_dash);
addVerticalLine(bar == HighestAll(lastBar), "last bar", color.cyan, curve.short_dash);
def bar_t1 = if !isNaN(firstBar)
            then bar
            else bar_t1[1];
def bar_t2 = if !isNaN(lastBar)
             then bar
             else bar_t2[1];
def prevFirstBar = if bar_t1 != bar_t1[1]
              then bar_t1[1]
              else prevFirstBar[1];
def prevLastBar = if bar_t2 != bar_t2[1]
                  then bar_t2[1]
                  else prevLastBar[1];
addVerticalLine(bar == HighestAll(prevFirstBar), "prev first bar", color.red, curve.short_dash);
addVerticalLine(bar == HighestAll(prevLastBar), "prev Last bar", color.red, curve.short_dash);
def hh = if bar == HighestAll(prevFirstBar)
         then h
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 h > hh[1]
              then h
              else hh[1];
def hhBar = if h == hh and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then barNumber()
            else double.nan;
def ll = if bar == HighestAll(prevFirstBar)
         then l
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 l < ll[1]
              then l
              else ll[1];
def llBar = if l == ll and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then bar
            else double.nan;
plot PrevDayHigh = if bar >= highestAll(hhBar)
                   then highestAll(if isNaN(c[-1])
                                   then hh
                                   else double.nan)
                   else double.nan;
     PrevDayHigh.SetStyle(Curve.Long_Dash);
     PrevDayHigh.SetLineWeight(3);
     PrevDayHigh.SetDefaultColor(Color.Green);
     PrevDayHigh.HideTitle();
plot PrevDayLow = if bar >= HighestAll(llBar)
                  then highestAll(if isNaN(c[-1])
                                  then ll
                                  else double.nan)
                  else double.nan;
     PrevDayLow.SetStyle(Curve.Long_Dash);
     PrevDayLow.SetLineWeight(3);
     PrevDayLow.SetDefaultColor(Color.Red);
     PrevDayLow.HideTitle();
def hl2bar = Floor((highestAll(hhbar) + highestAll(llBar)) / 2);
def hl2price = Round(((PrevDayHigh + PrevDayLow) / 2) / TickSize(), 0) * TickSize();
plot PrevDayHL2 = if bar >= highestAll(HL2bar)
               then highestAll(if !isNaN(c[-1])
                               then HL2price
                               else double.nan)
               else double.nan;
     PrevDayHL2.SetStyle(Curve.Long_Dash);
     PrevDayHL2.SetLineWeight(3);
     PrevDayHL2.SetDefaultColor(Color.Yellow);
     PrevDayHL2.HideTitle();
# End Code Previous Days High, Low, Mean
how can i get this without the vertical lines and words???
 
Hi everyone,

I hope this finds u well and in good health. I need help with adding a chart label of the opening price (name and price) as well as for high/low price.

here are the code for the opening price scripts im using.
Code:
input openingPMTime  = 0400.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input openingTime  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.

def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);

def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingPMTime) < 0, yes, no);
input LineWidth = 1;
def na = Double.NaN;

def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingPMTime) >= 0, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];

plot PlotPMOLine = if isToday and isBelowDaily then PMOpen else na;
     PlotPMOLine.SetDefaultColor(CreateColor(77, 166, 255));
     PlotPMOLine.SetLineWeight(LineWidth);
     PlotPMOLine.SetPaintingStrategy(PaintingStrategy.DASHES);
     PlotPMOLine.HideTitle();
     PlotPMOLine.HideBubble();


Here is the code for the yesterday high and low. Im looking to add a label for price and yesterday high / low on the chart

Code:
#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];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);


Lastly, is it possible to combine these two scripts into 1?

Thank you
 
@Tiredoflosing Here you go:

Code:
input openingPMTime  = 0400.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.
input openingTime  = 0930.0; #hint OrMeanS: Begin Mean Period. Usually Market Open EST.

def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);

def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingPMTime) < 0, yes, no);
input LineWidth = 1;
def na = Double.NaN;

def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingPMTime) >= 0, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];

def PlotPMOLine = if isToday and isBelowDaily then PMOpen else na;

AddLabel(yes, Concat("Opening = ", PlotPMOLine), color.orange);

#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
def Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
def Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

AddLabel(yes, Concat("Prev High = ", Yhigh), color.orange);
AddLabel(yes, Concat("Prev Low = ", Ylow), color.orange);
 
Here is what it looks like:

3DOqpxq.png

For anyone who wanted the above code, see below.

Code:
#Plot prior day high/low range#
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
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];


############################################################


AssignPriceColor(if close > Yhigh and open < close then Color.White
  else if close > YHIGH and open > close then Color.Gray
  else if close < Ylow and open < close then Color.White
  else if close < Ylow and open > close then Color.Gray
  else Color.CURRENT);
 
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.

Code:
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;
Hi @jruggiero - thank you for providing this solution. It works great!

I was wondering if it's possible to run a similar scan in pre-market to check for stocks that have broken previous WEEKLY highs / lows? Appreciate any input from more experienced members here.

Thanks for all you do, very much appreciated.
 
Can somebody help me setup the following thinkscrips code/scan, TOS lacks additional conditions

I just want to scan for:
Candle that make high over previous day high of day, yet closes under it.
or
Make low below previous day low of day, and closes over it.

Thats it! TOS custom candle pattern builder is missing the integration with the previous high of day study or any studies for that matter.
If I want to scan for 3 ascending candles, yet over vwap, its impossible to incorporate any indicators into the candle scanner.
 
Daily Higher Highs or Lower Lows That Are Reversing
Scan Rules:
  1. Run with a daily aggregation
  2. Scan = highcandle is true OR lowcandle is true

Ruby:
plot highcandle = high > high[1] and close <  high;
plot lowcandle =  low  < low[1]   and close  > low ;
 

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