Last hour of previous day

escher138

New member
I am trying to focus on high & low of the previous day's last hour prior to market close. I want to use that information into current day, just by drawing a plot or horizantal line from the end of that market day into the current day (not updating with new high/lows of current market day hours)....that is until the last hour of the day comes again then it can update.

I am struggling with wrapping my head around use of time in thinkscript.
Thanks for any assistance you can give.
 

XeoNoX

Well-known member
VIP
you stated:
"by drawing a plot or horizantal line from the end of that market day into the current day "

can you post a picture/chart with the line manually drawn to get a better understanding of what you mean?
 

mashume

Well-known member
VIP
Lifetime
You could do something along these lines:
Code:
declare upper;

def last_hour = if SecondsFromTime(1500) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;

def highs_last_hour = if last_hour then HIGH else double.nan;
def lows_last_hour = if last_hour then LOW else double.nan;

plot last_hour_highest = highestall(highs_last_hour);
plot last_hour_lowest = lowestall(lows_last_hour);

This will work on a 1 day chart at any intraday timeframe. It gets a lot more complex trying to get just the one day prior to today. I'm not sure I have the time to work it all out right now, but this may get you started. If you try it on longer charts, it will take the highest from ALL of the days present on your chart, and similarly the lowest from ALL of the days on your chart.

-mashume
 

escher138

New member
you stated:
"by drawing a plot or horizantal line from the end of that market day into the current day "

can you post a picture/chart with the line manually drawn to get a better understanding of what you mean?
ilwkW1L.png
 

escher138

New member
I think I have got it worked out, thanks to the head start by Mashume. I used that script provided, and added some conditions to check if it is today or previous day. Also, added a cloud between the high/low markers, grey for yesterday and green today to make it easier to see. Thanks for the responses.
zamWvEa.png


Code:
declare upper;
# last_hour defined as previous market day, betwen 1500-1600
def last_hour = if GetDay()-GetLastDay() == -1 and SecondsFromTime(1500) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;
def highs_last_hour = if last_hour then HIGH else double.nan; #update high and low only during last hour
def lows_last_hour = if last_hour then LOW else double.nan;
plot last_hour_highest = highestall(highs_last_hour);
plot last_hour_lowest = lowestall(lows_last_hour);

last_hour_highest.SetDefaultColor(GetColor(6));
last_hour_highest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
last_hour_lowest.SetDefaultColor(GetColor(5));
last_hour_lowest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#add cloud between the last hour high and low from that last hour of prev day though current day
AddCloud(if (GetLastDay() == GetDay() and GetLastYear() == GetYear()) then last_hour_highest else Double.NaN,last_hour_lowest,color.light_green);
AddCloud(if last_hour then last_hour_highest else Double.NaN,last_hour_lowest,color.gray);
 

ziongotoptions

Active member
hello I was wondering if someone could help create a script that would plot the high and low of the previous day's last hour high and low value before close( high and low between 15:00 and 14:00), so I could be able to see the next morning, I would really appreciate it
 

Svanoy

Well-known member
@ziongotoptions

Code:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = No;
input Show_Time_Frame_High_and_Low = Yes;
input periodstart = 1400;
input periodend = 1500;
input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];

def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
def h = fold ih = 0 to 1 while !IsNaN(close[10]) do varhigh;
def l = fold il = 0 to 1 while !IsNaN(close[10]) do varlow;
def o = fold io = 0 to 1 while !IsNaN(close[10]) do varopen;
def c = fold ic = 0 to 1 while !IsNaN(close[10]) do varclose;

plot PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PMLow.SetHiding(!Show_Time_Frame_High_and_Low);

plot DayHigh = if h > 1 then h else Double.NaN;
DayHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
DayHigh.SetDefaultColor(Color.LIGHT_GREEN);
DayHigh.SetHiding(!Show_High);

plot DayLow = if l > 1 then l else Double.NaN;
DayLow.SetPaintingStrategy(PaintingStrategy.DASHES);
DayLow.SetDefaultColor(Color.LIGHT_RED);
DayLow.SetHiding(!Show_Low);

plot DayOpen = if o > 1 then o else Double.NaN;
DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayOpen.AssignValueColor(if varopen >= varclose then Color.GREEN else Color.RED);
DayOpen.SetHiding(!Show_Open);

plot DayClose = if c > 1 then c else Double.NaN;
DayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayClose.AssignValueColor(if varopen >= varclose then Color.RED else Color.GREEN);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Time_Frame_High_and_Low,PreHigh,"Time Frame High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Time_Frame_High_and_Low,PreLow,"Time Frame Low",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Time_Frame_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Time_Frame_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
Last edited:

steve123

New member
Might it be possible for someone to write a study that plotted a previous days time range (hi, lo, mid) as defined by the user, that would display on the current day from open to close? For example, the user defines a range from 1:00 to 2:00, and the hi, lo, and mid of that time range from the previous day displays throughout the current day? Thanks, Steven
 

ziongotoptions

Active member
Might it be possible for someone to write a study that plotted a previous days time range (hi, lo, mid) as defined by the user, that would display on the current day from open to close? For example, the user defines a range from 1:00 to 2:00, and the hi, lo, and mid of that time range from the previous day displays throughout the current day? Thanks, Steven
There’s already a script on here for that, use the search function, it’s only missing the mid. Search for “high/low” something like that
 

steve123

New member
There’s already a script on here for that, use the search function, it’s only missing the mid. Search for “high/low” something like that
Thanks for your reply. I am looking for one that displays yesterdays levels throughout today. Instead of stopping the display of yesterday's range when today's range starts, I would like a script to display yesterday's range throughout the entire current day.
 

ziongotoptions

Active member

steve123

New member
Thanks again. I have been using the plot in the link and it works nicely. The plot of the previous day ends when the script begins calculating the present day time frame. It would be great if the previous day time frame displayed throughout the current day, in addition to the current day's plot. So, a 9-10 AM plot would from both days would display throughout the day. It would be wonderful if a midpoint were included.
 

halcyonguy

Well-known member
VIP
Lifetime

Similar threads

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