Previous Day High and Low Breakout Indicator for ThinkorSwim

Hello!

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

Code:
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.

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;
 

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

Modified the amounts to BH & BL
addlabel(1, if HiBrokeAmt then "BH " else if LoBrokeAmt then "BL " else "IN", color.black);
assignbackgroundcolor(if HiBrokeAmt then color.dark_green
else if LoBrokeAmt then color.dark_red
else color.dark_Orange);
 
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.
 
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.
 
@profitmaya You might want to check again, it's working for me.

BtLVABm.png
 
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
 
@zap You can try this in your scanner:

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

uD2yyHR.png
 
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, color.green, color.green, yes);
 
@Cribbage

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.

Code:
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, color.green, color.green);
ph.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited:
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!
 
I am plotting highs and lows as follows:

Code:
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:

Code:
plot DailyHigh = if GetLastDay() <> GetDay()    then high    else Double.Nan;
plot DailyLow = if GetLastDay() <> GetDay()    then low    else Double.Nan;
 
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.

example:

Code:
Plot scan = low < high[1] and high > high[1];
 
Last edited:
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
 
Found this script in the thinkScript lounge. Hopefully it's what you're looking for:

Code:
#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 color.pink
else color.current);

@BenTen Will this show which stocks are breaking the previous day's high or low during premarket hours, or just intraday?
 
Hello, I need some help to improvise the Daily high low indicator. I mainly used for scalping in 1min time-frame chart without pre-market session. I converted into TOS strategy for testing purposes but there is a problem with it. It creates the first order right away after opening candle. For example, If I set "marketOpen" time as "931" or 9:31am, It creates order at next candle or 9:32 according to the 9:31 candle. If 9:31 candle is red than it creates a short position if it's green than it creates long position. I tried to fix it by changing "marketOpen" time, let's say "940", same issue, order at 9:32 candle and 9:41 candle.

So my goal is to disable creating order at the second candle depending on "marketOpen" time OR in another word, ignore first candle and previous candle before "marketOpen" time. for instance, if my "marketOpen" time is 1000 or 10 am then ignore all candles from 9:30 am till 10 am.

mI6PJF1.png

gslL5sL.png

XtlpAdi.png


Link for strategy
https://tos.mx/ltZhUKr
Link for Workspace w/ stop loss added
https://tos.mx/qbPjsdD

Code:
input marketOpen = 931;
input marketClose = 1600;
input intraDaySpan = {Default "SameDay" , "OverNight"};
input numberOfDays = 1;
input numberOfYears = 0;

def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() - numberOfYears <= GetYear() ;

def OpenCounter =  SecondsFromTime(marketOpen);
def CloseCounter = SecondsTillTime(marketClose);

def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0;

def beforeMidnight = OpenCounter >= 0 and CloseCounter <= 0;
def afterMidnight = OpenCounter <= 0 and CloseCounter >= 0 ;

def Today ;
def hideChartBubbles ;
rec DailyHigh ;
rec DailyLow ;

switch (intraDaySpan) {
    case "SameDay":
    Today = if GetDay() != GetDay()[1] then 1 else 0;
    DailyHigh = if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high;
    DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = MarketHours;
    case "OverNight":
    Today = 0;
    DailyHigh = if beforeMidnight or afterMidnight then if high > DailyHigh[1] then high else DailyHigh[1] else  high;
    DailyLow = if beforeMidnight or afterMidnight then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = beforeMidnight or afterMidnight;
};

plot TodaysHigh = if okToPlot and hideChartBubbles  then DailyHigh else Double.NaN;
plot TodaysLow = if okToPlot and hideChartBubbles then DailyLow else Double.NaN;
TodaysHigh.SetDefaultColor(Color.GREEN);
TodaysLow.SetDefaultColor(Color.RED);


Def high= DailyHigh > DailyHigh[1] ;
Alert(high,"New High", Alert.BAR, Sound.Bell);
AddOrder(OrderType.BUY_AUTO, high , tickColor = GetColor(1), arrowColor = GetColor(1), name = ".");



Def low= DailyLow < DailyLow[1] ;
Alert(low, "New Low", Alert.BAR, Sound.Bell);
AddOrder(OrderType.Sell_AUTO, low , tickColor = GetColor(1), arrowColor = GetColor(1), name = ".");
your workspace dos not work
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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