Opening Range Average

rlohmeyer

Active member
Hi,
I extracted code from an opening range breakout indicator, posted below. It defines the opening range as the first 30 minutes of the Regular Session. I am looking for how to modify or add to this code to allow me to define an average of the opening range for any particular instrument for the past x days. This would allow me to add labels or run scans for the instruments that have the largest initial ranges, which is useful for playing the opening range after the first 1-5 minutes.

Can anyone assist? Much appreciated.


Code:
# 30 min opening range Market Volatility V1.1
# Robert Payne
# Adapted to strategy by WalkingBallista and BenTen
#https://usethinkscript.com/threads/opening-range-breakout-strategy-with-market-volatility-for-thinkorswim.164/
#@rlohmeyer code extracted to determine actual size of opening range
def OpenRangeMinutes = 30;
def MarketOpenTime = 0930;
def ShowTodayOnly = no;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;
def ORH =  if FirstMinute then high else if OpenRangeTime and high > ORH[1] then high else ORH[1];
def ORL= if FirstMinute then low else if OpenRangeTime and low < ORL[1] then low else ORL[1];
#code added to determine size of opening range
def HL = Round(ORH - ORL, 2);
 
Solution
Hi,
I extracted code from an opening range breakout indicator, posted below. It defines the opening range as the first 30 minutes of the Regular Session. I am looking for how to modify or add to this code to allow me to define an average of the opening range for any particular instrument for the past x days. This would allow me to add labels or run scans for the instruments that have the largest initial ranges, which is useful for playing the opening range after the first 1-5 minutes.

Can anyone assist? Much appreciated.


Code:
# 30 min opening range Market Volatility V1.1
# Robert Payne
# Adapted to strategy by WalkingBallista and BenTen...
Hi,
I extracted code from an opening range breakout indicator, posted below. It defines the opening range as the first 30 minutes of the Regular Session. I am looking for how to modify or add to this code to allow me to define an average of the opening range for any particular instrument for the past x days. This would allow me to add labels or run scans for the instruments that have the largest initial ranges, which is useful for playing the opening range after the first 1-5 minutes.

Can anyone assist? Much appreciated.


Code:
# 30 min opening range Market Volatility V1.1
# Robert Payne
# Adapted to strategy by WalkingBallista and BenTen
#https://usethinkscript.com/threads/opening-range-breakout-strategy-with-market-volatility-for-thinkorswim.164/
#@rlohmeyer code extracted to determine actual size of opening range
def OpenRangeMinutes = 30;
def MarketOpenTime = 0930;
def ShowTodayOnly = no;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;
def ORH =  if FirstMinute then high else if OpenRangeTime and high > ORH[1] then high else ORH[1];
def ORL= if FirstMinute then low else if OpenRangeTime and low < ORL[1] then low else ORL[1];
#code added to determine size of opening range
def HL = Round(ORH - ORL, 2);

if a simple average will work for you, you could add up the close prices in the desired time periods, then divide by the quantity of bars, to get an average.

here is an idea outline

is the current bar within x days of the last bar?
..if so , is it during the orb time period?
....if so then,
......count bars,
def barcnt = barcnt[1] +1;
......add up close prices
def clstotal = clstotal[1] +close;

def avg = if count > 0 then clstotal/barcnt else 0;
 
Solution

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

@drasp
Thanks, but not using the info for entry, but for planning. If I use ORB trading, it is based on the first 15 minutes.

Regards,
Bob
make an indicator that takes the first 15 min candle and H+L/C and you have a great support and resistance indicator for opening range. [just be sure to be able to manipulate the timeframe].

This method works incredibly on tick charts too.
Opening candle [5min is what I prefer]. H+L/C, make it a horizontal line for the day; then use it as a place to get in. It also helps dicatate what the opening bias is.
 
Last edited:
make an indicator that takes the first 15 min candle and H+L/C and you have a great support and resistance indicator for opening range. [just be sure to be able to manipulate the timeframe].

This method works incredibly on tick charts too.
Opening candle [5min is what I prefer]. H+L/C, make it a horizontal line for the day; then use it as a place to get in. It also helps dicatate what the opening bias is.
I will look at this on the open over a few days.
 
@drasp @MerryDay

Well, I gave the Drasp Opening Range Support and Resistance Indicator a real test today, on NVIDIA (NVDA), which came out yesterday PM (11/17/21) with earnings that significantly beat estimates. NVIDIA was up 26% pre-market, so the first 5 minute bar ( my test opening range bar) was going to be a doozey. It was, with a range of almost $10. The results are below. The indicator is the white line with the heavy white dots. The indicator performed beautifully. Both indicator lines, above and below the first 5 minute bar, resisted several tests and reversed price. Price did not retest either for the rest of the session.

I am very impressed with the accuracy of this indicator, especially considering the significant increase in volatility of NVIDIA. This is now on my day trade chart for further look/see. Now a question, can you enlighten me on the logic behind this indicator and did you come up with it? I would really like to know.

I assume you code, but if you want the code I used let me know.

Regards,
Bob

LvVgnKh.jpg
 
@SuryaKiranC

Here is a link for my present PriceTimeGrid

It allows settings for 3 types of horizontal lines. The primary Increment, and what I refer to as the "Major" increment and "SMajor" increment. To insure these levels keep their integrity I only use Levels such as .25, .5, 1, 5, 25 etc. You can also set a line to draw the midpoint of an increment. So if you set your Increment at .5, the midpoints will draw at .25.

It also allows you to draw vertical lines at particular time frames. Since I trade a 5 minute chart, I will set these at 15 minutes and 30 minutes.

I generally do not use this on a Day Chart, only intraday.

http://tos.mx/4Ll9oFp

Regards,
Bob
 
@drasp @MerryDay

Well, I gave the Drasp Opening Range Support and Resistance Indicator a real test today, on NVIDIA (NVDA), which came out yesterday PM (11/17/21) with earnings that significantly beat estimates. NVIDIA was up 26% pre-market, so the first 5 minute bar ( my test opening range bar) was going to be a doozey. It was, with a range of almost $10. The results are below. The indicator is the white line with the heavy white dots. The indicator performed beautifully. Both indicator lines, above and below the first 5 minute bar, resisted several tests and reversed price. Price did not retest either for the rest of the session.

I am very impressed with the accuracy of this indicator, especially considering the significant increase in volatility of NVIDIA. This is now on my day trade chart for further look/see. Now a question, can you enlighten me on the logic behind this indicator and did you come up with it? I would really like to know.

I assume you code, but if you want the code I used let me know.

Regards,
Bob

LvVgnKh.jpg
It’s good isn’t it. And I see you used the previous days line which is interesting.

I don’t code nope. So if you made a line props to you. I might even ask to borrow it. Opening range is like the pivot point. If you add yesterday’s pivot point. Today’s pivot point. And today’s opening range 5-30 min candle you have a great setup. The only question is when to get out.

The logic is self evident. It’s your original question. Its the average bias of the opening range whatever you define it.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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