jayy

extended session - Regular Opening-Range- Jayy

Opening Range and some other scripts updated to plot correctly (see comments below.) There are three variations of the fibonacci expansion beyond the opening range and retracements within the opening range of the US Market session - I have not put in the script for the other markets yet.
The three scripts have different uses and strengths:
The extended session script (with the script here below) will plot the opening range whether you are using the extended session or the regular session. (that is to say whether "ext" in the lower right hand corner is highlighted or not.). While in the extended session the opening range has some plotting issues with periods like 13 minutes or any period that is not divisible into 330 mins with a round number outcome (eg 330/60 =5.5. Therefore an hour long opening range has problems in the extended session.

The pre session script is only for the premarket. You can select any opening range period you like. I have set the opening range to be the full premarket session. If you select a different session you will have to unselect "pre open to 9:30 EST for Opening Range?" in the format section. The script defaults to 15 minutes in the "period Of Pre Opening Range?". To go back to the 4 am to 9:30 pre opening range select "pre open to 9:30 EST for Opening Range?" there is no automatic 330 minute selection.

The past days offset script only works in 5 min or 15 minute period. It will show the opening range from up to 20 days past over the current days price action. Use this for the regular session only. 0 shows the current day's opening range. Use the positive integers for number of days back ie 1, 2, 3 etc not -1, -2, -3 etc. The script is preprogrammed to use the current day (0).

Scripts updated to plot correctly: One thing they all have in common is a way of they deal with a somewhat random problem that shifts the plots 4 hours in one direction or the other ie the plot started at 9:30 EST or 1:30PM EST. This issue started to occur approximately June 22, 2015 and impacts any script that tried to use "session" times to manage a plot in my scripts. The issue now seems to have been resolved during this past week.

Just in case the problem reoccurs I have added a "Switch session plot?" to each script. If the plot looks funny check or uncheck the "Switch session plot?" and see the difference. Of course if a new issue crops up it will likely require a different fix.
I have updated all of the scripts shown on this chart. If you are using a script of mine that suffers from the compiler issue then you will find an update on this chart. You can get any and all of the scripts by clicking on the small sideways wishbone on the left middle of the chart. You will see a dialogue box. Then click "make it mine". This will import all of the scripts to your computer and you can play around with them all to decide what you want and what you don't want. This is the easiest way to get all of the scripts in one fell swoop. It is also the easiest way for me to make all of the scripts available. I do not have all of the plots visible since it is too messy and one of the scripts (pre OR) is only for the regular session. To view the scripts click on the blue eye to the right of the script title to show it on this script. If you can only use the regular session. The scripts will all (with the exception of the pre OR) work fine.

If for any reason this script seems flakey refresh the page r try a slightly different period. I have noticed that sometimes randomly the script loves to return to the 5 min OR. This is a very new issue transient issue. As always if you see an issue please let me know.

Cheers Jayy

Jayy
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
/////Uses 15 min OR. Targets set at 127% , 162%, 200 %, 262 %, 362%, 423%, 685%, 1109% and 1794% 
//of the selected opening range
//Plots only on intraday charts and you can turn on and off some of the fib targets
// option to display fib targets within Opening Range
// as per http://tradingwithleafwest.net/wp-content/uploads/2015/03/How-to-Draw-Open-Ranges.pdf
// for more on OR Leaf__West style see http://tradingwithleafwest.net/?page_id=290 @ http://tradingwithleafwest.net/ 
//If for some reason this pdf os not at Leaf West's Site I can email it to you.'
// This version is a slight update to the original which stopped functioning fully after a recent update to
//Tradingview regarding sessions - at least the issue started coincidently to the recent change. 
// This only does the opening range for 930 to 1600.
//Originally created by ChrisMoody on 7-07-2014, Special Thanks To "The Coding Genius Behind The Curtain"
study(title="extended session - Regular  Opening-Range- Jayy", shorttitle=" extended Regular Opening Range - Jayy", overlay=true)


apt1 = input(127, minval=.01, maxval=150, title="Target A - 127% of Opening Range")
apt2 = input(161.8, minval=.01, maxval=600, title="Target 1 -161.8% of Opening Range")
apt3 = input(200, minval=.01, maxval=600, title="Target 2- 200% of Opening Range")
apt4 = input(261.8, minval=.01, maxval=600, title="Target 3 -261.8% of Opening Range")
apt5 = input(361.8, minval=.01, maxval=600, title="Target 4 - 361.8% of Opening Range")
apt6 = input(423, minval=.01, maxval=600, title="Target 5 - 423% of Opening Range")
apt7 = input(685, minval=.01, maxval=600, title="Target 6 - 685% of Opening Range")
apt8 = input(1109, minval=.01, maxval=600, title="Target 7 - 1109% of Opening Range")
apt9 = input(1794.4, minval=.01, maxval=600, title="Target 8 - 1794% of Opening Range")
sho362= input(true, title="Show 361.8%?")
sho423= input(true, title="Show 423%?")
sho685= input(false, title="Show 685%?")
sho1109= input(false, title="Show 1109? and 1794%?")
pltup = input(false, title= "plot fibs within OR from bottom up?")
pltdwn = input(false, title= "plot fibs within OR from top down?")
resol = input('15', type=resolution, title=" length/time Of Opening Range?")
snp = input(true, title="Plot 1 and 2 When 1st and 2nd Profit Target are Achieved?")
r= input("930-1600", type=session, title= "plot session")
highTimeFrame = input("D", type=resolution)
//sessSpec = input("930-1600", type=session)
sesst= input(true, title= "switch session plot?")
pt1= apt1-100
pt2= apt2-100
pt3= apt3-100
pt4= apt4-100
pt5= apt5-100
pt6= apt6-100
pt7= apt7-100
pt8= apt8-100
pt9= apt9-100

res15= resol=='15'?true:false
res30= resol=='30'?true:false
// Highhier  = security(tickerid,"D", high[1])
// Lowhier   = security(tickerid,"D", low[1])
// Closehier = security(tickerid,"D", close[1])
// Opentoday = security(tickerid,"D", open[1])
// shovwap = input(true, title= "Show VWAP?") 
// shoinsid = input(true, title= "Show inside and outside bars?") 
// sess= input(true, title= "switch session plot?")



x= "1331-2000"
y="931-1600"
plt=sesst?y:x
xi= "1330-2000"
yi="930-1600"
sessSpec=sesst?yi:xi
// xbg= "800-1330"



bartimeSess =  time('D', r) 
fr2to17 =  time(period) 
newbarSess = bartimeSess != bartimeSess[1]
high_range = valuewhen(newbarSess,high,0)
low_range = valuewhen(newbarSess,low,0)
adopt(r, s) => security(tickerid, r, s)
// HighRes = adopt(res15?'15':resol, high_range) // :res30?'30' // res15?'15':
// LowRes = adopt(res15?'15':resol, low_range)  // :res60?'60'
HighRes = adopt(resol, high_range) // :res30?'30' // res15?'15':
LowRes = adopt(resol, low_range)
is_newbar(rest, sess) =>
    t = time(rest, sess)
    change(t) != 0 ? 1 : 0
newbar = is_newbar(highTimeFrame, sessSpec)
highRes = newbar ? HighRes: nz(highRes[1])
lowRes= newbar ? LowRes: nz(lowRes[1])


//Formula For Opening Range

range = highRes - lowRes

//Highlighting Line Rules For Opening Range
highColor =time ("1", plt)?black:na //black
lowColor =time ("1", plt)?black:na //black

//Plot Statements For Opening Range Lines
openRangeHigh = plot(isintraday and time ("1", sessSpec)? highRes : na, color=highColor, style=line, linewidth=2)
openRangeLow = plot(isintraday and time ("1", sessSpec)? lowRes : na, color=lowColor, style=line, linewidth=2)

fill(openRangeHigh, openRangeLow, color=yellow, transp=80, title="Opening Range Fill")
openRangeMid= lowRes + range/2

plot ( openRangeMid, color=lowColor, style=line, linewidth=1)//(isintraday? lowRes : na, color=lowColor, style=line, linewidth=2)

pltupColor =time ("1", plt)?aqua:na //black
pltdwnColor =time ("1", plt)?fuchsia:na //black
plot(pltup?lowRes+ range*.236:na, color=pltupColor, linewidth=1)
plot(pltup?lowRes+ range*.382:na, color=pltupColor, linewidth=1)
plot(pltup?lowRes+ range*.618:na, color=pltupColor, linewidth=1)
plot(pltup?lowRes+ range*.786:na, color=pltupColor, linewidth=1)

plot(pltdwn?highRes- range*.236:na, color=pltdwnColor, linewidth=1)
plot(pltdwn?highRes- range*.382:na, color=pltdwnColor, linewidth=1)
plot(pltdwn?highRes- range*.618:na, color=pltdwnColor, linewidth=1)
plot(pltdwn?highRes- range*.786:na, color=pltdwnColor, linewidth=1)

//Formula For 127%
pft1 = pt1*.01
highRes2 = highRes+range*pft1
lowRes2 = lowRes-range*pft1
//Highlighting Line rules for 127%
highColor2 =time ("1", plt)?red:na //aqua
lowColor2 =time ("1", plt)?green:na //lime
//Plots For 127%
p1=plot(isintraday? highRes2 : na, color=highColor2, style=line, linewidth=1)
p2=plot(isintraday? lowRes2 : na, color=lowColor2, style=line, linewidth=1)

//Formula For 162%
pft2 = pt2*.01
highRes3 = highRes+range*pft2
lowRes3 = lowRes-range*pft2
//Highlighting Line rules for 162%
highColor3 =time ("1", plt)?red:na //aqua
lowColor3 =time ("1", plt)?teal:na //lime
//Plots For 162%
plot(isintraday? highRes3 : na, color=highColor3, style=line, linewidth=1)
plot(isintraday? lowRes3 : na, color=lowColor3, style=line, linewidth=1)

//Formula For 200%
pft3 = pt3*.01
highRes4 = highRes+range*pft3
lowRes4 = lowRes-range*pft3
//Highlighting Line rules for 200%
highColor4 =time ("1", plt)?red:na
lowColor4=time ("1", plt)?teal:na
//Plots For 200%
plot(isintraday? highRes4 : na, color=highColor4, style=line, linewidth=1)
plot(isintraday? lowRes4 : na, color=lowColor4, style=line, linewidth=1)


//Formula For 262%
pft4 = pt4*.01
highRes5 = highRes+range*pft4
lowRes5 = lowRes-range*pft4
//Highlighting Line rules for 262%
highColor5 =time ("1", plt)?red:na
lowColor5 =time ("1", plt)?green :na
//Plots For 262%
plot(isintraday? highRes5 : na, color=highColor5, style=line, linewidth=1)
plot(isintraday? lowRes5 : na, color=lowColor5, style=line, linewidth=1)

//Formula For 362%
pft5 = pt5*.01
highRes6 = highRes+range*pft5
lowRes6 = lowRes-range*pft5
//Highlighting Line rules for 362%
highColor6 =time ("1", plt)?red:na //aqua
lowColor6=time ("1", plt)?green:na //lime
//Plots For 362%
plot(isintraday and sho362? highRes6 : na, color=highColor6, style=line, linewidth=1)
plot(isintraday and sho362? lowRes6 : na, color=lowColor6, style=line, linewidth=1)


//Formula For 423%
pft6 = pt6*.01
highRes7 = highRes+range*pft6
lowRes7 = lowRes-range*pft6
//Highlighting Line rules for 423%
highColor7 =time ("1", plt)?red:na //aqua
lowColor7=time ("1", plt)?teal:na //lime 
//Plots For 423%
plot(isintraday and sho423? highRes7: na, color=highColor7, style=line, linewidth=1)
plot(isintraday and sho423? lowRes7 : na, color=lowColor7, style=line, linewidth=1)

//Formula For 685%
pft7 = pt7*.01
highRes8 = highRes+range*pft7
lowRes8 = lowRes-range*pft7
//Highlighting Line rules for 685%
//a=time ("1", "931-1600")?aqua:na
highColor8 =time ("1", plt)?red:na //aqua
lowColor8 = time ("1", plt)? green:na //lime
//Plots For 685%
plot(isintraday and sho685? highRes8: na, color=highColor8, style=line, linewidth=1)
plot(isintraday and sho685? lowRes8 : na, color=lowColor8, style=line, linewidth=1)


//Formula For 1109%
pft8 = pt8*.01
highRes9 = highRes+range*pft8
lowRes9 = lowRes-range*pft8
//Highlighting Line rules for1109%
//a=time ("1", "931-1600")?aqua:na
highColor9 =time ("1", plt)?red:na //aqua
lowColor9 = time ("1", plt)? green:na //lime
//Plots For1109%
plot(isintraday and sho1109? highRes9: na, color=highColor9, style=line, linewidth=1)
plot(isintraday and sho1109? lowRes9 : na, color=lowColor9, style=line, linewidth=1)

//Formula For Profit Target 1794%
pft9 = pt9*.01
highRes10 = highRes+range*pft8
lowRes10 = lowRes-range*pft8
//Highlighting Line rules for 1794%
//a=time ("1", "931-1600")?aqua:na
highColor10 =time ("1", plt)?red:na //aqua
lowColor10 = time ("1", plt)? green:na //lime
//Plots For 1794%
plot(isintraday and sho1109? highRes10: na, color=highColor10, style=line, linewidth=1)
plot(isintraday and sho1109? lowRes10 : na, color=lowColor10, style=line, linewidth=1)

//plot(sma(close,390),color= red, style=line, linewidth=2 )
//plot(sma(close,195), color= green, style=line, linewidth=2)


//Rules for when to plot Numbers 1 or 2 When Profit Target 1 or 2 is Reached
pt1UHit = (high >= highRes2  and high[1] < highRes2 and high[2] < highRes2 and high[2] < highRes2 and high[2] < highRes2 and high[2] < highRes2) and isintraday
pt1LHit = (low <= lowRes2  and low[1] > lowRes2 and low[2] > lowRes2 and low[2] > lowRes2 and low[2] > lowRes2 and low[2] > lowRes2) and low > lowRes3 and isintraday
pt2UHit = (high >= highRes3  and high[1] < highRes3 and high[2] < highRes3 and high[2] < highRes3 and high[2] < highRes3 and high[2] < highRes3) and isintraday
pt2LHit = (low <= lowRes3  and low[1] > lowRes3 and low[2] > lowRes3 and low[2] > lowRes3 and low[2] > lowRes3 and low[2] > lowRes3) and isintraday
pt3UHit = (high >= highRes4  and high[1] < highRes4 and high[2] < highRes4 and high[2] < highRes4 and high[2] < highRes4 and high[2] < highRes4) and isintraday
pt3LHit = (low <= lowRes4  and low[1] > lowRes4 and low[2] > lowRes4 and low[2] > lowRes4 and low[2] > lowRes4 and low[2] > lowRes4) and isintraday




//Rules for plotting 1 or 2 When Profit Target 1 or 2 is Reached
plotchar(snp and pt1UHit ? pt1UHit : na, title='UpSide Profit Target 1 Achieved', char='A',  location=location.abovebar, color=black, transp=0, offset=0)
plotchar(snp and pt1LHit ? pt1LHit : na, title='DownSide Profit Target 1 Achieved', char='A',  location=location.belowbar, color=black, transp=0, offset=0)
plotchar(snp and pt2UHit ? pt2UHit : na, title='UpSide Profit Target 2 Achieved', char='1', location=location.abovebar, color=black, transp=0, offset=0)
plotchar(snp and pt2LHit ? pt2LHit : na, title='DownSide Profit Target 2 Achieved', char='1',  location=location.belowbar, color=black, transp=0, offset=0)
plotchar(snp and pt3UHit ? pt3UHit : na, title='UpSide Profit Target 3 Achieved', char='2', location=location.abovebar, color=black, transp=0, offset=0)
plotchar(snp and pt3LHit ? pt3LHit : na, title='DownSide Profit Target 3 Achieved', char='2',  location=location.belowbar, color=black, transp=0, offset=0)

//// last line