Price-based, not time-based Opening Range

MitchInSF

New member
Hi Gang!

I'm trying to build an opening range indicator that's based on first reversals of initial highs and lows and NOT time-dependent. I don't want to arbitrarily say my opening range is 2 bars or 10 bars, I want it determined by the price action itself.

Example: let's suppose we have 4 bars with the following OHLC values:

100-110-90-95 <-- highest high = 110
95-105-85-90 <-- lowest low set here at 85.
90-100-87-90 <-- we now know that 85 is the lowest low, because this bar has a higher low of 87
90-95-90-100 <-- this bar is immaterial as we've had our first higher low OR our first higher high.

So, I consider my opening range to be 85 - 110.

I'm jet lagged out of my mind or would try to write this myself right now, but instead am going to get some sunshine on my face and think about it. Meanwhile, If someone has this laying around, it would be much appreciated!

Thanks!

(just realized I'd originally posted this in the wrong place - apologies!)
 
Last edited:
Solution
Hi Gang!

I'm trying to build an opening range indicator that's based on first reversals of initial highs and lows and NOT time-dependent. I don't want to arbitrarily say my opening range is 2 bars or 10 bars, I want it determined by the price action itself.

Example: let's suppose we have 4 bars with the following OHLC values:

100-110-90-95 <-- highest high = 110
95-105-85-90 <-- lowest low set here at 85.
90-100-87-90 <-- we now know that 85 is the lowest low, because this bar has a higher low of 87
90-95-90-100 <-- this bar is immaterial as we've had our first higher low OR our first higher high.

So, I consider my opening range to be 85 - 110.

I'm jet lagged out of my mind or would try to write this...
Hi Gang!

I'm trying to build an opening range indicator that's based on first reversals of initial highs and lows and NOT time-dependent. I don't want to arbitrarily say my opening range is 2 bars or 10 bars, I want it determined by the price action itself.

Example: let's suppose we have 4 bars with the following OHLC values:

100-110-90-95 <-- highest high = 110
95-105-85-90 <-- lowest low set here at 85.
90-100-87-90 <-- we now know that 85 is the lowest low, because this bar has a higher low of 87
90-95-90-100 <-- this bar is immaterial as we've had our first higher low OR our first higher high.

So, I consider my opening range to be 85 - 110.

I'm jet lagged out of my mind or would try to write this myself right now, but instead am going to get some sunshine on my face and think about it. Meanwhile, If someone has this laying around, it would be much appreciated!

Thanks!

(just realized I'd originally posted this in the wrong place - apologies!)

this is something i did quick that i think is what you want,

Code:
# orb_rng_price_not_bars_01

# https://usethinkscript.com/threads/price-based-not-time-based-opening-range.12509/
# I'm trying to build an opening range indicator that's based on first reversals of initial highs and lows and NOT time-dependent. I don't want to arbitrarily say my opening range is 2 bars or 10 bars, I want it determined by the price action itself.


def na = Double.NaN;
#input show_ORB_label = yes;

input show_range_lines = no;
def srl = show_range_lines;

input show_arrows = yes;

# open/close times  (ET)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;


# get candle width , seconds , timeframe
#def getaggmin = round(getaggregationPeriod()/60,0);
def getgg = GetAggregationPeriod();
def getaggmin = Round(getgg / 60, 0);

def firstbar = if secondsfromTime(start) == 0 then 1 else 0;

def top = if firstbar then 1
 else if top[1] == 0 then 0
 else if daytime and high < high[1] then 0
 else if daytime and high > high[1] then 1
 else 0;


def bot = if firstbar then 1
 else if bot[1] == 0 then 0
 else if daytime and low > low[1] then 0
 else if daytime and low < low[1] then 1
 else 0;


def topz;
if firstbar then {
 topz = fold k = 0 to 400
 with p
 while getvalue(top, -k) == 1
 do getvalue(high, -k);
} else {
 topz = topz[1];
}

plot topline = topz;
topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topline.SetDefaultColor(Color.cyan);
#topline.setlineweight(1);
topline.hidebubble();


def botz;
if firstbar then {
 botz = fold m = 0 to 400
 with q
 while getvalue(bot, -m) == 1
 do getvalue(low, -m);
} else {
 botz = botz[1];
}

plot botline = botz;
botline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
botline.SetDefaultColor(Color.cyan);
#botline.setlineweight(1);
botline.hidebubble();


# --------------------------
# test stuff

addchartbubble(0, low,
top + " T\n" +
bot + " B"
, color.yellow, no);
#
 
Solution

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

this is something i did quick that i think is what you want,

Code:
# orb_rng_price_not_bars_01

# https://usethinkscript.com/threads/price-based-not-time-based-opening-range.12509/
# I'm trying to build an opening range indicator that's based on first reversals of initial highs and lows and NOT time-dependent. I don't want to arbitrarily say my opening range is 2 bars or 10 bars, I want it determined by the price action itself.


def na = Double.NaN;
#input show_ORB_label = yes;

input show_range_lines = no;
def srl = show_range_lines;

input show_arrows = yes;

# open/close times  (ET)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;


# get candle width , seconds , timeframe
#def getaggmin = round(getaggregationPeriod()/60,0);
def getgg = GetAggregationPeriod();
def getaggmin = Round(getgg / 60, 0);

def firstbar = if secondsfromTime(start) == 0 then 1 else 0;

def top = if firstbar then 1
 else if top[1] == 0 then 0
 else if daytime and high < high[1] then 0
 else if daytime and high > high[1] then 1
 else 0;


def bot = if firstbar then 1
 else if bot[1] == 0 then 0
 else if daytime and low > low[1] then 0
 else if daytime and low < low[1] then 1
 else 0;


def topz;
if firstbar then {
 topz = fold k = 0 to 400
 with p
 while getvalue(top, -k) == 1
 do getvalue(high, -k);
} else {
 topz = topz[1];
}

plot topline = topz;
topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topline.SetDefaultColor(Color.cyan);
#topline.setlineweight(1);
topline.hidebubble();


def botz;
if firstbar then {
 botz = fold m = 0 to 400
 with q
 while getvalue(bot, -m) == 1
 do getvalue(low, -m);
} else {
 botz = botz[1];
}

plot botline = botz;
botline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
botline.SetDefaultColor(Color.cyan);
#botline.setlineweight(1);
botline.hidebubble();


# --------------------------
# test stuff

addchartbubble(0, low,
top + " T\n" +
bot + " B"
, color.yellow, no);
#
 
@halcyonguy This is so good. While poking through the (wonderful!) treasure trove of usethinkscript, I came across this:

https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/

I'm trying to push the beautiful square box you gave me into this powerful round hole provided by @BenTen. If you're looking for a new challenge, can you convert @BenTen 's beautiful beast into a price-based opening range from the current 5m or 15m?

If it's too big an ask, I totally understand. I know it's one thing to build your own code and a totally different thing to work within someone else's framework.

Cheers!
 
@halcyonguy This is so good. While poking through the (wonderful!) treasure trove of usethinkscript, I came across this:

https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/

I'm trying to push the beautiful square box you gave me into this powerful round hole provided by @BenTen. If you're looking for a new challenge, can you convert @BenTen 's beautiful beast into a price-based opening range from the current 5m or 15m?

If it's too big an ask, I totally understand. I know it's one thing to build your own code and a totally different thing to work within someone else's framework.

Cheers!

that looks interesting.
i am busy with house projects, and spending more time on here than i should... i will look at it in a week or 2.
i'm ok if someone else does it before me.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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