Previous Day High Price Line Plot & Bubble On Intraday Chart

DMacTrades

New member
Hi all. I am looking for help in creating a custom code that plots a horizontal line and creates a bubble for yesterday's high of day on today's intraday chart (the bubble would indicate the HOD from yesterday).

I found this code from a thread talking about the monthly and changed it so that it prints a label on the daily indicating yesterday's high and today's high, but it only works on the daily and I can't figure out how to have it plot a line on the intraday. Thanks very much in advance.

def DAY = AggregationPeriod.DAY;

def dayHigh = high (period = DAY);

AddLabel(yes, "PDH: " + dayHigh +", PDH1: " + dayhigh[1], Color.White);

def PDH = high (period = DAY);
def PDH1 = high (period = DAY)[1];

# PDH[1] is NOT equal to PDH
 

DMacTrades

New member
This is what I have come up with and kudos go to @escher138. I have modified his code to plot the Previous Day High and Low.

If anyone is able to provide guidance as to how to get the plot lines to start at the open of the previous day only (instead of going back a year) that would be awesome!


# prev_day defined as previous market day, betwen 0930 - 1600.
def prev_day = if GetDay()-GetLastDay() == -1 and SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;
def highs_prev_day = if prev_day then HIGH else double.nan; #update high and low only during last hour
def lows_prev_day = if prev_day then LOW else double.nan;
plot prev_day_highest = highestall(highs_prev_day);
plot prev_day_lowest = lowestall(lows_prev_day);

prev_day_highest.SetDefaultColor(GetColor(6));
prev_day_highest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prev_day_lowest.SetDefaultColor(GetColor(5));
prev_day_lowest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#add cloud between the prev day high and previous day low of prev day though current day
AddCloud(if (GetLastDay() == GetDay() and GetLastYear() == GetYear()) then prev_day_highest else Double.NaN,prev_day_lowest,color.light_green);
AddCloud(if prev_day then prev_day_highest else Double.NaN,prev_day_lowest,color.gray);
 

mansor

Active member
https://usethinkscript.com/threads/previous-day-high-and-low-breakout-indicator-for-thinkorswim.154/

Edit:

After reading the above link, here are the labels. opening todays, yhigh & ylow. Thanks for asking the question in the first place, it got me curious.. cause all this time I had scroll back to check previous days' highs & lows. This helps! Thanks @BenTen for scripting this out & thanks to @Tiredoflosing for asking Q as well

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);
 
Last edited:

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.
Top