Whats wrong with my code (Open High Low indicator)

Trigun1127

Member
So I have my code set to display yesterdays High And Low while also displaying just the days open price for that current day. However the open price has been inaccurate for the past two days either by a tick or a whole point. I'm also using this on the 5 minute chart.

declare hide_on_daily;
declare once_per_bar;

input timeFrame = {default DAY, WEEK, MONTH};

plot high = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, high(period = timeFrame)[1], Double.NaN);
plot Low = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, low(period = timeFrame)[1], Double.NaN);
plot Open = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, open(period = timeFrame)[0], Double.NaN);

high.SetDefaultColor (Color.GREEN);
high.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Open.SetDefaultColor (Color.Yellow);
Open.SetPaintingStrategy(PaintingStrategy.DASHES);

 
Solution
Its actually very odd be cause orginally the study was working fine. Now its always off by a tick. I have no clue whats causing the issue.

Heres a picture of the databox

I adjusted your code to not use open(period=timeframe)[0], but to just open, which is how I usually do it, when it is for today's open. This seems to work consistently. I did see the former worked before at times.

That is probably what was causing the slight differences. I would not recommend the plot names the way you did and then used a different version of the same plot name within your logic. For example, using plot high = ... high(period=timeframe)[1]... would be better if it were def hi = high(period=timeframe)[1]... and plot high =...
So I had a chance to test today, yesterday oddly I had no problem on old code but then today the High wasnt printing. So input new code and this is what what's happening
Before Candle Close
After Candle Close

I am assuming you are referencing that the new code sometimes does not extend the lines. If so, this should hopefully fix that.

The code fix I did friday used !isnan(close) to ensure that it picked up periods with data. The code fix I just did with isnan(close) on hi, lo, op extended those lines if there is no data.

Thanks for letting me know!

Ruby:
declare hide_on_daily;
declare once_per_bar;

input timeFrame = {default DAY, WEEK, MONTH};
def x      = if timeFrame == timeFrame.WEEK
             then GetWeek()
             else if timeFrame == timeFrame.MONTH   
             then GetMonth()
             else GetDay();
def hi     = if isnan(close)
             then hi[1]
             else If(!isnan(close) and GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN and
             x != x[1],
             high(period = timeFrame)[1],
             hi[1]);
plot high  = hi;
def lo     = if isnan(close)
             then lo[1]
             else If(!isnan(close) and GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN and
             x != x[1] ,
             low(period = timeFrame)[1],
             lo[1]);
plot Low   = lo;
def op     = if isnan(close)
             then op[1]
             else If(!isnan(close) and GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN and
             x != x[1] ,
             open,
             op[1]);
plot Open  = op;

high.SetDefaultColor (Color.GREEN);
high.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Open.SetDefaultColor (Color.YELLOW);
Open.SetPaintingStrategy(PaintingStrategy.DASHES);
 
I am assuming you are referencing that the new code sometimes does not extend the lines. If so, this should hopefully fix that.

The code fix I did friday used !isnan(close) to ensure that it picked up periods with data. The code fix I just did with isnan(close) on hi, lo, op extended those lines if there is no data.

Thanks for letting me know!
Looking good no more issues that I'm seeing currently!
 

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
470 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