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

Similar threads

Top