# Return highest and lowest in the day without considering current candle?

#### kkrac

##### New member
For a watchlist column, I want to get the highest and lowest candle in the current day (5min chart) without considering the current candle that is being drawn.
I have this code:

Code:
``````def day = GetDay();
def h = if day != day[1]
then high
else if day[1] != day[2] or high[1] > h[2]
then high[1]
else h[2];

def l = if day != day[1]
then low
else if day[1] != day[2] or low[1] < l[2]
then low[1]
else l[2];

But for some reason it sometimes shows the correct candle but sometimes it doesn't, I can't understand why.

Can someone help out?

Note: as far as I know, I cannot reference a higher timeframe in a watchlist column, otherwise it would be easy I think by doing highest = high(period = "day");

Thanks

Last edited:
Solution
For a watchlist column, I want to get the highest and lowest candle in the current day (5min chart) without considering the current candle that is being drawn.

instead of current , think of it as the last bar.
i changed the offsets, so the current bar is compared to previous values, EXCEPT when it is the last bar.

this is a chart study, to test with and verify it is working
Ruby:
``````def day = GetDay();

def highest =
if day != day[1] then high
else if isnan(close[-1]) then highest[1]
else if high > highest[1] then high else highest[1];

def lowest = if day != day[1] then low
else if isnan(close[-1]) then lowest[1]
else if low < lowest[1] then low else lowest[1];

input show_labels = yes;
For a watchlist column, I want to get the highest and lowest candle in the current day (5min chart) without considering the current candle that is being drawn.

instead of current , think of it as the last bar.
i changed the offsets, so the current bar is compared to previous values, EXCEPT when it is the last bar.

this is a chart study, to test with and verify it is working
Ruby:
``````def day = GetDay();

def highest =
if day != day[1] then high
else if isnan(close[-1]) then highest[1]
else if high > highest[1] then high else highest[1];

def lowest = if day != day[1] then low
else if isnan(close[-1]) then lowest[1]
else if low < lowest[1] then low else lowest[1];

input show_labels = yes;
addLabel(show_labels, "highest " + highest, color.green);
addLabel(show_labels, "lowest " + lowest, color.red);

input show_test_lines = no;
plot z1 = if show_test_lines then highest else double.nan;
plot z2 = if show_test_lines then lowest else double.nan;``````

--------------------------------------------------------

here is a column study.
it shows the highest and lowest for each symbol.

if you want 2 columns, one for high and one for low, copy this study and edit the addlabel

Ruby:
``````#
def day = GetDay();

def highest =
if day != day[1] then high
else if isnan(close[-1]) then highest[1]
else if high > highest[1] then high else highest[1];

def lowest = if day != day[1] then low
else if isnan(close[-1]) then lowest[1]
else if low < lowest[1] then low else lowest[1];

# use white font with dark background
addlabel(1, "H " + round(highest,2) + " | " + "L " + round(lowest,2), color.white);

# if the background is changed to a lighter color, change font to black
#addlabel(1, "H " + round(highest,2) + " | " + "L " + round(lowest,2), color.black);
#assignbackgroundcolor(color.yellow);
#``````

87k+ Posts
401 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?