Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- // based on: https://www.tradingview.com/script/BglpAPCp-ranges/
- study("Ranges v2", overlay=true)
- sessNum = input(3, minval=0, maxval=3, title="Session to use")
- session_0 = input("-----", title="0 (local day)")
- session_1 = input("0000-0000", title="1 (24 hours)")
- __Asian_______=input("(2) Asian", title="---------")
- session_2_start = input('1700', type=input.string, title="start")
- // see the strange difference: https://i.imgur.com/8XfrsCW.png
- //because 0200-0100 types doesn't work for some days (like friday to Sunday), because (time('D', '0200-0100') returns na because it cant find the second "ENDTIME" on next day), so we use "backup" sessions
- session_2_end = input('0030', type=input.string, title="END")
- __European_______=input("(3) European", title="---------")
- session_3_start = input('0200', type=input.string, title="start")
- session_3_end = input('0159', type=input.string, title="end")
- //Session Selection Rules
- sessToUse = sessNum == 1 ? session_1 : sessNum == 2 ? session_2_start +"-"+session_2_end : sessNum == 3 ? session_3_start +"-"+session_3_end : "daily_is_chosen"
- sessToUse_end_00= sessNum == 1 ? session_1 : sessNum == 2 ? session_2_start +"-"+"0000" : sessNum == 3 ? session_3_start +"-"+"0000" : "daily_is_chosen"
- res = input('480', type=input.string, title="Length Of Opening Range-Defaults to 540 Minutes (9 Hours) Select Drop Down Box To Change?")
- // ===== FOR TESTING PURPOSES ====== //
- is_newbar(res) => change(time(res)) != 0 ? 1 : 0 //Day depending on your timezone
- show_my_GMT_daystart = input(false)
- plotchar(show_my_GMT_daystart and is_newbar("D") ? low : na, title="my_gmt_daystart", location=location.absolute, char="|", size=size.normal, color=color.orange)
- // ================================= //
- //Session Rules
- sessionStartTime = sessToUse=="daily_is_chosen" ? time('D') : time('D', sessToUse)
- sessionStartTime_00 = sessToUse=="daily_is_chosen" ? time('D') : time('D', sessToUse_end_00)
- newSess(sess)=> (not na(sess) and ( na(sess[1]) or (sess != sess[1]) ) )
- newSession = newSess(sessionStartTime)
- newSession_00 = newSess(sessionStartTime_00)
- realNewSession = newSession or newSession_00
- //only happens mostly 0000-0000 res, from jump from friday to sunday or like that. otherwise, this is normal to be na at 16:00 for 1700 -1900 sessions
- //gappedNewSession= sessNum == 1 ? (na(sessionStartTime) and not na(sessionStartTime[1]) ) : false
- //newSessionFinal = realNewSession or gappedNewSession
- //plotchar( time('D', '0200-0100'), location=location.abovebar, title="Session Start", char="|", size=size.large, color=color.green)
- //plotchar( time('D', '0200-0000'), location=location.belowbar, title="Session Start", char="|", size=size.large, color=color.orange)
- //lastSessionGapped = false
- //lastSessionGapped := realNewSession ? false : gappedNewSession ? true : lastSessionGapped[1]
- //time_current = sessToUse=="daily_is_chosen" ? time(timeframe.period) : time(timeframe.period, sessToUse)
- //sessionStartBar = sessToUse=="daily_is_chosen" ? realNewSession : (not na(time_current) and na(time_current[1]))
- //plotchar(newSession, location=location.belowbar, title="Session Start", char="|", size=size.large, color=color.green)
- adopt(r, s)=> security(syminfo.tickerid, r, s)
- highRes_ = adopt(res, valuewhen(newSession, high, 0) )
- lowRes_ = adopt(res, valuewhen(newSession, low, 0) )
- change_in_Res= highRes_ != highRes_[1] or lowRes_ != lowRes_[1]
- oneSessionCompleted = false
- oneSessionCompleted := realNewSession ? false : ( change_in_Res ? true : oneSessionCompleted[1])
- highRes = 0.0
- highRes := ( not oneSessionCompleted ? na : highRes_)
- lowRes = 0.0
- lowRes := ( not oneSessionCompleted ? na : lowRes_ )
- plot(lowRes_)
- plot(adopt('480', low), color=color.orange)
- show_plot=true
- migrationBar= not na(highRes_) and not na(highRes_[1]) and change_in_Res
- hidePeriod = migrationBar
- //Plot Statements For Opening Range Lines
- openRangeHigh = plot(not show_plot or hidePeriod? na : highRes, color=color.navy, style=plot.style_linebr, linewidth=1)
- openRangeLow = plot(not show_plot or hidePeriod? na : lowRes, color=color.navy, style=plot.style_linebr, linewidth=1)
- fill(openRangeHigh, openRangeLow, color=color.navy, transp=90, title="Opening Range Fill")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement