HOD and LOD time columns


Category:
0
0

How do I make a column showing time for High of Day, and a column showing time for Low of Day

If the same price is reached multiple times intraday, show the first time

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on July 2, 2022 6:43 pm
84 views
0
Found some code to show HOD time and LOD time: def D = 86400; def H = 3600; def epoch = (GetTime() / 1000); def hour = Floor((epoch % D) / H); # 5 hour diff for GMT DST def roll = if hour > 4 then hour - 4 else if hour < 4 then (hour + 24) - 4 else 0; def min = Floor(((epoch % D) % H)) / 60; def Up = high == high(period = "DAY"); def Dn = low == low(period = "DAY"); def tHUp = if Up then roll else tHUp[1]; def tMUp = if Up then min else tMUp[1]; def tHDn = if Dn then roll else tHDn[1]; def tMDn = if Dn then min else tMDn[1]; AddLabel(1,tHUP + ":" + (if tMUp < 10 then "0" else "") + tMUp, color.white); #AddLabel(1,tHDn + ":" + (if tMDn < 10 then "0" else "") + tMDn, color.white); But If a stock has reached its high multiple times intraday, the code would pick the last time to show. Not sure how to make it show the first time though
( at July 3, 2022 10:42 am)
0
Private answer

The solution posted in the comments section of the question will work for a chart study but not for a custom watchlist column set to an intraday time frame. The reason for this is that it references a secondary aggregation period to get the high of day. Secondary aggregation periods are not currently supported in Thinkorswim.

The leaves us with limited options. I cannot complete this request within the time limit I allow for free solutions in this forum. However I can provide link to a two previous solution which shows how to display the number of bars since the high and low of day:

https://www.hahn-tech.com/ans/highlow-of-day-column/

A savvy script writer may be able to combine that solution with some of the code from the comments section of the question to achieve the requested solution.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on July 3, 2022 11:14 am
0
Hi Pete, The code does work in a custom watchlist column, set the time frame to 1 minute and uncheck include extended hours. It shows HOD and LOD time accurately, here are two screenshots: https://imgur.com/a/KdAjQOT But it just picks the 'last time' rather than the 'first time' to show, if a stock set the same High or same Low multiple times throughout the day
( at July 3, 2022 10:19 pm)
0
This code is not working as you think it is. The secondary aggregation periods are not supported in custom watchlist columns. You can test this for your self by applying the following code to a new custom watchlist column: plot Up = high(period = "DAY"); When set to an intraday time frame, the column displays a value of "NaN". Not available. That statement is attempting to read the high from the daily time frame. If you change the custom column to a daily time frame it will display the correct high of day. So despite what you think, this code is not suitable for a custom watchlist column. Period. The only way to discover these deficiencies is to break the code down to individual pieces and identify what each line of the code is doing.
( at July 4, 2022 12:38 pm)