Advertisement
xmd79

Remaining ATR [vnhilton]", "RATR

Jan 24th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.24 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. // © vnhilton
  3.  
  4. //@version=5
  5. indicator("Remaining ATR [vnhilton]", "RATR", overlay=true, max_lines_count=500) //Visible only on intraday timeframes
  6.  
  7. //RTH Session
  8. rth = time(timeframe.period, session.regular, syminfo.timezone)
  9.  
  10. //Parameters
  11. length = input(20, "Day ATR period", "Previous Day ATR will be used in calculations as it's static", group="ATR Parameters")
  12. atrRTHM1 = input.float(1, "ATR Multiplier #1", 0, group="ATR Parameters")
  13. atrRTHM2 = input.float(2, "ATR Multiplier #2", 0, group="ATR Parameters")
  14. atrRTHM3 = input.float(3, "ATR Multiplier #3", 0, group="ATR Parameters")
  15.  
  16. irYAxis = input(close, "Intraday Range Y-Axis", group="Intraday Range Label Parameters")
  17. irForm = input.string("Multiplier", "Intraday Range Form", ["Multiplier", "Percent", "Price"], tooltip="ATR Multiplier; Intraday Price; Percentage of ATR", group="Intraday Range Label Parameters")
  18. irLabelOffset = input(0, "Intraday Label Offset", "Offsets to the right of the current candle", group="Intraday Range Label Parameters")
  19. irLabelSize = input.string("Tiny", "Label Size", ["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group="Intraday Range Label Parameters")
  20. irLabelTextColor = input.color(color.new(#ffffff, 0), "Intraday Range Label Text Color", group="Intraday Range Label Parameters")
  21.  
  22. extension = input(false, "Extend Current Lines to The Right?", group="Line Parameters")
  23. recentLinesOnly = input(false, "Show Recent Lines Only?", group="Line Parameters")
  24. insideLineHide = input(false, "Hide RATR Lines When RATR <= 0?", "When RATR Lines go within the intraday high/low range, the lines will be hidden", group="Line Parameters")
  25. lineStyle = input.string("Solid", "Line Style", ["Dashed", "Dotted", "Solid"], group="Line Parameters")
  26.  
  27. insideLabelHide = input(false, "Hide RATR Labels When RATR <= 0?", "When RATR Lines go within the intraday high/low range, the labels will be hidden", group="Label Parameters")
  28. labelOffset = input(0, "Label Offset", "Offsets to the right of lines", group="Label Parameters")
  29. labelSize = input.string("Normal", "Label Size", ["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group="Label Parameters")
  30.  
  31. openLineColor = input.color(color.new(#b2b5be, 0), "Open line Color", group = "Open Line Parameters")
  32. openLineThickness = input.int(1, "Open Line's thickness", 1, group="Open Line Parameters")
  33. openLabelTextColor = input.color(color.new(#b2b5be, 0), "Open Label Text Color", group="Open Line Parameters")
  34.  
  35. baseLineThickness = input.int(1, "Baselines' thickness", 1, tooltip="Baselines are high & low lines", group="Baselines Parameters")
  36. highDLineColor = input.color(color.new(#bfd08c, 0), "High Line Color", group = "Baselines Parameters")
  37. highDLabelTextColor = input.color(color.new(#bfd08c, 0), "High Label Text Color", group="Baselines Parameters")
  38. highDPlotFillColor = input.color(color.new(#bfd08c, 90), "High Line Plot Fill Color", group = "Baselines Parameters")
  39.  
  40. lowDLineColor = input.color(color.new(#e35542, 0), "Low Line Color", group = "Baselines Parameters")
  41. lowDLabelTextColor = input.color(color.new(#e35542, 0), "Low Label Text Color", group="Baselines Parameters")
  42. lowDPlotFillColor = input.color(color.new(#e35542, 90), "Low Line Plot Fill Color", group = "Baselines Parameters")
  43.  
  44. atrThickness = input.int(1, "ATR lines' thickness", 1, group="ATR Lines Parameters")
  45. atr1LineColor = input.color(color.new(#4deeea, 0), "ATR #1 Lines Color", group="ATR Lines Parameters")
  46. atr1LineInsideColor = input.color(color.new(#4deeea, 80), "ATR #1 Lines Inside Color", "When RATR <= 0, then lines will change to a different color", group="ATR Lines Parameters")
  47. atr1LabelTextColor = input.color(color.new(#4deeea, 0), "ATR #1 Label Text Color", group="ATR Lines Parameters")
  48. atr1LabelTextInsideColor = input.color(color.new(#4deeea, 80), "ATR #1 Label Text Inside Color", "When RATR <= 0, then label will change to a different color", group="ATR Lines Parameters")
  49. atr1PlotFillColor = input.color(color.new(#4deeea, 90), "ATR #1 Line Plot Fill Color", "For the cleanest plot fills, make sure the ATR multipliers are as follows: M3 > M2 > M1", group = "ATR Lines Parameters")
  50.  
  51. atr2LineColor = input.color(color.new(#8a00ff, 0), "ATR #2 Lines Color", group="ATR Lines Parameters")
  52. atr2LineInsideColor = input.color(color.new(#8a00ff, 80), "ATR #2 Lines Inside Color", group="ATR Lines Parameters")
  53. atr2LabelTextColor = input.color(color.new(#8a00ff, 0), "ATR #2 Label Text Color", group="ATR Lines Parameters")
  54. atr2LabelTextInsideColor = input.color(color.new(#8a00ff, 80), "ATR #2 Label Text Inside Color", group="ATR Lines Parameters")
  55. atr2PlotFillColor = input.color(color.new(#8a00ff, 90), "ATR #2 Line Plot Fill Color", group = "ATR Lines Parameters")
  56.  
  57. atr3LineColor = input.color(color.new(#f000ff, 0), "ATR #3 Lines Color", group="ATR Lines Parameters")
  58. atr3LineInsideColor = input.color(color.new(#f000ff, 80), "ATR #3 Lines Inside Color", group="ATR Lines Parameters")
  59. atr3LabelTextColor = input.color(color.new(#f000ff, 0), "ATR #3 Label Text Color", group="ATR Lines Parameters")
  60. atr3LabelTextInsideColor = input.color(color.new(#f000ff, 80), "ATR #3 Label Text Inside Color", group="ATR Lines Parameters")
  61. atr3PlotFillColor = input.color(color.new(#f000ff, 90), "ATR #3 Line Plot Fill Color", group = "ATR Lines Parameters")
  62.  
  63. //hl2 Range Function
  64. hl2Range(h, l) =>
  65. (h + l) / 2
  66.  
  67. //Values Gathering
  68. atr = ta.atr(length)
  69.  
  70. [yAtrD, yHighD, yLowD] = request.security(syminfo.tickerid, "D", [atr[1], high[1], low[1]], lookahead=barmerge.lookahead_on) //Daily data as ATR values consistent across daily/intraday TFs, & HL only used as conditions
  71.  
  72. //Obtain OHL via intraday data due to daily/intraday data inconsistencies
  73. //Counting RTH Bars
  74. rthBars = int(na)
  75.  
  76. //Reset On New Day
  77. isNewDay = time("D") != time("D")[1]
  78.  
  79. rthBars := isNewDay ? 1 : rth ? nz(rthBars[1]) + 1 : 0
  80.  
  81. //Getting Open Value & Resetting rthBars For RTH Only
  82. var float openD = na
  83. if rthBars == 1
  84. openD := open
  85.  
  86. //Getting HL Values (This Leads to Warning But Extracting Functions Out Prevents Script From Working)
  87. highD = rthBars < 1 ? ta.highest(high, 1) : ta.highest(high, rthBars)
  88. lowD = rthBars < 1 ? ta.lowest(low, 1) : ta.lowest(low, rthBars)
  89.  
  90. CATR = highD - lowD //Current ATR
  91.  
  92. //ATR Calculations
  93. remainingATR(multiplier) =>
  94. RATR = multiplier * yAtrD - CATR //Remaining ATR
  95.  
  96. //Yesterday's & Today's HL2
  97. yRange = hl2Range(yHighD, yLowD) //Used to detect new day
  98. tRange = hl2Range(highD, lowD) //Used to detect intraday new highs/lows
  99.  
  100. //Label Size Selection
  101. labelSizing(choice) =>
  102. switch labelSize
  103. "Auto" => size.auto
  104. "Tiny" => size.tiny
  105. "Small" => size.small
  106. "Normal" => size.normal
  107. "Large" => size.large
  108. "Huge" => size.huge
  109.  
  110. //Line Style Selection
  111. lineStyling(choice) =>
  112. switch lineStyle
  113. "Dashed" => line.style_dashed
  114. "Dotted" => line.style_dotted
  115. "Solid" => line.style_solid
  116.  
  117. //Intraday Range Label Form Calculation
  118. irRangeFormSelection(choice) =>
  119. switch irForm
  120. "Multiplier" => str.tostring(CATR / yAtrD, '#0.00') + "x"
  121. "Percent" => str.tostring(CATR * 100 / yAtrD, '#0.00') + "%"
  122. "Price" => str.tostring(CATR, format.mintick)
  123.  
  124. //Line Style Assignments
  125. style = lineStyling(lineStyle)
  126.  
  127. //Labels Size Assignment
  128. size = labelSizing(labelSize)
  129. irSize = labelSizing(irLabelSize)
  130.  
  131. //Intraday Range Assignment
  132. irPrice = irRangeFormSelection(irForm)
  133.  
  134. //Setup Lines
  135. var line openLine = na
  136. var line highLine = na
  137. var line lowLine = na
  138.  
  139. var line atr1LineU = na
  140. var line atr1LineD = na
  141. var line atr2LineU = na
  142. var line atr2LineD = na
  143. var line atr3LineU = na
  144. var line atr3LineD = na
  145.  
  146. //Setup Line Plot Fills
  147. var linefill atr1FillUp = na
  148. var linefill atr1FillDown = na
  149. var linefill atr2FillUp = na
  150. var linefill atr2FillDown = na
  151. var linefill atr3FillUp = na
  152. var linefill atr3FillDown = na
  153.  
  154. //Setup Labels
  155. var label openLabel = na
  156. var label highLabel = na
  157. var label lowLabel = na
  158.  
  159. var label irLabel = na
  160.  
  161. var label atr1LabelU = na
  162. var label atr1LabelD = na
  163. var label atr2LabelU = na
  164. var label atr2LabelD = na
  165. var label atr3LabelU = na
  166. var label atr3LabelD = na
  167.  
  168. //Code to Clean Up RATR Lines When RATR < 0
  169. ratrCleanUp(ratr, pLinePrice, linePrice, line, label) =>
  170. if ratr < 0 and pLinePrice != linePrice
  171. line.set_color(line, color.new(#000000, 100))
  172. label.set_textcolor(label, color.new(#000000, 100))
  173.  
  174. //Code to Detect New Day
  175. if yRange[1] != yRange and timeframe.isintraday
  176.  
  177. //Stop Old Lines Extensions If There're Any
  178. line.set_extend(openLine, extend.none)
  179. line.set_extend(highLine, extend.none)
  180. line.set_extend(lowLine, extend.none)
  181.  
  182. line.set_extend(atr1LineU, extend.none)
  183. line.set_extend(atr1LineD, extend.none)
  184. line.set_extend(atr2LineU, extend.none)
  185. line.set_extend(atr2LineD, extend.none)
  186. line.set_extend(atr3LineU, extend.none)
  187. line.set_extend(atr3LineD, extend.none)
  188.  
  189. //Delete Old Labels to Keep Charts Clean If There're Any
  190. label.delete(openLabel)
  191. label.delete(highLabel)
  192. label.delete(lowLabel)
  193.  
  194. label.delete(irLabel)
  195.  
  196. label.delete(atr1LabelU)
  197. label.delete(atr1LabelD)
  198. label.delete(atr2LabelU)
  199. label.delete(atr2LabelD)
  200. label.delete(atr3LabelU)
  201. label.delete(atr3LabelD)
  202.  
  203. //Create New Lines
  204. openLine := line.new(bar_index, openD, bar_index, openD, color=openLineColor, style=style, width=openLineThickness)
  205. highLine := line.new(bar_index, highD, bar_index, highD, color=highDLineColor, style=style, width=baseLineThickness)
  206. lowLine := line.new(bar_index, lowD, bar_index, lowD, color=lowDLineColor, style=style, width=baseLineThickness)
  207.  
  208. atr1LineU := line.new(bar_index, highD + remainingATR(atrRTHM1), bar_index, highD + remainingATR(atrRTHM1), color=atr1LineColor, style=style, width=atrThickness)
  209. atr1LineD := line.new(bar_index, lowD - remainingATR(atrRTHM1), bar_index, lowD - remainingATR(atrRTHM1), color=atr1LineColor, style=style, width=atrThickness)
  210. atr2LineU := line.new(bar_index, highD + remainingATR(atrRTHM2), bar_index, highD + remainingATR(atrRTHM2), color=atr2LineColor, style=style, width=atrThickness)
  211. atr2LineD := line.new(bar_index, lowD - remainingATR(atrRTHM2), bar_index, lowD - remainingATR(atrRTHM2), color=atr2LineColor, style=style, width=atrThickness)
  212. atr3LineU := line.new(bar_index, highD + remainingATR(atrRTHM3), bar_index, highD + remainingATR(atrRTHM3), color=atr3LineColor, style=style, width=atrThickness)
  213. atr3LineD := line.new(bar_index, lowD - remainingATR(atrRTHM3), bar_index, lowD - remainingATR(atrRTHM3), color=atr3LineColor, style=style, width=atrThickness)
  214.  
  215. //Line Fills
  216. linefill.new(openLine, highLine, highDPlotFillColor)
  217. linefill.new(openLine, lowLine, lowDPlotFillColor)
  218.  
  219. atr1FillUp := linefill.new(highLine, atr1LineU, atr1PlotFillColor)
  220. atr1FillDown := linefill.new(lowLine, atr1LineD, atr1PlotFillColor)
  221. atr2FillUp := linefill.new(highLine, atr2LineU, atr2PlotFillColor)
  222. atr2FillDown := linefill.new(lowLine, atr2LineD, atr2PlotFillColor)
  223. atr3FillUp := linefill.new(highLine, atr3LineU, atr3PlotFillColor)
  224. atr3FillDown := linefill.new(lowLine, atr3LineD, atr3PlotFillColor)
  225.  
  226. //Create Labels
  227. openLabel := label.new(bar_index + labelOffset, openD, 'Open: ' + str.tostring(openD, format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=openLabelTextColor, size=size)
  228. highLabel := label.new(bar_index + labelOffset, highD, 'High: ' + str.tostring(highD, format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=highDLabelTextColor, size=size)
  229. lowLabel := label.new(bar_index + labelOffset, lowD, 'Low: ' + str.tostring(lowD, format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=lowDLabelTextColor, size=size)
  230.  
  231. irLabel := label.new(bar_index + irLabelOffset, irYAxis, 'IR: ' + irPrice, color=color.new(#000000, 100), style=label.style_label_left, textcolor=irLabelTextColor, size=irSize)
  232.  
  233. atr1LabelU := label.new(bar_index + labelOffset, highD + remainingATR(atrRTHM1), 'RATR #1: ' + str.tostring(highD + remainingATR(atrRTHM1), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr1LabelTextColor, size=size)
  234. atr1LabelD := label.new(bar_index + labelOffset, lowD - remainingATR(atrRTHM1), 'RATR #1: ' + str.tostring(lowD - remainingATR(atrRTHM1), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr1LabelTextColor, size=size)
  235. atr2LabelU := label.new(bar_index + labelOffset, highD + remainingATR(atrRTHM2), 'RATR #2: ' + str.tostring(highD + remainingATR(atrRTHM2), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr2LabelTextColor, size=size)
  236. atr2LabelD := label.new(bar_index + labelOffset, lowD - remainingATR(atrRTHM2), 'RATR #2: ' + str.tostring(lowD - remainingATR(atrRTHM2), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr2LabelTextColor, size=size)
  237. atr3LabelU := label.new(bar_index + labelOffset, highD + remainingATR(atrRTHM3), 'RATR #3: ' + str.tostring(highD + remainingATR(atrRTHM3), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr3LabelTextColor, size=size)
  238. atr3LabelD := label.new(bar_index + labelOffset, lowD - remainingATR(atrRTHM3), 'RATR #3: ' + str.tostring(lowD - remainingATR(atrRTHM3), format.mintick), color=color.new(#000000, 100), style=label.style_label_left, textcolor=atr3LabelTextColor, size=size)
  239.  
  240. //If Only Want Recent Lines On Chart
  241. if recentLinesOnly
  242. line.delete(openLine[1])
  243. line.delete(highLine[1])
  244. line.delete(lowLine[1])
  245.  
  246. line.delete(atr1LineU[1])
  247. line.delete(atr1LineD[1])
  248. line.delete(atr2LineU[1])
  249. line.delete(atr2LineD[1])
  250. line.delete(atr3LineU[1])
  251. line.delete(atr3LineD[1])
  252.  
  253. //Extending lines
  254. if extension
  255. line.set_extend(openLine, extend.right)
  256. line.set_extend(highLine, extend.right)
  257. line.set_extend(lowLine, extend.right)
  258.  
  259. line.set_extend(atr1LineU, extend.right)
  260. line.set_extend(atr1LineD, extend.right)
  261. line.set_extend(atr2LineU, extend.right)
  262. line.set_extend(atr2LineD, extend.right)
  263. line.set_extend(atr3LineU, extend.right)
  264. line.set_extend(atr3LineD, extend.right)
  265.  
  266. //Code to Detect Intraday Range Change
  267. if tRange[1] != tRange and rth and timeframe.isintraday
  268.  
  269. //Delete Line Plot Fills
  270. linefill.delete(atr1FillUp)
  271. linefill.delete(atr1FillDown)
  272. linefill.delete(atr2FillUp)
  273. linefill.delete(atr2FillDown)
  274. linefill.delete(atr3FillUp)
  275. linefill.delete(atr3FillDown)
  276.  
  277. //Create & Update Line Plot Fills
  278. atr1FillUp := linefill.new(highLine, atr1LineU, atr1PlotFillColor)
  279. atr1FillDown := linefill.new(lowLine, atr1LineD, atr1PlotFillColor)
  280. atr2FillUp := linefill.new(highD >= line.get_y1(atr1LineU) ? highLine : atr1LineU, atr2LineU, atr2PlotFillColor)
  281. atr2FillDown := linefill.new(lowD <= line.get_y1(atr1LineD) ? lowLine : atr1LineD, atr2LineD, atr2PlotFillColor)
  282. atr3FillUp := linefill.new(highD >= line.get_y1(atr2LineU) ? highLine : atr2LineU, atr3LineU, atr3PlotFillColor)
  283. atr3FillDown := linefill.new(lowD <= line.get_y1(atr2LineD) ? lowLine : atr2LineD, atr3LineD, atr3PlotFillColor)
  284.  
  285. linefill.set_color(atr1FillUp, remainingATR(atrRTHM1) >= 0 ? atr1PlotFillColor : na)
  286. linefill.set_color(atr1FillDown, remainingATR(atrRTHM1) >= 0 ? atr1PlotFillColor : na)
  287. linefill.set_color(atr2FillUp, remainingATR(atrRTHM2) >= 0 ? atr2PlotFillColor : na)
  288. linefill.set_color(atr2FillDown, remainingATR(atrRTHM2) >= 0 ? atr2PlotFillColor : na)
  289. linefill.set_color(atr3FillUp, remainingATR(atrRTHM3) >= 0 ? atr3PlotFillColor : na)
  290. linefill.set_color(atr3FillDown, remainingATR(atrRTHM3) >= 0 ? atr3PlotFillColor : na)
  291.  
  292. //Code For When RATR <= 0? i.e. RATR Lines Are Inside Range
  293. if remainingATR(atrRTHM1) <= 0
  294.  
  295. line.set_color(atr1LineU, atr1LineInsideColor)
  296. line.set_color(atr1LineD, atr1LineInsideColor)
  297.  
  298. label.set_textcolor(atr1LabelU, atr1LabelTextInsideColor)
  299. label.set_textcolor(atr1LabelD, atr1LabelTextInsideColor)
  300.  
  301. if insideLineHide
  302. line.set_color(atr1LineU, color.new(#000000, 100))
  303. line.set_color(atr1LineD, color.new(#000000, 100))
  304.  
  305. if insideLabelHide
  306. label.set_textcolor(atr1LabelU, color.new(#000000, 100))
  307. label.set_textcolor(atr1LabelD, color.new(#000000, 100))
  308.  
  309. if remainingATR(atrRTHM2) <= 0
  310.  
  311. line.set_color(atr2LineU, atr2LineInsideColor)
  312. line.set_color(atr2LineD, atr2LineInsideColor)
  313.  
  314. label.set_textcolor(atr2LabelU, atr2LabelTextInsideColor)
  315. label.set_textcolor(atr2LabelD, atr2LabelTextInsideColor)
  316.  
  317. if insideLineHide
  318. line.set_color(atr2LineU, color.new(#000000, 100))
  319. line.set_color(atr2LineD, color.new(#000000, 100))
  320.  
  321. if insideLabelHide
  322. label.set_textcolor(atr2LabelU, color.new(#000000, 100))
  323. label.set_textcolor(atr2LabelD, color.new(#000000, 100))
  324.  
  325. if remainingATR(atrRTHM3) <= 0
  326.  
  327. line.set_color(atr3LineU, atr3LineInsideColor)
  328. line.set_color(atr3LineD, atr3LineInsideColor)
  329.  
  330. label.set_textcolor(atr3LabelU, atr3LabelTextInsideColor)
  331. label.set_textcolor(atr3LabelD, atr3LabelTextInsideColor)
  332.  
  333. if insideLineHide
  334. line.set_color(atr3LineU, color.new(#000000, 100))
  335. line.set_color(atr3LineD, color.new(#000000, 100))
  336.  
  337. if insideLabelHide
  338. label.set_textcolor(atr3LabelU, color.new(#000000, 100))
  339. label.set_textcolor(atr3LabelD, color.new(#000000, 100))
  340.  
  341. //Remove Moving RATR Lines To Prevent Visual Confusion when RATR < 0
  342. ratrCleanUp(remainingATR(atrRTHM1), line.get_y1(atr1LineU)[1], line.get_y1(atr1LineU), atr1LineU, atr1LabelU)
  343. ratrCleanUp(remainingATR(atrRTHM1), line.get_y1(atr1LineD)[1], line.get_y1(atr1LineD), atr1LineD, atr1LabelD)
  344. ratrCleanUp(remainingATR(atrRTHM2), line.get_y1(atr2LineU)[1], line.get_y1(atr2LineU), atr2LineU, atr2LabelU)
  345. ratrCleanUp(remainingATR(atrRTHM2), line.get_y1(atr2LineD)[1], line.get_y1(atr2LineD), atr2LineD, atr2LabelD)
  346. ratrCleanUp(remainingATR(atrRTHM3), line.get_y1(atr3LineU)[1], line.get_y1(atr3LineU), atr3LineU, atr3LabelU)
  347. ratrCleanUp(remainingATR(atrRTHM3), line.get_y1(atr3LineD)[1], line.get_y1(atr3LineD), atr3LineD, atr3LabelD)
  348.  
  349. //Update Line Coordinates
  350. line.set_x2(openLine, bar_index)
  351. line.set_x2(highLine, bar_index)
  352. line.set_x2(lowLine, bar_index)
  353.  
  354. line.set_x2(atr1LineU, bar_index)
  355. line.set_x2(atr1LineD, bar_index)
  356. line.set_x2(atr2LineU, bar_index)
  357. line.set_x2(atr2LineD, bar_index)
  358. line.set_x2(atr3LineU, bar_index)
  359. line.set_x2(atr3LineD, bar_index)
  360.  
  361. line.set_y1(highLine, highD)
  362. line.set_y2(highLine, highD)
  363. line.set_y1(lowLine, lowD)
  364. line.set_y2(lowLine, lowD)
  365.  
  366. line.set_y1(atr1LineU, highD + remainingATR(atrRTHM1))
  367. line.set_y2(atr1LineU, highD + remainingATR(atrRTHM1))
  368. line.set_y1(atr1LineD, lowD - remainingATR(atrRTHM1))
  369. line.set_y2(atr1LineD, lowD - remainingATR(atrRTHM1))
  370. line.set_y1(atr2LineU, highD + remainingATR(atrRTHM2))
  371. line.set_y2(atr2LineU, highD + remainingATR(atrRTHM2))
  372. line.set_y1(atr2LineD, lowD - remainingATR(atrRTHM2))
  373. line.set_y2(atr2LineD, lowD - remainingATR(atrRTHM2))
  374. line.set_y1(atr3LineU, highD + remainingATR(atrRTHM3))
  375. line.set_y2(atr3LineU, highD + remainingATR(atrRTHM3))
  376. line.set_y1(atr3LineD, lowD - remainingATR(atrRTHM3))
  377. line.set_y2(atr3LineD, lowD - remainingATR(atrRTHM3))
  378.  
  379. //Update Label Coordinates
  380. label.set_x(openLabel, bar_index + labelOffset)
  381. label.set_x(highLabel, bar_index + labelOffset)
  382. label.set_x(lowLabel, bar_index + labelOffset)
  383.  
  384. label.set_x(irLabel, bar_index + irLabelOffset)
  385.  
  386. label.set_x(atr1LabelU, bar_index + labelOffset)
  387. label.set_x(atr1LabelD, bar_index + labelOffset)
  388. label.set_x(atr2LabelU, bar_index + labelOffset)
  389. label.set_x(atr2LabelD, bar_index + labelOffset)
  390. label.set_x(atr3LabelU, bar_index + labelOffset)
  391. label.set_x(atr3LabelD, bar_index + labelOffset)
  392.  
  393. label.set_y(highLabel, highD)
  394. label.set_y(lowLabel, lowD)
  395.  
  396. label.set_y(irLabel, irYAxis)
  397.  
  398. label.set_y(atr1LabelU, highD + remainingATR(atrRTHM1))
  399. label.set_y(atr1LabelD, lowD - remainingATR(atrRTHM1))
  400. label.set_y(atr2LabelU, highD + remainingATR(atrRTHM2))
  401. label.set_y(atr2LabelD, lowD - remainingATR(atrRTHM2))
  402. label.set_y(atr3LabelU, highD + remainingATR(atrRTHM3))
  403. label.set_y(atr3LabelD, lowD - remainingATR(atrRTHM3))
  404.  
  405. //Update Label Text
  406. label.set_text(highLabel, 'High: ' + str.tostring(highD, format.mintick))
  407. label.set_text(lowLabel, 'Low: ' + str.tostring(lowD, format.mintick))
  408.  
  409. label.set_text(irLabel, 'IR: ' + irPrice)
  410.  
  411. label.set_text(atr1LabelU, 'RATR #1: ' + str.tostring(highD + remainingATR(atrRTHM1), format.mintick))
  412. label.set_text(atr1LabelD, 'RATR #1: ' + str.tostring(lowD - remainingATR(atrRTHM1), format.mintick))
  413. label.set_text(atr2LabelU, 'RATR #2: ' + str.tostring(highD + remainingATR(atrRTHM2), format.mintick))
  414. label.set_text(atr2LabelD, 'RATR #2: ' + str.tostring(lowD - remainingATR(atrRTHM2), format.mintick))
  415. label.set_text(atr3LabelU, 'RATR #3: ' + str.tostring(highD + remainingATR(atrRTHM3), format.mintick))
  416. label.set_text(atr3LabelD, 'RATR #3: ' + str.tostring(lowD - remainingATR(atrRTHM3), format.mintick))
  417.  
  418. //Code to Detect No Intraday Range Change
  419. if tRange[1] == tRange and rth and timeframe.isintraday
  420.  
  421. //Update Line Coordinates
  422. line.set_x2(openLine, bar_index)
  423. line.set_x2(highLine, bar_index)
  424. line.set_x2(lowLine, bar_index)
  425.  
  426. line.set_x2(atr1LineU, bar_index)
  427. line.set_x2(atr1LineD, bar_index)
  428. line.set_x2(atr2LineU, bar_index)
  429. line.set_x2(atr2LineD, bar_index)
  430. line.set_x2(atr3LineU, bar_index)
  431. line.set_x2(atr3LineD, bar_index)
  432.  
  433. //Update Label Coordinates
  434. label.set_x(openLabel, bar_index + labelOffset)
  435. label.set_x(highLabel, bar_index + labelOffset)
  436. label.set_x(lowLabel, bar_index + labelOffset)
  437.  
  438. label.set_x(irLabel, bar_index + irLabelOffset)
  439. label.set_y(irLabel, irYAxis)
  440.  
  441. label.set_x(atr1LabelU, bar_index + labelOffset)
  442. label.set_x(atr1LabelD, bar_index + labelOffset)
  443. label.set_x(atr2LabelU, bar_index + labelOffset)
  444. label.set_x(atr2LabelD, bar_index + labelOffset)
  445. label.set_x(atr3LabelU, bar_index + labelOffset)
  446. label.set_x(atr3LabelD, bar_index + labelOffset)
  447.  
  448. //Code to Detect ETH Range
  449. if not rth and timeframe.isintraday
  450. //Stop Old Lines Extensions If There're Any
  451. line.set_extend(openLine, extend.none)
  452. line.set_extend(highLine, extend.none)
  453. line.set_extend(lowLine, extend.none)
  454.  
  455. line.set_extend(atr1LineU, extend.none)
  456. line.set_extend(atr1LineD, extend.none)
  457. line.set_extend(atr2LineU, extend.none)
  458. line.set_extend(atr2LineD, extend.none)
  459. line.set_extend(atr3LineU, extend.none)
  460. line.set_extend(atr3LineD, extend.none)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement