UPDATE 4 May 2009: Modified code so user can specify the open time. This is useful for trading the OR in other markets such as the Globex futures session.
UPDATE 11 Feb 2009: Added second fib extension option per Jim’s comment.
Trader-X has returned to blogging recently (and there was much rejoicing)! He is sharing his new, simplified setups on his blog. I decided to do some Thinkscript code to automate the plotting of the opening range and the Fibonacci retracements and extensions that Trader-X now uses. This is all my own interpretation of what X is doing, so any errors are my own.
I decided that the plot behavior I would want is to plot these lines starting from when the OR is defined, showing nothing at any time earlier than that. This helps to visually cue you to NOT take a trade before the OR is completed! If you want to see the levels for each day, set the input “ShowTodayOnly” to “No”. You also input the time (EST) that the OR begins, and the time the OR is “completed”. If your market opened at 9:30 EST, and you wanted a 30 minute opening range, you would enter “0930” for ORBegin, and “1000” for OREnd (and that is the default). A 60 minute OR would be “0930” and “1030”, respectively. Finally, you can input the fib extension you want plotted as well.
Here is the code:
# Automatic Opening Range and Fibonacci Levels
# By Prospectus @ https://readtheprospectus.wordpress.com
# Inspired by Trader-X @ http://traderx.blogspot.com
#
# This Thinkscript is designed to plot the OR high, low,
# 50% fib retrace, and fib extensions for the current day.
# This will only work correctly on time-based charts,
# where the OR timeframe is divisible by the bar period
# e.g. 30 minute OR, 10 min bars. An extra fib extension
# may be used if desired to create a target zone.
#
def na=double.nan;
#
# Define time that OR begins (in hhmm format,
# 0930 is the default):
#
input ORBegin = 0930;
#
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
#
input OREnd = 1000;
#
# Input first and second fib extension levels
# (default 1.382, 1.621):
#
Input FibExt1=1.382;
Input FibExt2=1.621;
#
# Show Today only? (Default Yes)
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
# Show Second fib extension? (Default No)
#
input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
#
# Create logic for OR definition:
#
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;
#
# Create logic to paint only current day post-open:
#
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;
#
# Track OR High:
#
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];
#
# Track OR Low:
#
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];
#
# Calculate OR width:
#
Def ORWidth = ORHigh - ORLow;
#
# Calculate fib levels:
#
Def fib_mid = (ORHigh+ORLow)/2;
Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);
Def fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);
Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);
Def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);
#
# Define all the plots:
#
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot FibMid=if ORActive OR today<1 then na else fib_mid;
Plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;
Plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;
Plot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;
Plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;
#
# Formatting:
#
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Long_DASH);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Long_DASH);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setStyle(curve.SHORT_DASH);
FibMid.setlineweight(3);
FibExtUp1.setdefaultcolor(color.green);
FibExtUp1.setStyle(curve.SHORT_DASH);
FibExtUp1.setlineweight(2);
FibExtDown1.setdefaultcolor(color.red);
FibExtDown1.setStyle(curve.SHORT_DASH);
FibExtDown1.setlineweight(2);
FibExtUp2.setdefaultcolor(color.green);
FibExtUp2.setStyle(curve.SHORT_DASH);
FibExtUp2.setlineweight(1);
FibExtDown2.setdefaultcolor(color.red);
FibExtDown2.setStyle(curve.SHORT_DASH);
FibExtDown2.setlineweight(1);
Tags: fibonacci_retracements, opening_range, Thinkscript, trader-x
February 9, 2009 at 8:33 pm
Prospectus,
Nice job of coding. I like your color scheme.
You might consider also adding the 1.62 extension level so that you have a target range 1.38-1.62. A market will good momentum will often move thru the 1.38 extension and tag the other side of the zone (1.62).
February 10, 2009 at 6:47 am
Thanks, Jim. I’ll add in one more Fib extension level.
February 10, 2009 at 3:31 pm
Can we detect what timeframe is set and use it for plotting, because every time you need change ORTime?
February 10, 2009 at 3:32 pm
And of couse – good job, Prospectus!
February 11, 2009 at 10:52 am
Pupsor,
As I understand it, Trader-X sticks to a 30 minute opening range, regardless of the timeframe of the bars. If you put “1000” in as the time that the OR is finished, then my thinkscript is smart enough to figure out how many bars it needs to be for that time. I’m not sure why you would need to change the OR time based on chart timeframe.
If that doesn’t clarify, then I don’t understand your question, I guess. If so, feel free to ask again!
February 13, 2009 at 4:14 pm
Prospectus,
I am glad you decided to make this study. I have been trying to make this for eSignal for a while, but have had a tough time with the code, etc. I was very excited when I read your comment on Trader X’s blog stating that you were going to work on it, but didn’t expect it that quick! This is very helpful.
Thanks,
Tyler
February 13, 2009 at 5:03 pm
Tyler,
No problem. Good luck with your coding and trading!
March 3, 2009 at 3:29 am
can this be done in Quotetracker, too ? thanks
March 3, 2009 at 4:44 am
Quentin:
QuoteTracker doesn’t let you create custom indicators. You could add some paintbar code to paint something like a dot when price crosses a fib level, but you would have to do a lot of hard-coded nested logic. Plus, you wouldn’t get the fib levels to plot on the chart. So yes and no, to answer your question. You can manually draw a fib retracement of course, but that could get tedious.
May 30, 2009 at 8:48 pm
Great script, thanks for sharing!! 🙂
July 15, 2009 at 12:54 am
I am unable to make this code work in think or swim.
Getting error ORWidth with error :- “No such variable ORWidth at 65:28”
Def ORWidth = ORHigh – ORLow;
Can some one help please.
Thanks
Subramanik
July 15, 2009 at 4:08 am
Subramanik,
In your thinkscript editor, delete all the “-” in the code and type a new “-” from your keyboard. That should fix your problem. WordPress changed the “-” from the code I typed in into a fancy hyphen character that thinkscript chokes on. I’ve fixed it in the code, so future users can just copy/paste the code from the article above and it should work.
July 21, 2009 at 11:25 am
tks for the effort you put in here I appreciate it!
November 6, 2009 at 2:50 am
Prospectus,
Nice looking indicator. I had a question though.
How can I use this in a 24 hrs market such as the currency futures ? I trade the Euro a lot and was wondering if the open range envelope should be started earlier to account for the 24 hrs nature of contract. If so what time would be the Start Time ?
Your thoughts would be appreciated.
November 7, 2009 at 10:33 am
I would think you want to align with an “open” somewhere, be it New York, London or Tokyo. But I’m not a forex expert by any means.
January 30, 2010 at 1:54 am
Hi, I noticed the plots start at 10 instead of 9:30. Could we shift the lines left?
January 30, 2010 at 9:05 pm
I’ll work on it
February 1, 2010 at 8:18 pm
Hello,
I want to thank you for your contribution to the trading community.. Was referred here today by someone in our chatroom…
I made a few changes to this study so I could obtain the Initial Balance (first hour) of trading, which works very well thank you… I tried to make the changes to show me the previous days information but it does not want to show up. Can you help me with that? The only thing I need is the high and low for the first hour and able to see previous days information as well.
Just as an FYI, I have used 4 seperate studies to give me the IB, ongoing midpoint, previuos days high, low and close .. really good info to have on there… The only other item I am looking for is to plot the opening print, is there an easy way to do that or to add it to the study?
Thanks in advance,
Followmytrade
February 2, 2010 at 7:06 pm
followmytrade,
You can plot the opening print like this:
def prioropen=open(period=”DAY”)[1];
February 9, 2011 at 1:57 am
Hi,
Have you coding this OR Auto FIB levels in Ninja Trader Script? Can you share it here? Tx in advance…
March 30, 2011 at 12:03 pm
Hello,
Is there a way to plot the input values on top of each retracement line?
Plot 138.2%, 162.1%, etc on the left edge on top of each retracement line and the $amount on the rigth edge, so that we know the value each line represents.
Just like a normal fib drawing does.
Thank you
March 30, 2011 at 1:27 pm
I’ll look into it
September 14, 2011 at 2:17 pm
[…] 2011GBP/JPY Elliott wave count and Fibonacci levels for September 13, 2011Lesson 3: Fibonacci LevelsAutomatic Opening Range and Fibonacci Levels for Think or Swim div.socialicons{float:left;display:block;margin-right: 10px;}div.socialicons p{margin-bottom: […]
October 5, 2011 at 10:51 am
love your code.
what would be the trick to draw a set of fibs for the 16h00 – 09h30 globex session?
thank you.
July 24, 2012 at 12:42 pm
[…] for Ninja trader. Thanks, using TOS, found a free OR indie that works if anyone else wants it: Automatic Opening Range and Fibonacci Levels for Think or Swim Read the Prospectus Set times and disabled all plots except ORH and ORL. So today's OR is 87.43 to 88.36, correct? […]
November 29, 2012 at 10:59 am
Great Indicator!
Could we have the Fib level number showing on the right side of of the chart just above the Fib levels? 1.621.. etc..
Thanks
September 24, 2013 at 11:30 am
[…] Automatic Opening Range and Fibonacci Levels for Think or Swim … […]
September 26, 2013 at 10:43 am
Its an Excellent Script! THANKS for sharing!
October 15, 2013 at 4:47 pm
[…] Automatic Opening Range and Fibonacci Levels for Think or Swim … […]
August 26, 2014 at 5:05 pm
[…] Automatic Opening Range and Fibonacci Levels for Think or Swim … […]
August 27, 2015 at 12:45 pm
awesome, this study rocks. Thanks
December 4, 2016 at 7:53 pm
Thank you for your site post. Jones and I happen to be saving for just a new e-book oon this issue and your writing hhas made
people like us to save all of our money. Yourr ideaas really responded to all our issues.
In fact, over what we had known just before wwe
ran into your xcellent blog. We no longer nurture
doubts along with a troubled mind because you have actually attended to
each of our needs here. Thanks
February 26, 2017 at 4:16 pm
Great script, is there a way to set it for the most resent high/low instead calculating the hole day.
Thanks
August 15, 2017 at 7:03 pm
I am impressed with your considerate method, let’s connect some
point.
January 16, 2018 at 8:19 pm
I appreciate you for this, I’ll certainly share it with my favorite audience.
January 30, 2018 at 7:02 pm
Your notions on trading are really extraordinary, I am going to throw several of my readers to your web site.
March 9, 2018 at 7:20 pm
The foundation regarding your investing method is effortless to see.
Many thanks for distributing this with us at this moment.
May 5, 2018 at 3:28 am
Excellent script but does not work on the thinkscript mobile platform. Have you noticed such differences between the mobile and desktop platforms
May 9, 2018 at 11:47 am
Yes. I need to go back and make changes, but haven’t found time
July 30, 2018 at 1:52 am
Everything you come up with hits a nerve with me, thanks for baffling your followers.
December 19, 2020 at 2:12 pm
would you be able to convert this awesome indicator to ninjascript(for NT8)?