Advertisement
xmd79

Market Sessions

Nov 23rd, 2023
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.88 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © JVibez
  3.  
  4. //@version=5
  5. indicator("Market Sessions)", overlay = true, max_bars_back = 400, max_boxes_count = 300, max_labels_count = 300, max_lines_count = 54)
  6. import PineCoders/Time/3
  7.  
  8. Yearnow = year(timenow)
  9. Monthnow = month(timenow)
  10. Daynow = dayofmonth(timenow)
  11.  
  12. _timezone = "UTC"
  13.  
  14. // Forex Sessions
  15. Asia_start = timestamp(_timezone, Yearnow, Monthnow,Daynow - 1, 23, 00, 00)
  16. Asia_end = timestamp(_timezone, Yearnow, Monthnow,Daynow, 8, 00, 00)
  17. Euro_start = timestamp(_timezone, Yearnow, Monthnow, Daynow, 08, 00, 00)
  18. Euro_end = timestamp(_timezone, Yearnow, Monthnow, Daynow, 17, 00, 00)
  19. USA_start = timestamp(_timezone, Yearnow, Monthnow, Daynow, 13, 00, 00)
  20. USA_end = timestamp(_timezone, Yearnow, Monthnow, Daynow, 22, 00, 00)
  21. // Stock Sessions
  22. _Asia_start = timestamp(_timezone, Yearnow, Monthnow,Daynow, 00, 00, 00)
  23. _Asia_end = timestamp(_timezone, Yearnow, Monthnow,Daynow, 8, 00, 00)
  24. _Euro_start = timestamp(_timezone, Yearnow, Monthnow,Daynow, 9, 00, 00)
  25. _Euro_end = timestamp(_timezone, Yearnow, Monthnow,Daynow, 17, 30, 00)
  26. _USA_start = timestamp(_timezone, Yearnow, Monthnow,Daynow, 15, 30, 00)
  27. _USA_end = timestamp(_timezone, Yearnow, Monthnow,Daynow, 22, 00, 00)
  28.  
  29. start_day = timestamp(_timezone, Yearnow, Monthnow,Daynow, 00, 00, 00)
  30. end_day = timestamp(_timezone, Yearnow, Monthnow,Daynow, 23, 59, 59)
  31.  
  32. // Get Diffrent Sessions
  33. Asia_sess = time >= Asia_start and time < Asia_end
  34. Euro_sess = time >= Euro_start and time < Euro_end
  35. USA_sess = time >= USA_start and time < USA_end
  36. EuUS_sess = time >= USA_start and time < Euro_end
  37. _Asia_sess = time >= _Asia_start and time < _Asia_end
  38. _Euro_sess = time >= _Euro_start and time < _Euro_end
  39. _USA_sess = time >= _USA_start and time < _USA_end
  40. UsAs_gap = time >= USA_end and time < Asia_start
  41. day_sess = time >= start_day and time < end_day
  42.  
  43. t_mrktsess = "Market Session/Daily HiLO"
  44. t_DLHiLo = "Daily High/Low Inputs"
  45. // Plot Inputs
  46. p_sess = input.bool(true, "Sessions","","1",t_mrktsess)
  47. p_bckgr = input.bool(true, "Background","","1",t_mrktsess)
  48. bcktest = input.bool(false, "Shows Past", "Shows the Past Sessions for Backtest", "1", t_mrktsess) and day_sess == false
  49. //
  50. i_stok = input.string("No Text", "Dashboard Position", ["No Text", "Text"], "", "4", t_mrktsess)
  51. b_stok = input.bool(true, "Stock Open Close","","4",t_mrktsess)
  52. // Dashboard Inputs
  53. i_dashpos = input.string("Top Right", "Dashboard Position", ["Bottom Right", "Bottom Left", "Top Right", "Top Left"], "", "2", t_mrktsess)
  54. draw_testables = input.bool(true,"Dashboard","","2", t_mrktsess)
  55.  
  56. // Daily HiLo Inputs
  57. i_textpos = input.string("Right", "Text Position", ["Right", "Middle", "Left"], "", "3", t_DLHiLo)
  58. p_DHLO = input.bool(true, "Last Day High/Low","","3",t_DLHiLo)
  59. colhigh = input.color(color.rgb(216, 216, 216), "Daily High", "", "3.1", t_DLHiLo)
  60. collow = input.color(color.rgb(216, 216, 216), "Daily Low", "", "3.1", t_DLHiLo)
  61.  
  62. Dhigh = request.security(syminfo.tickerid, "D", high)
  63. Dlow = request.security(syminfo.tickerid, "D", low)
  64.  
  65.  
  66.  
  67.  
  68. ASST_EUFX = "0000-0800:123456"
  69. EUFX_EUST = "0800-0900:123456"
  70. EUST_USFX = "0900-1300:123456"
  71. USFX_USST = "1300-1530:123456"
  72. USST_EUST = "1530-1730:123456"
  73. EUST_USST = "1730-2200:123456"
  74. USAS_gap = "2200-2300:123456"
  75.  
  76. fun_session(session) =>
  77. sess_true = not na(time(timeframe.period, session, "UCT"))
  78. [sess_true]
  79.  
  80. [_ASST_EUFX] = fun_session(ASST_EUFX)
  81. [_EUFX_EUST] = fun_session(EUFX_EUST)
  82. [_EUST_USFX] = fun_session(EUST_USFX)
  83. [_USFX_USST] = fun_session(USFX_USST)
  84. [_USST_EUST] = fun_session(USST_EUST)
  85. [_EUST_USST] = fun_session(EUST_USST)
  86. [_USAS_gap] = fun_session(USAS_gap)
  87.  
  88. // Stock Open
  89. _open = time == _Asia_start or time == _Euro_start or time == _USA_start
  90. _close = time == _Asia_end or time == _Euro_end or time == _USA_end
  91.  
  92. _20EMA = input.int(20, "1 EMA", inline = "1")
  93. _50EMA = input.int(50, "2 EMA", inline = "2")
  94. _200EMA = input.int(200, "3 EMA", inline = "3")
  95.  
  96. _20col = input.color(color.rgb(150, 211, 135), "", inline = "1")
  97. _50col = input.color(color.rgb(221, 156, 119), "", inline = "2")
  98. _200col = input.color(color.rgb(108, 201, 224), "", inline = "3")
  99.  
  100. b20EMA = input.bool(true, "", inline = "1")
  101. b50EMA = input.bool(true, "", inline = "2")
  102. b200EMA = input.bool(true, "", inline = "3")
  103.  
  104. _20_EMA = ta.ema(close, _20EMA)
  105. _50_EMA = ta.ema(close, _50EMA)
  106. _200_EMA = ta.ema(close, _200EMA)
  107.  
  108. frame_sess = timeframe.isminutes and timeframe.multiplier < 61 ? true : false
  109. frame_sess1 = timeframe.isminutes and timeframe.multiplier < 59 ? true : false
  110.  
  111. daysinc = ta.barssince(day_sess[1] == false and day_sess)
  112. asiasinc = ta.barssince(Asia_sess[1] == false and Asia_sess)
  113.  
  114. var label linetxt = na
  115. var label linetxt2 = na
  116.  
  117. _opentrue = false
  118. _closetrue = false
  119.  
  120. txtpos = switch i_textpos
  121. "Right" => bar_index
  122. "Middle" => bar_index - (asiasinc / 2)
  123. "Left" => bar_index - asiasinc
  124. s_stok = switch i_stok
  125. "Text" => true
  126. "No Text" => false
  127.  
  128. if day_sess and barstate.islastconfirmedhistory and p_DHLO
  129. line.new(bar_index - asiasinc, Dhigh, bar_index + 1, Dhigh, color = colhigh)
  130. line.new(bar_index - asiasinc, Dlow, bar_index + 1, Dlow, color = collow)
  131. label.delete(linetxt)
  132. linetxt := label.new(txtpos, Dhigh, text = "Last Day High", textcolor = colhigh, style = label.style_none)
  133. label.delete(linetxt2)
  134. linetxt2 := label.new(txtpos, Dlow, text = "Last Day Low", textcolor = collow, style = label.style_none)
  135.  
  136. if _open and b_stok and frame_sess1 and p_sess
  137. line.new(bar_index, high, bar_index, low, extend = extend.both, color = color.new(#ffffff, 15), style = line.style_dotted
  138. , width = 1)
  139. if _close and b_stok and frame_sess1 and p_sess
  140. line.new(bar_index, high, bar_index, low, extend = extend.both, color = color.new(#706f6f, 0), style = line.style_dotted
  141. , width = 1)
  142.  
  143. if bcktest
  144. if _ASST_EUFX[1] == false and _ASST_EUFX or _EUST_USFX[1] == false and _EUST_USFX or _USST_EUST[1] == false and _USST_EUST and frame_sess1
  145. line.new(bar_index, high, bar_index, low, extend = extend.both, color = color.new(#ffffff, 15), style = line.style_dotted
  146. , width = 1)
  147. _opentrue := true
  148. if _ASST_EUFX[1] and _ASST_EUFX == false or _USST_EUST[1] and _USST_EUST == false or _USAS_gap[1] == false and _USAS_gap and frame_sess1
  149. line.new(bar_index, high, bar_index, low, extend = extend.both, color = color.new(#706f6f, 0), style = line.style_dotted
  150. , width = 1)
  151. _closetrue := true
  152.  
  153. var int pl_hold = na
  154. var int svpl_hold = na
  155. if time == Asia_start
  156. pl_hold := 1
  157. if not na(pl_hold)
  158. pl_hold := pl_hold + 1
  159. if time == _Asia_start
  160. svpl_hold := pl_hold[1] / 2
  161. pl_hold := na
  162. plotshape(_USAS_gap)
  163. plot(b20EMA ? _20_EMA : na, "1 EMA", _20col, display = display.pane)
  164. plot(b50EMA ? _50_EMA : na, "2 EMA", _50col, display = display.pane)
  165. plot(b200EMA ? _200_EMA : na, "3 EMA", _200col, display = display.pane)
  166.  
  167. plot(Dhigh, color=color.new(#bc3a3a, 0), display = display.status_line)
  168. plot(Dlow, color=color.new(#5aa53f, 0), display = display.status_line)
  169.  
  170. d_sess = p_sess ? display.pane : display.data_window
  171. plotshape(frame_sess ? time == Asia_start : na, "Sydney/Tokyo Sesssion", color = na,
  172. text = "Sydney/Tokyo" , location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  173. plotshape(frame_sess ? time == Euro_start : na, "London Sesssion", color = na,
  174. text = "London", location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  175. plotshape(frame_sess ? time == USA_start : na, "NewYork Sesssion", color = na,
  176. text = "NewYork", location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  177.  
  178. plotshape(frame_sess1 and s_stok ? time == _Asia_start : na, "Open Stock Asia", color = na, offset = svpl_hold,
  179. text = "Open" , location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  180. plotshape(frame_sess1 and s_stok ? time == _Euro_start : na, "Open Stock Euro", color = na, offset = svpl_hold,
  181. text = "Open", location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  182. plotshape(frame_sess1 and s_stok ? time == _USA_start : na, "Open Stock USA", color = na, offset = svpl_hold,
  183. text = "Open", location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  184.  
  185. plotshape(frame_sess1 and s_stok ? time == _Asia_end : na, "Close Stock Asia", color = na, offset = -svpl_hold,
  186. text = "Close" , location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  187. plotshape(frame_sess1 and s_stok ? time == _Euro_end : na, "Close Stock Euro", color = na, offset = -svpl_hold,
  188. text = "Close", location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  189. plotshape(frame_sess1 and s_stok ? time == _USA_end : na, "Close Stock USA", color = na, offset = -svpl_hold,
  190. text = "Close", location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  191.  
  192. plotshape(frame_sess ? time >= Asia_start and time < _Asia_start : na, "Asia Forex to Asia Stock", shape.square, location.bottom,
  193. color.rgb(156, 237, 35, 55), display = d_sess)
  194. plotshape(frame_sess ? time >= _Asia_start and time < Euro_start : na, "Asia Stock to Euro Forex", shape.square, location.bottom,
  195. color.rgb(244, 236, 0, 55), display = d_sess)
  196. plotshape(frame_sess ? time >= Euro_start and time < _Euro_start : na, "Euro Forex To Euro Stock", shape.square, location.bottom,
  197. color.rgb(255, 191, 0, 55), display = d_sess)
  198. plotshape(frame_sess ? time >= _Euro_start and time < USA_start : na, "Euro Stock to USA Forex", shape.square, location.bottom,
  199. color.rgb(255, 140, 0, 55), display = d_sess)
  200. plotshape(frame_sess ? time >= USA_start and time < _USA_start : na, "USA Forex to USA Stock", shape.square, location.bottom,
  201. color.rgb(230, 87, 4, 55), display = d_sess)
  202. plotshape(frame_sess ? time >= _USA_start and time < _Euro_end : na, "USA Forex to Euro Stock", shape.square, location.bottom,
  203. color.rgb(255, 0, 0, 55), display = d_sess)
  204. plotshape(frame_sess ? time >= _Euro_end and time < _USA_end : na, "Euro Stock to USA Stock", shape.square, location.bottom,
  205. color.rgb(236, 63, 5, 55), display = d_sess)
  206.  
  207. plotshape(Asia_sess, "Asia Session", display = display.data_window)
  208. plotshape(Euro_sess, "Euro Session", display = display.data_window)
  209. plotshape(USA_sess, "USA Session", display = display.data_window)
  210.  
  211. bgcolor(frame_sess and p_sess and _USAS_gap ? color.rgb(255, 255, 255, 95) : na)
  212. bgcolor(frame_sess and p_sess and p_bckgr and Asia_sess ? color.rgb(255, 255, 255, 98) : na)
  213. bgcolor(frame_sess and p_sess and p_bckgr and (Euro_sess or _Euro_sess) ? color.rgb(255, 255, 255, 97) : na)
  214. bgcolor(frame_sess and p_sess and p_bckgr and USA_sess ? color.rgb(255, 255, 255, 98) : na)
  215.  
  216. plotshape(frame_sess1 and bcktest and _opentrue, "Open Stock Asia", color = na, offset = svpl_hold,
  217. text = "Open" , location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  218. plotshape(frame_sess1 and bcktest and _closetrue, "Close Stock Asia", color = na, offset = -svpl_hold,
  219. text = "Close" , location = location.top, textcolor = color.rgb(255, 255, 255, 24), display = d_sess)
  220.  
  221.  
  222. plotshape(bcktest ? _ASST_EUFX[1] == false and _ASST_EUFX : na, "Sydney/Tokyo Sesssion", color = na,
  223. text = "Sydney/Tokyo" , location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = display.pane, show_last = 900)
  224. plotshape(bcktest ? _EUFX_EUST[1] == false and _EUFX_EUST : na, "London Sesssion", color = na,
  225. text = "London", location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = display.pane, show_last = 900)
  226. plotshape(bcktest ? _USST_EUST[1] == false and _USST_EUST : na, "NewYork Sesssion", color = na,
  227. text = "NewYork", location = location.bottom, textcolor = color.rgb(255, 255, 255, 24), display = display.pane, show_last = 900)
  228.  
  229. plotshape(bcktest ? _ASST_EUFX : na, "Asia Stock to Euro Forex", shape.square, location.bottom,
  230. color.rgb(244, 236, 0, 55), display = display.pane, show_last = 900)
  231. plotshape(bcktest ?_EUFX_EUST : na, "Euro Forex To Euro Stock", shape.square, location.bottom,
  232. color.rgb(255, 191, 0, 55), display = display.pane, show_last = 900)
  233. plotshape(bcktest ? _EUST_USFX : na, "Euro Stock to USA Forex", shape.square, location.bottom,
  234. color.rgb(255, 140, 0, 55), display = display.pane, show_last = 900)
  235. plotshape(bcktest ? _USFX_USST : na, "USA Forex to USA Stock", shape.square, location.bottom,
  236. color.rgb(230, 87, 4, 55), display = display.pane, show_last = 900)
  237. plotshape(bcktest ? _USST_EUST : na, "USA Forex to Euro Stock", shape.square, location.bottom,
  238. color.rgb(255, 0, 0, 55), display = display.pane, show_last = 900)
  239. plotshape(bcktest ? _EUST_USST : na, "Euro Stock to USA Stock", shape.square, location.bottom,
  240. color.rgb(236, 63, 5, 55), display = display.pane, show_last = 900)
  241.  
  242. bgcolor(bcktest and _USAS_gap ? color.rgb(255, 255, 255, 95) : na)
  243.  
  244. fun_filltaCell(_table,_column,_row,_title,_value,_textpos,_bgcolor,_textcolor) => // Get Sell Function
  245. _celltext = _title + _value
  246. table.cell(_table,_column,_row,_celltext,text_halign=_textpos,bgcolor = _bgcolor,text_color = _textcolor)
  247. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  248. // prepare stats Tables
  249. tablespos = switch i_dashpos
  250. "Bottom Right" => position.bottom_right
  251. "Bottom Left" => position.bottom_left
  252. "Top Right" => position.top_right
  253. "Top Left" => position.top_left
  254. => position.top_right
  255.  
  256. var tradetable = table.new(tablespos,2,15,color.new(#166aaf, 100),color.new(#49464d, 100),4,color.new(#49464d, 100),4)
  257. // Color Variables For Tables
  258. // raw Stats Tables
  259. if draw_testables
  260. if barstate.islastconfirmedhistory
  261. // Update Tables
  262. fun_filltaCell(tradetable,0,0, "Current Session","",text.align_center,color.new(#3497e8, 80),color.new(#f1f1f1, 0))
  263. fun_filltaCell(tradetable,1,0, Asia_sess ? "Sydney/Tokyo" : time >= Euro_start and time < USA_start ? "London" :
  264. time >= USA_start and time < _Euro_end ? "London/NewYork" :
  265. time >= _Euro_end and time < _USA_end ? "NewYork" : _USAS_gap ? "Low Volume Zone" : na, "",text.align_center,
  266. Asia_sess or Euro_sess or USA_sess ? color.new(#20adc0, 80) : _USAS_gap ? color.rgb(195, 195, 195, 64) :
  267. color.new(#20adc0, 80) ,color.new(#f1f1f1, 0))
  268.  
  269. fun_filltaCell(tradetable,0,1,"Next Session","",text.align_center,color.new(#3497e8, 80),color.new(#f1f1f1, 0))
  270. fun_filltaCell(tradetable,1,1, Asia_sess ? "London" : Euro_sess and not USA_sess ? "NewYork" : Euro_sess or _Euro_sess and USA_sess ? "Low Volume Zone" :
  271. USA_sess ? "Low Volume Zone" : _USAS_gap ? "Sydney/Tokyo" : na,"",text.align_center,color.new(#20adc0, 80),color.new(#f1f1f1, 0))
  272.  
  273. fun_filltaCell(tradetable,0,2,"Session Start in","",text.align_center,color.new(#3497e8, 80),color.new(#f1f1f1, 0))
  274. fun_filltaCell(tradetable,1,2, str.format_time(Asia_sess ? Euro_start - timenow : Euro_sess and not USA_sess ? USA_start - timenow :
  275. Euro_sess and (USA_sess or _USA_sess) ? USA_end - timenow : _USAS_gap ? Asia_start - timenow : na,
  276. "HH:mm ", _timezone),"",text.align_center,color.new(#20adc0, 80),color.new(#f1f1f1, 0))
  277. // fun_filltaCell(tradetable,1,3, str.format_time(week_sess, "dd:MM:yyyy", _timezone),"",text.align_center,color.new(#20adc0, 80),color.new(#f1f1f1, 0))
  278.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement