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

addLabel(1, h);
addLabel(1, l);

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;
addLabel(show_labels, "highest " + highest...
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);
#
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
484 Online
Create Post

Similar threads

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.
Back
Top