SHARE
TWEET

older-v1-session-openingrange

selnomeria Sep 18th, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. // based on: https://www.tradingview.com/script/BglpAPCp-ranges/
  3. study("Ranges v2", overlay=true)
  4.  
  5. sessNum   = input(3, minval=0, maxval=3, title="Session to use")
  6. session_0 = input("-----", title="0 (local day)")
  7. session_1 = input("0000-0000", title="1 (24 hours)")
  8. __Asian_______=input("(2) Asian", title="---------")
  9. session_2_start = input('1700', type=input.string, title="start")
  10. // see the strange difference: https://i.imgur.com/8XfrsCW.png
  11. //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
  12. session_2_end = input('0030', type=input.string, title="END")
  13. __European_______=input("(3) European", title="---------")
  14. session_3_start = input('0200', type=input.string, title="start")
  15. session_3_end = input('0159', type=input.string, title="end")
  16. //Session Selection Rules
  17. sessToUse   = sessNum == 1 ? session_1 : sessNum == 2 ? session_2_start +"-"+session_2_end  : sessNum == 3 ? session_3_start +"-"+session_3_end : "daily_is_chosen"
  18. sessToUse_end_00= sessNum == 1 ? session_1 : sessNum == 2 ? session_2_start +"-"+"0000"         : sessNum == 3 ? session_3_start +"-"+"0000"        : "daily_is_chosen"
  19.  
  20. res = input('480', type=input.string, title="Length Of Opening Range-Defaults to 540 Minutes (9 Hours) Select Drop Down Box To Change?")
  21.  
  22. // ===== FOR TESTING PURPOSES ====== //
  23. is_newbar(res) => change(time(res)) != 0 ? 1 : 0 //Day depending on your timezone
  24. show_my_GMT_daystart = input(false)
  25. 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)
  26. // ================================= //
  27.  
  28. //Session Rules
  29. sessionStartTime    = sessToUse=="daily_is_chosen" ? time('D') : time('D', sessToUse)
  30. sessionStartTime_00 = sessToUse=="daily_is_chosen" ? time('D') : time('D', sessToUse_end_00)
  31.  
  32. newSess(sess)=> (not na(sess) and ( na(sess[1]) or (sess != sess[1]) )  )
  33. newSession     = newSess(sessionStartTime)
  34. newSession_00  = newSess(sessionStartTime_00)
  35. realNewSession = newSession or newSession_00
  36. //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
  37. //gappedNewSession= sessNum == 1 ? (na(sessionStartTime) and not na(sessionStartTime[1]) ) : false
  38. //newSessionFinal      = realNewSession or gappedNewSession
  39. //plotchar( time('D', '0200-0100'),  location=location.abovebar, title="Session Start", char="|", size=size.large, color=color.green)
  40. //plotchar( time('D', '0200-0000'),  location=location.belowbar, title="Session Start", char="|", size=size.large, color=color.orange)
  41. //lastSessionGapped = false
  42. //lastSessionGapped := realNewSession ? false : gappedNewSession ? true :  lastSessionGapped[1]
  43. //time_current    = sessToUse=="daily_is_chosen" ? time(timeframe.period) : time(timeframe.period, sessToUse)
  44. //sessionStartBar = sessToUse=="daily_is_chosen" ? realNewSession : (not na(time_current) and na(time_current[1]))
  45. //plotchar(newSession,  location=location.belowbar, title="Session Start", char="|", size=size.large, color=color.green)
  46. adopt(r, s)=> security(syminfo.tickerid, r, s)
  47.  
  48. highRes_ = adopt(res, valuewhen(newSession, high, 0)  )
  49. lowRes_  = adopt(res, valuewhen(newSession, low, 0) )
  50. change_in_Res= highRes_ != highRes_[1]   or  lowRes_ != lowRes_[1]
  51. oneSessionCompleted = false
  52. oneSessionCompleted := realNewSession ? false : ( change_in_Res ? true : oneSessionCompleted[1])
  53. highRes = 0.0
  54. highRes := ( not oneSessionCompleted ? na : highRes_)
  55. lowRes  = 0.0
  56. lowRes  := ( not oneSessionCompleted ? na : lowRes_ )
  57.  
  58. plot(lowRes_)
  59. plot(adopt('480', low), color=color.orange)
  60.  
  61. show_plot=true
  62. migrationBar= not na(highRes_) and not na(highRes_[1]) and change_in_Res
  63. hidePeriod = migrationBar
  64. //Plot Statements For Opening Range Lines
  65. openRangeHigh = plot(not show_plot or hidePeriod? na : highRes, color=color.navy, style=plot.style_linebr, linewidth=1)
  66. openRangeLow  = plot(not show_plot or hidePeriod? na : lowRes,  color=color.navy, style=plot.style_linebr, linewidth=1)
  67. fill(openRangeHigh, openRangeLow, color=color.navy, transp=90, title="Opening Range Fill")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top