Advertisement
xmd79

DR/IDR of Omega

Jan 15th, 2023
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.75 KB | None | 0 0
  1. //@version=5
  2. indicator('DR/IDR of Omega', overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
  3. import PineCoders/VisibleChart/4 as PCchart
  4.  
  5. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  6. // © TheMas7er and bmistiaen and TRSTNGLRD
  7.  
  8. // Input options
  9. // {
  10. LS0='Solid', LS1='Dashed', LS2='Dotted'
  11. BX0='DR', BX1='IDR'
  12. XL0='Follow Time', XL1='Session End', XL2='ADR End', XL3='ODR End', XL4='RDR End'
  13. STDLT0='Dynamic',STDLT1='Static'
  14. // } Input options
  15.  
  16. TIMEZONE = 'America/New_York'
  17. ONE_HOUR = 3600*1000
  18. ONE_DAY = 24*ONE_HOUR
  19.  
  20. // Inputs
  21. // {
  22. var GRP1 = "Time Settings"
  23. //timings
  24. exchangeOffset = input.int(0,"Exchange Offset (hours)", group=GRP1)
  25. Omega2v1Time = input.session('0430-0935', 'Omega2v1 Time', group=GRP1)
  26. Omega2v1Extend = input.session('0935-1600', 'Omega2v1 Lines Time', group=GRP1)
  27. Omega4v1Time = input.session('0930-1030', 'Omega4v1 Time', group=GRP1)
  28. Omega4v1Extend = input.session('1030-1600', 'Omega4v1 Lines Time', group=GRP1)
  29. Omega4v2Time = input.session('1930-2030', 'Omega4v2 Time', group=GRP1)
  30. Omega4v2Extend = input.session('2030-0200', 'Omega4v2 Lines Time', group=GRP1)
  31. Omega8v1Time = input.session('0300-0400', 'Omega8v1 Time', group=GRP1)
  32. Omega8v1Extend = input.session('0400-0830', 'Omega8v1 Lines Time', group=GRP1)
  33. Omega8v2Time = input.session('2130-2235', 'Omega8v2 Time', group=GRP1)
  34. Omega8v2Extend = input.session('2235-0245', 'Omega8v2 Lines Time', group=GRP1)
  35. Omega8v3Time = input.session('1130-1235', 'Omega8v3 Time', group=GRP1)
  36. Omega8v3Extend = input.session('1235-1645', 'Omega8v3 Lines Time', group=GRP1)
  37. Omega16v1Time = input.session('1845-1935', 'Omega16v1 Time', group=GRP1)
  38. Omega16v1Extend = input.session('1935-2115', 'Omega16v1 Lines Time', group=GRP1)
  39. Omega16v2Time = input.session('2130-2220', 'Omega16v2 Time', group=GRP1)
  40. Omega16v2Extend = input.session('2220-0000', 'Omega16v2 Lines Time', group=GRP1)
  41. Omega16v3Time = input.session('0015-0105', 'Omega16v3 Time', group=GRP1)
  42. Omega16v3Extend = input.session('0105-0245', 'Omega16v3 Lines Time', group=GRP1)
  43. Omega16v4Time = input.session('0300-0350', 'Omega16v4 Time', group=GRP1)
  44. Omega16v4Extend = input.session('0350-0545', 'Omega16v4 Lines Time', group=GRP1)
  45. Omega16v5Time = input.session('0600-0650', 'Omega16v5 Time', group=GRP1)
  46. Omega16v5Extend = input.session('0650-0815', 'Omega16v5 Lines Time', group=GRP1)
  47. Omega16v6Time = input.session('0845-0935', 'Omega16v6 Time', group=GRP1)
  48. Omega16v6Extend = input.session('0935-1115', 'Omega16v6 Lines Time', group=GRP1)
  49. Omega16v7Time = input.session('1130-1220', 'Omega16v7 Time', group=GRP1)
  50. Omega16v7Extend = input.session('1220-1400', 'Omega16v7 Lines Time', group=GRP1)
  51. Omega16v8Time = input.session('1415-1505', 'Omega16v8 Time', group=GRP1)
  52. Omega16v8Extend = input.session('1505-1645', 'Omega16v8 Lines Time', group=GRP1)
  53.  
  54. var GRP2 = "General Settings"
  55. //lines
  56. showOmega2v1 = input.bool(true, 'Omega2v1', group=GRP2, inline='session')
  57. showOmega4v1 = input.bool(true, 'Omega4v1', group=GRP2, inline='session')
  58. showOmega4v2 = input.bool(true, 'Omega4v2', group=GRP2, inline='session')
  59. showOmega8v1 = input.bool(true, 'Omega8v1', group=GRP2, inline='session')
  60. showOmega8v2 = input.bool(true, 'Omega8v2', group=GRP2, inline='session')
  61. showOmega8v3 = input.bool(true, 'Omega8v3', group=GRP2, inline='session')
  62. showOmega16v1 = input.bool(true, 'Omega16v1', group=GRP2, inline='session')
  63. showOmega16v2 = input.bool(true, 'Omega16v2', group=GRP2, inline='session')
  64. showOmega16v3 = input.bool(true, 'Omega16v3', group=GRP2, inline='session')
  65. showOmega16v4 = input.bool(true, 'Omega16v4', group=GRP2, inline='session')
  66. showOmega16v5 = input.bool(true, 'Omega16v5', group=GRP2, inline='session')
  67. showOmega16v6 = input.bool(true, 'Omega16v6', group=GRP2, inline='session')
  68. showOmega16v7 = input.bool(true, 'Omega16v7', group=GRP2, inline='session')
  69. showOmega16v8 = input.bool(true, 'Omega16v8', group=GRP2, inline='session')
  70. drlines = input.bool(true, 'Show DR Lines ?', group=GRP2)
  71. idrlines = input.bool(true, 'Show IDR Lines ?', group=GRP2)
  72. middledrline = input.bool(false, 'Show Middle DR Line ?', group=GRP2)
  73. middleidrline = input.bool(true, 'Show Middle IDR Line ?', group=GRP2)
  74. openline = input.bool(true, 'Show Opening Line ?', group=GRP2, inline='openline', tooltip='Shows the Opening line of the Defining Range.\n- Extend: Extends the drawing of the Opening line into the RDR/ODR Lines Time.')
  75. extendopLines = input.bool(true, 'Extend', group=GRP2, inline='openline') // Extend, follow price
  76. extendopLinesType = input.string(XL1, '', options=[XL0,XL1,XL2,XL3,XL4], group=GRP2, inline='openline')
  77. showBackground = input.bool(true, 'Show DR/IDR Box ?', group=GRP2)
  78. boxType = input.string(BX1, 'Box DR or IDR ?', options=[BX0,BX1], group=GRP2)
  79. extenddrLines = input.bool(true, 'Extend DR Lines ?', group=GRP2)
  80. extendidrLines = input.bool(true, 'Extend IDR Lines ?', group=GRP2)
  81. showAllHistory = input.bool(false, 'Show complete history ?', 'Might cause a slight drawing delay when panning/moving/zooming the chart.', group=GRP2)
  82. useBoxColors = input.bool(false, 'Box color based on open and close', 'If unchecked, it will default to the selected Box Background Color', group=GRP2)
  83. extendToEndOfRDR = input.bool(false, 'Extend lines of all ranges to end of most recent Regular session?', group=GRP2)
  84. showStdLines = input.bool(true, 'Show STD Lines ?', group=GRP2, inline='stdlines', tooltip='Shows the Standard Deviation lines in 0.5 IDR range increments.\n- All = Shows all the STD lines on previous sessions.\n- Labels = Show STD level labels.\n- Dropdown = Choose between Dynamic or Static STD lines.')
  85. showStdLinesAll = input.bool(true, 'All', group=GRP2, inline='stdlines')
  86. showStdLineLabels = input.bool(true, 'Labels', group=GRP2, inline='stdlines')
  87. stdLineType = input.string(STDLT1, '', [STDLT0,STDLT1], group=GRP2, inline='stdlines')
  88. stdLineDynamicExtraPos = input.int(0, 'Dynamic (+)', minval=0, group=GRP2, inline='stdlinedynamic', tooltip='Dynamic STD Lines.\nDynamically draw STD lines around price action. Progresses with price.\n- (+) = Number of positive extra levels to draw in addition to the lines that are automatically drawn around price action.\n- (-) = Number of negative extra levels to draw in addition to the lines that are automatically drawn around price action.\n- Auto = Automatically determine number of STD lines that need to be drawn. Follows price action.')
  89. stdLineDynamicExtraNeg = input.int(0, '(-)', minval=0, group=GRP2, inline='stdlinedynamic')
  90. stdLineDynamicExtraAuto = input.bool(false, 'Auto', group=GRP2, inline='stdlinedynamic')
  91. stdLineStaticExtraPos = input.int(10, 'Static (+)', minval=0, group=GRP2, inline='stdlinestatic', tooltip='Static STD Lines.\nDraws a fixed number of STD lines.\n- (+) = Number of positive levels to draw.\n- (-) = Number of negative levels to draw.')
  92. stdLineStaticExtraNeg = input.int(10, '(-)', minval=0, group=GRP2, inline='stdlinestatic')
  93.  
  94.  
  95. var GRP3 = "Styles"
  96. linesWidth = input.int(1, 'Box And Lines Width ?', minval=1, maxval=4, group=GRP3)
  97. drLineColor = input.color(#9b8269, 'DR Line Color', group=GRP3, inline='drline')
  98. drLineStyle = input.string(LS0, 'Style', options=[LS0,LS1,LS2], group=GRP3, inline='drline')
  99. idrLineColor = input.color(#9b8269, 'IDR Line Color', group=GRP3, inline='idrline')
  100. idrLineStyle = input.string(LS1, 'Style', options=[LS0,LS1,LS2], group=GRP3, inline='idrline')
  101. middleLineColor = input.color(#d3d2d0, 'Middle Line Color', group=GRP3, inline='midline')
  102. middleLineStyle = input.string(LS2, 'Style', options=[LS0,LS1,LS2], group=GRP3, inline='midline')
  103. opLineColor = input.color(#33658a, 'Opening Line', group=GRP3, inline='openline', tooltip='Opening line:\n- Color\n- Style\n- Width')
  104. opLineStyle = input.string(LS2, '', options=[LS0,LS1,LS2], group=GRP3, inline='openline')
  105. stdLineColor = input.color(#d3d2d0, 'STD Lines', group=GRP3, inline='stdline', tooltip='Standard deviation lines:\n- Color\n- Style\n- Width')
  106. stdLineStyle = input.string(LS2, '', options=[LS0,LS1,LS2], group=GRP3, inline='stdline')
  107. backgroundColor = input.color(color.new(color.gray, 75), 'Box Background Color', group=GRP3)
  108. boxBorderSize = input.int(0, title="Box border size", minval=0, group=GRP3)
  109. upBoxColor = input.color(color.new(color.green, 85), 'Up box', group=GRP3, inline='upbox')
  110. upBorderColor = input.color(color.green, 'border', group=GRP3, inline='upbox')
  111. downBoxColor = input.color(color.new(color.red, 85), 'Down box', group=GRP3, inline='downbox')
  112. downBorderColor = input.color(color.red, 'border', group=GRP3, inline='downbox')
  113. // } Inputs
  114.  
  115.  
  116. // Constants
  117. // {
  118. exchangeOffsetMS = exchangeOffset * 3600000
  119. // } Constants
  120.  
  121.  
  122. // Variables {
  123. var int startTime = na
  124. var int endTime = na
  125. var string currentSession = na
  126.  
  127. var line lowrdrl = na
  128. var line highrdrl = na
  129. var line lowridrl = na
  130. var line highridrl = na
  131. var line leftrdrl = na
  132. var line rightrdrl = na
  133. var line middlerdrl = na
  134. var line middleridrl = na
  135. var line drLineOpen = na
  136. var box bgBox = na
  137.  
  138. var line[] stdLines = array.new<line>()
  139. var float[] stdLevels = array.new<float>()
  140. var label[] stdLabels = array.new<label>()
  141.  
  142. var float rdrlow = na
  143. var float rdrhigh = na
  144. var float ridrlow = na
  145. var float ridrhigh = na
  146. var float rdrmiddle = na
  147. var float ridrmiddle = na
  148. var float sessionOpen = na
  149.  
  150. var float regidrlow = na
  151. var float regidrhigh = na
  152. var float sessionHigh = na
  153. var float sessionLow = na
  154. var int stdLinesStartTime = na
  155. var int stdLinesStopTime = na
  156.  
  157. var bool use_m5 = false
  158. // } Variables
  159.  
  160.  
  161. // Functions {
  162. f_insession(_session) =>
  163. not na(time(timeframe.period, _session, TIMEZONE))
  164.  
  165. f_timestrToHM(_timeStr) =>
  166. var int hourInt = na
  167. var int minuteInt = na
  168. if str.length(_timeStr) == 4
  169. hourInt := int(str.tonumber(str.substring(_timeStr, 0, 2)))
  170. minuteInt := int(str.tonumber(str.substring(_timeStr, 2, 4)))
  171. [hourInt, minuteInt]
  172.  
  173. f_sessionTime(_session, _timezone=syminfo.timezone, _part) =>
  174. var int ts = na
  175. if str.length(_session) == 9 and (_part == 0 or _part == 1)
  176. arraySessionSplit = str.split(_session, '-')
  177. timeStrTo = array.get(arraySessionSplit, _part)
  178. [hourTo, minuteTo] = f_timestrToHM(timeStrTo)
  179. ts := timestamp(_timezone, year, month, dayofmonth, hourTo, minuteTo)
  180. ts
  181.  
  182. f_sessionStartTime(_session, _timezone=syminfo.timezone) => f_sessionTime(_session, _timezone, 0)
  183. f_sessionStopTime(_session, _timezone=syminfo.timezone) => f_sessionTime(_session, _timezone, 1)
  184. f_timestamp_to_date(int _ts = na, string _tz = na) => timestamp(_tz, year(_ts, _tz), month(_ts, _tz), dayofmonth(_ts, _tz))
  185.  
  186. f_lineStyle(_inputOption) =>
  187. switch(_inputOption)
  188. LS0 => line.style_solid
  189. LS1 => line.style_dashed
  190. LS2 => line.style_dotted
  191. => line.style_solid
  192.  
  193. f_newline(_color, _style) => line.new(na, na, na, na, xloc=xloc.bar_time, color=_color, style=_style, width=linesWidth)
  194. f_newdrline() => f_newline(drLineColor, f_lineStyle(drLineStyle))
  195. f_newidrline() => f_newline(idrLineColor, f_lineStyle(idrLineStyle))
  196. f_newmdline() => f_newline(middleLineColor, f_lineStyle(middleLineStyle))
  197. f_newopline() => f_newline(opLineColor, f_lineStyle(opLineStyle))
  198. f_newstdine() => f_newline(stdLineColor, f_lineStyle(stdLineStyle))
  199.  
  200.  
  201. f_newbox() => box.new(na, na, na, na, xloc=xloc.bar_time, bgcolor=backgroundColor, border_width=boxBorderSize)
  202.  
  203. f_moveLine(_line, _x1, _y, _x2) => line.set_xy1(_line, _x1 + exchangeOffsetMS, _y), line.set_xy2(_line, _x2 + exchangeOffsetMS, _y), _line
  204.  
  205. f_movebox(_box, _left, _top, _right, _bottom, _bordercolor, _bgcolor) => box.set_lefttop(_box, _left + exchangeOffsetMS, _top), box.set_rightbottom(_box, _right + exchangeOffsetMS, _bottom), box.set_border_color(_box, _bordercolor), box.set_bgcolor(_box, _bgcolor)
  206.  
  207. f_newLabel() => label.new(na, na, '', xloc = xloc.bar_time, yloc=yloc.price, style=label.style_label_left, color=color(na), textcolor=stdLineColor)
  208. f_moveLabel(_label, _x, _y, _text) =>
  209. label.set_xy(_label, _x, _y)
  210. label.set_text(_label, _text)
  211. _label
  212.  
  213. f_drawStdLine(_fromTime, _toTime, _level, float _stdLabelValue=na) =>
  214. if not na(_level)
  215. if not array.includes(stdLevels, _level)
  216. array.push(stdLevels, _level)
  217. array.push(stdLines, f_moveLine(f_newstdine(), _fromTime, _level, _toTime))
  218. if showStdLineLabels
  219. array.push(stdLabels, f_moveLabel(f_newLabel(), _toTime, _level, str.format('{0}',_stdLabelValue)))
  220.  
  221.  
  222. f_drawStdLines(_fromTime, _toTime, bool _clear = false) =>
  223. var float stdStepFactor = 0.5
  224. var float stdStep = na
  225. var float stdLevel = na
  226. var float stdLabelValue = na
  227. var int nrLevels = na
  228. var int nrLevelsPos = na
  229. var int nrLevelsNeg = na
  230.  
  231. if _clear and not showStdLinesAll and array.size(stdLevels) > 0
  232. // If we don't need to show all the lines, delete them each time we clear. If we do need to show all the previous lines, don't delete them.
  233. for tmpIndex = 0 to array.size(stdLines)-1
  234. line.delete(array.get(stdLines, tmpIndex))
  235. if showStdLineLabels
  236. label.delete(array.get(stdLabels, tmpIndex))
  237.  
  238. if _clear
  239. array.clear(stdLevels)
  240. array.clear(stdLines)
  241. if showStdLineLabels
  242. array.clear(stdLabels)
  243.  
  244. stdStep := math.abs(regidrhigh-regidrlow) * stdStepFactor
  245.  
  246. if stdStep != 0
  247.  
  248. switch stdLineType
  249. STDLT0 =>
  250. nrLevelsPos := math.ceil(math.max(sessionHigh - regidrhigh, 0) / stdStep) + (stdLineDynamicExtraAuto ? 0 : stdLineDynamicExtraPos)
  251. nrLevelsNeg := math.ceil(math.max(regidrlow - sessionLow, 0) / stdStep) + (stdLineDynamicExtraAuto ? 0 : stdLineDynamicExtraNeg)
  252. STDLT1 =>
  253. nrLevelsPos := stdLineStaticExtraPos
  254. nrLevelsNeg := stdLineStaticExtraNeg
  255.  
  256. // Positive lines
  257. if nrLevelsPos >= 1
  258. for cnt = 1 to nrLevelsPos
  259. stdLevel := regidrhigh + (cnt * stdStep)
  260. stdLabelValue := cnt * stdStepFactor
  261. f_drawStdLine(_fromTime, _toTime, stdLevel, stdLabelValue)
  262.  
  263. // Negative lines
  264. if nrLevelsNeg >= 1
  265. for cnt = 1 to nrLevelsNeg
  266. stdLevel := regidrlow - (cnt * stdStep)
  267. stdLabelValue := cnt * (-stdStepFactor)
  268. f_drawStdLine(_fromTime, _toTime, stdLevel, stdLabelValue)
  269.  
  270. // } Functions
  271.  
  272. // Use the 5 minute timeframe if the chart timeframe is lower than 5m
  273. if barstate.isfirst
  274. use_m5 := timeframe.in_seconds() < 300
  275.  
  276. [m5_open, m5_high, m5_low, m5_close] = request.security(syminfo.tickerid, '5', [open, high, low, close], lookahead = barmerge.lookahead_on)
  277.  
  278. open_value = use_m5 ? m5_open : open
  279. high_value = use_m5 ? m5_high : high
  280. low_value = use_m5 ? m5_low : low
  281. close_value = use_m5 ? m5_close : close
  282.  
  283. inOmega2v1Session = f_insession(Omega2v1Time) and showOmega2v1
  284. inOmega2v1Extend = f_insession(Omega2v1Extend) and showOmega2v1
  285. inOmega4v1Session = f_insession(Omega4v1Time) and showOmega4v1
  286. inOmega4v1Extend = f_insession(Omega4v1Extend) and showOmega4v1
  287. inOmega4v2Session = f_insession(Omega4v2Time) and showOmega4v2
  288. inOmega4v2Extend = f_insession(Omega4v2Extend) and showOmega4v2
  289. inOmega8v1Session = f_insession(Omega8v1Time) and showOmega8v1
  290. inOmega8v1Extend = f_insession(Omega8v1Extend) and showOmega8v1
  291. inOmega8v2Session = f_insession(Omega8v2Time) and showOmega8v2
  292. inOmega8v2Extend = f_insession(Omega8v2Extend) and showOmega8v2
  293. inOmega8v3Session = f_insession(Omega8v3Time) and showOmega8v3
  294. inOmega8v3Extend = f_insession(Omega8v3Extend) and showOmega8v3
  295. inOmega16v1Session = f_insession(Omega16v1Time) and showOmega16v1
  296. inOmega16v1Extend = f_insession(Omega16v1Extend) and showOmega16v1
  297. inOmega16v2Session = f_insession(Omega16v2Time) and showOmega16v2
  298. inOmega16v2Extend = f_insession(Omega16v2Extend) and showOmega16v2
  299. inOmega16v3Session = f_insession(Omega16v3Time) and showOmega16v3
  300. inOmega16v3Extend = f_insession(Omega16v3Extend) and showOmega16v3
  301. inOmega16v4Session = f_insession(Omega16v4Time) and showOmega16v4
  302. inOmega16v4Extend = f_insession(Omega16v4Extend) and showOmega16v4
  303. inOmega16v5Session = f_insession(Omega16v5Time) and showOmega16v5
  304. inOmega16v5Extend = f_insession(Omega16v5Extend) and showOmega16v5
  305. inOmega16v6Session = f_insession(Omega16v6Time) and showOmega16v6
  306. inOmega16v6Extend = f_insession(Omega16v6Extend) and showOmega16v6
  307. inOmega16v7Session = f_insession(Omega16v7Time) and showOmega16v7
  308. inOmega16v7Extend = f_insession(Omega16v7Extend) and showOmega16v7
  309. inOmega16v8Session = f_insession(Omega16v8Time) and showOmega16v8
  310. inOmega16v8Extend = f_insession(Omega16v8Extend) and showOmega16v8
  311.  
  312. inSession = inOmega2v1Session or inOmega4v1Session or inOmega4v2Session or inOmega8v1Session or inOmega8v2Session or inOmega8v3Session or inOmega16v1Session or inOmega16v2Session or inOmega16v3Session or inOmega16v4Session or inOmega16v5Session or inOmega16v6Session or inOmega16v7Session or inOmega16v8Session
  313. inExtend = inOmega2v1Extend or inOmega4v1Extend or inOmega4v2Extend or inOmega8v1Extend or inOmega8v2Extend or inOmega8v3Extend or inOmega16v1Extend or inOmega16v2Extend or inOmega16v3Extend or inOmega16v4Extend or inOmega16v5Extend or inOmega16v6Extend or inOmega16v7Extend or inOmega16v8Extend
  314.  
  315. enterSession = inSession and not inSession[1]
  316. enterExtend = inExtend and not inExtend[1]
  317.  
  318. leaveOmega4v1Session = not inOmega4v1Session and inOmega4v1Session[1]
  319. enterOmega4v1Extend = inOmega4v1Extend and not inOmega4v1Extend[1]
  320.  
  321.  
  322. if timeframe.isintraday and (PCchart.barIsVisible() or not showAllHistory)
  323. if enterSession
  324. currentSession := inOmega2v1Session ? Omega2v1Time : inOmega4v1Session ? Omega4v1Time : inOmega8v1Session ? Omega8v1Time : inOmega4v2Session ? Omega4v2Time : inOmega8v2Session ? Omega8v2Time : inOmega8v3Session ? Omega8v3Time : inOmega16v1Session ? Omega16v1Time : inOmega16v2Session ? Omega16v2Time : inOmega16v3Session ? Omega16v3Time : inOmega16v4Session ? Omega16v4Time : inOmega16v5Session ? Omega16v5Time : inOmega16v6Session ? Omega16v6Time : inOmega16v7Session ? Omega16v7Time : inOmega16v8Session ? Omega16v8Time : na
  325. else if enterExtend
  326. currentSession := inOmega2v1Extend ? Omega2v1Extend : inOmega4v1Extend ? Omega4v1Extend : inOmega8v1Extend ? Omega8v1Extend : inOmega4v2Extend ? Omega4v2Extend : inOmega8v2Extend ? Omega8v2Extend : inOmega8v3Extend ? Omega8v3Extend : inOmega16v1Extend ? Omega16v1Extend : inOmega16v2Extend ? Omega16v2Extend : inOmega16v3Extend ? Omega16v3Extend : inOmega16v4Extend ? Omega16v4Extend : inOmega16v5Extend ? Omega16v5Extend : inOmega16v6Extend ? Omega16v6Extend : inOmega16v7Extend ? Omega16v7Extend : inOmega16v8Extend ? Omega16v8Extend : na
  327.  
  328. if inSession
  329.  
  330. // Initialize levels
  331. if not inSession[1]
  332. startTime := time
  333. sessionOpen := open_value
  334. rdrhigh := high_value
  335. rdrlow := low_value
  336. ridrlow := math.min(open_value, close_value)
  337. ridrhigh := math.max(open_value, close_value)
  338.  
  339. // Initialize drawing objects
  340. if showBackground
  341. bgBox := f_newbox()
  342.  
  343. if drlines
  344. highrdrl := f_newdrline()
  345. lowrdrl := f_newdrline()
  346.  
  347. if idrlines
  348. highridrl := f_newidrline()
  349. lowridrl := f_newidrline()
  350.  
  351. if middledrline
  352. middlerdrl := f_newmdline()
  353.  
  354. if middleidrline
  355. middleridrl := f_newmdline()
  356.  
  357. if openline
  358. drLineOpen := f_newopline()
  359.  
  360. // Calculate levels
  361. rdrhigh := math.max(high_value, rdrhigh)
  362. rdrlow := math.min(low_value, rdrlow)
  363. ridrhigh := math.max(open_value, close_value, ridrhigh)
  364. ridrlow := math.min(open_value, close_value, ridrlow)
  365. rdrmiddle := math.avg(rdrhigh, rdrlow)
  366. ridrmiddle := math.avg(ridrhigh, ridrlow)
  367.  
  368. if leaveOmega4v1Session
  369. regidrhigh := ridrhigh
  370. regidrlow := ridrlow
  371. if inOmega4v1Extend
  372. stdLinesStartTime := f_sessionStartTime(Omega4v1Extend, TIMEZONE)
  373. stdLinesStopTime := f_sessionStopTime(Omega8v1Extend, TIMEZONE) + ONE_DAY * (dayofweek == dayofweek.friday and syminfo.type != 'crypto' ? 3 : 1)
  374.  
  375. if enterOmega4v1Extend
  376. // Initialize session high/low.
  377. sessionHigh := high_value
  378. sessionLow := low_value
  379.  
  380. // Remember high/low since session started. Needed for drawing STD levels. Also keep high low beyond Extend.
  381. sessionHigh := math.max(sessionHigh, high_value)
  382. sessionLow := math.min(sessionLow, low_value)
  383.  
  384. // Draw objects
  385. if showBackground and inSession
  386. boxUp = close_value > sessionOpen
  387. boxBorderColor = useBoxColors ? (boxUp ? upBorderColor : downBorderColor) : backgroundColor
  388. boxBackgroundColor = useBoxColors ? (boxUp ? upBoxColor : downBoxColor) : backgroundColor
  389. boxHigh = boxType==BX0 ? rdrhigh : ridrhigh
  390. boxLow = boxType==BX0 ? rdrlow : ridrlow
  391. f_movebox(bgBox, startTime, boxHigh, time, boxLow, boxBorderColor, boxBackgroundColor)
  392.  
  393. if extendToEndOfRDR
  394. if syminfo.type == 'warrant' or syminfo.type == 'structured' or syminfo.type == 'right'
  395. endTime := time
  396. else if time > (timenow - 2 * ONE_DAY) // no need to call functions every bar. Only start checking 2 days ago.
  397. if f_timestamp_to_date(f_sessionStopTime(currentSession, TIMEZONE), TIMEZONE) == f_timestamp_to_date(timenow, TIMEZONE) //timenow_date
  398. endTime := f_sessionStopTime(Omega4v1Extend, TIMEZONE)
  399. else
  400. endTime := time
  401. else
  402. endTime := time
  403. else
  404. endTime := time
  405.  
  406. if drlines and (inSession or (extenddrLines and inExtend))
  407. f_moveLine(highrdrl, startTime, rdrhigh, endTime)
  408. f_moveLine(lowrdrl, startTime, rdrlow, endTime)
  409. if middledrline
  410. f_moveLine(middlerdrl, startTime, rdrmiddle, endTime)
  411.  
  412. if idrlines and (inSession or (extendidrLines and inExtend))
  413. f_moveLine(highridrl, startTime, ridrhigh, endTime)
  414. f_moveLine(lowridrl, startTime, ridrlow, endTime)
  415. if middleidrline
  416. f_moveLine(middleridrl, startTime, ridrmiddle, endTime)
  417.  
  418. if openline and (inSession or (extendopLines and inExtend))
  419. f_moveLine(drLineOpen, startTime, sessionOpen, endTime)
  420.  
  421. if showStdLines
  422. f_drawStdLines(stdLinesStartTime, stdLinesStopTime, enterOmega4v1Extend)
  423.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement