jayy

forex session - Opening-Range- Jayy

My first try on anything forex. Let me know if it needs adjustment.
This is Opening Range for forex
Targets set at 127% , 162%, 200 %, 262 %, 362%, 423%, 685%, 1109% and 1794%
of the selected opening range. You can adjust targets as you like in the dialogue box
362%, 423%, 685%, 1109% and 1794% levels will not show unless selected in the dialogue box.
Check any one (only one) of the time periods to change the opening range period to suit.
New York opens at 8:00 am to 5:00 pm EST (EDT)
Tokyo opens at 7:00 pm to 4:00 am EST (EDT)
Sydney opens at 5:00 pm to 2:00 am EST (EDT)
London opens at 3:00 am to 12:00 noon EST (EDT)
Because the actual forex day starts at 5pm it is not possible to plot some time periods correctly
ie try 120 minutes on the New York session. (Although this is not a problem with the other sessions)
If you keep to an hour or less and use periods that divide evenly into an hour all will be fine. All periods will actually work but will start looking a little funny.
No such problem occurs if you just use 5pm est to 5 pm est. other sessions could be put in as options or hard wired in with a few lines of script changes
There is an option in the dialogue box to display fib targets within Opening Range itself.
In the far past I adapted some original work created by Chris Moody from a 7-07-2014 script - there have been multiple adaptations . The script layout/ structure remains similar and messages regarding targets achieved (lines 224 - 230) are from the original script. In the original Chris gave Special Thanks To "The Coding Genius Behind The Curtain" - so hat tip to both.

Jayy
オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?
// My first try on anything forex.  Let me know if it needs adjustment.
//  This is Opening Range for forex 
// Targets set at 127% , 162%, 200 %, 262 %, 362%, 423%, 685%, 1109% and 1794% 
// of the selected opening range.  You can adjust targets as you like in the dialogue box
//
// 362%, 423%, 685%, 1109% and 1794% will not show unless selected in the dialogue box.
// Check any one (only one) of the time periods to change the opening range period to suit.
// New York opens at 8:00 am to 5:00 pm EST (EDT)
// Tokyo opens at 7:00 pm to 4:00 am EST (EDT)
// Sydney opens at 5:00 pm to 2:00 am EST (EDT)
// London opens at 3:00 am to 12:00 noon EST (EDT)
// Because the actual forex day starts at 5pm it is not possible to plot some time periods correctly
// 
// ie try 120 minutes on the New York session. (Although this is not a problem with the other sessions)
//  If you keep to an hour or less and use periods that divide evenly into an hour all will be fine.
//All periods will actually work but will start looking a little funny.
// No such problem occurs if you just use 5pm est to 5 pm est.
// other sessions could be put in as options or hard wired in with a few lines of script changes
// There is an option in the dialogue box to display fib targets within Opening Range itself
//In the far past I adapted some original work created by ChrisMoody from a 7-07-2014 script - there have been multiple adaptations 
// the structure remains and messages regarding targets acheived (lines 224 - 230)
//In the original script Chris gave Special Thanks To "The Coding Genius Behind The Curtain"

study(title="forex session -  Opening-Range- Jayy", shorttitle="forex OR -Jayy", overlay=true)

sesstny= input(false, title= "Check for New York 8:00 am to 5:00 pm EST (EDT) session?")
sesstAUD= input(false, title= "Check for Sydney 5:00 pm to 2:00 am EST (EDT) session?")
sesstTokyo= input(false, title= "Check for Tokyo 7:00 pm to 4:00 am EST (EDT) session?")
sesstLondon= input(false, title= "Check for London 3:00 am to 12:00 noon EST (EDT) session?")
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('60', 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("1700-1700", type=session, title= "plot session")
highTimeFrame = input("D", type=resolution)
//sessSpec = input("930-1600", type=session)


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

ny= "801-1859"
a= "1701-400"
t= "1901-500"
l= "301-1400"
y="1701-1700"
plt=sesstny?ny:sesstAUD?a:sesstTokyo?t:sesstLondon?l :y
nyi= "800-1700"
ai= "1700-400"
ti= "1900-500"
li= "300-1300"
yi="1700-1700"
sessSpec=sesstny?nyi:sesstAUD?ai:sesstTokyo?ti:sesstLondon?li :yi
// xbg= "800-1330"

ri=sesstny?nyi:sesstAUD?ai:sesstTokyo?ti:sesstLondon?li : r

bartimeSess =  time('D', ri) 
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=90, 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