• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

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
 

rad14733

Well-known member
VIP
@DMacTrades I'm fairly certain that has already been posted at least once here in the forums... Have you done ample research using various terms in the search feature in the upper right corner of every page...???
 

DMacTrades

New member
@rad14733 - Yes. I have searched "previous day high", "previous day high plot", "previous day high label", and haven't found anything specific to Previous Day High. However, I have found a post about a member who was working on something similar for the high and low of the previous day's final hour of trading and should be able to modify that. I will post the code when done if it works.
 

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);
 

rad14733

Well-known member
VIP
@DMacTrades How about trying to use indexing and simplifying things... That should get you going...

Ruby:
def prevDayHigh = high(period = AggregationPeriod.DAY)[1];
def prevDayLow = low(period = AggregationPeriod.DAY)[1];
 

mansor

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:

Similar threads

Top