How to Plot CURRENT Daily High?

I'm working on a High of Day Momentum Breakout type strategy, and would like to be able to plot TODAY's rolling highest high, but I'm running into some issues that I think pertain to bar counting. woohoo......

This is what I have so far:

Code:
# Get yesterday's high to use for today
def yesterdaysHigh = DailyHighLow("aggregation period" = AggregationPeriod.DAY, length = 1, displace = -1, "show only last period" = no).DailyHigh;

# Mark the BarNumber() for today's opening bar
def todaysOpeningBarNumber = if GetDay() != GetDay()[1] then BarNumber() else todaysOpeningBarNumber[1];

# Get the difference between the previous bar's BarNumber()
# and todaysOpeningBarNumber to use as the Highest(length)
# parameter next
def potentialBarDiff = BarNumber()[1] - todaysOpeningBarNumber;

# Get the highest high from today's opening bar up to the previous
# bar
def highestHighSinceOpeningBar = Highest(data=high[1], length=potentialBarDiff);

# Plot today's highest high!
plot currentDailyHigh = Max(yesterdaysHigh, highestHighSinceOpeningBar);
currentDailyHigh.SetDefaultColor(Color.YELLOW);

(Notice how I'm using shifts of [1] here as I will be looking for the current bar's high to breakout from the previous high.)

The problem with this code is the length used for the Highest() function, as I receive the "Only constants expected here" because the length of potentialBarDiff changes as bars progress.

There's a lot of content around getting yesterday's high which I've already done, but as today's high pushes higher, I want to plot the highest high for today, which is (psuedo):

Code:
 def currentDailyHigh = Max(yesterdaysHigh, Highest(data=high[1], length=BarNumber() - todaysOpeningBarNumber))

Am I on the right track here, or is there a script already made for this somewhere that I just haven't found yet?
 
Solution
I should mention that I will be using this on intraday timeframes (5 minute specifically but any of them should work).

See if this helps you. It finds the HHigh today, it's barnumber, and the High of the bar prior to HH. I left on the plot of barnumbers for testing. A label shows the outputs.

Screenshot-2022-10-16-170210.png
Ruby:
plot bn = barnumber();
bn.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
# Get yesterday's high to use for today
def yesterdaysHigh = DailyHighLow("aggregation period" = AggregationPeriod.DAY, length = 1, displace = -1, "show only last period" = no).DailyHigh;

# Mark the BarNumber() for today's opening bar
def todaysOpeningBarNumber = if GetDay() != GetDay()[1] then Bn else todaysOpeningBarNumber[1];

# Get the...

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

I should mention that I will be using this on intraday timeframes (5 minute specifically but any of them should work).

See if this helps you. It finds the HHigh today, it's barnumber, and the High of the bar prior to HH. I left on the plot of barnumbers for testing. A label shows the outputs.

Screenshot-2022-10-16-170210.png
Ruby:
plot bn = barnumber();
bn.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
# Get yesterday's high to use for today
def yesterdaysHigh = DailyHighLow("aggregation period" = AggregationPeriod.DAY, length = 1, displace = -1, "show only last period" = no).DailyHigh;

# Mark the BarNumber() for today's opening bar
def todaysOpeningBarNumber = if GetDay() != GetDay()[1] then Bn else todaysOpeningBarNumber[1];

# Get the difference between the previous bar's BarNumber()
# and todaysOpeningBarNumber to use as the Highest(length)
# parameter next
def potentialBarDiff = bn[1] - todaysOpeningBarNumber;

# Get the highest high from today's opening bar up to the previous
# bar

def todayshh = if bn == todaysOpeningBarNumber then high else if high > todayshh[1] then high else todayshh[1];
def todayshhbar = if high == todayshh then bn else todayshhbar[1];

def previousbarhightoHighestHighSinceOpeningBar =  if bn == highestall(todayshhbar-1) then high else previousbarhightoHighestHighSinceOpeningBar[1];

AddLabel(1, "HH: " + todayshh[1] + " HHBar: " + todayshhbar + " PH: " + previousbarhightoHighestHighSinceOpeningBar, color.gray);
 
Solution
Thank you! This worked like a charm:


Code:
def currentBarNumber = BarNumber();

# Get yesterday's high to use for today
def yesterdaysHigh = DailyHighLow("aggregation period" = AggregationPeriod.DAY, length = 1, displace = -1, "show only last period" = no).DailyHigh;

# Mark the BarNumber() for today's opening bar
def todaysOpeningBarNumber = if GetDay() != GetDay()[1] then BarNumber() else todaysOpeningBarNumber[1];

# Get the highest high from today's opening bar up to the previous bar
def todaysHighestHigh = if currentBarNumber == todaysOpeningBarNumber then high else if high > todaysHighestHigh[1] then high else todaysHighestHigh[1];

# Plot today's highest high!
plot currentDailyHigh = Max(yesterdaysHigh, todaysHighestHigh);
currentDailyHigh.SetDefaultColor(Color.YELLOW);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
477 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