Guest User

Auto Levels

a guest
Dec 31st, 2025
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.63 KB | None | 0 0
  1. // This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © taylorbray
  3.  
  4. // NOTES
  5. // Add ETH open, RTH open, RTH close, ETH close
  6. // - could use ticker.new(x, x, session) to call specific req.sec from certain sessions
  7. //
  8. //
  9.  
  10. //@version=6
  11. indicator('Auto Levels', overlay = true, precision = 2, max_bars_back = 5000)
  12.  
  13. //////////////////////////////////// CLOSE PRICE
  14.  
  15. prevcolor = input.color(defval = #808080c4, title = 'Level Color', group = 'APPEARANCE SETTINGS')
  16. textcolor1 = input.color(defval = #808080c4, title = 'Text Color', group = 'APPEARANCE SETTINGS')
  17. linetype1 = input.string(defval = 'Solid', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
  18. textsizeinput1 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
  19.  
  20. tickertype = ''
  21.  
  22. if syminfo.type == 'futures'
  23. tickertype := 'futures'
  24. if syminfo.type == 'stock'
  25. tickertype := 'stock'
  26. if syminfo.type == 'crypto'
  27. tickertype := 'crypto'
  28.  
  29.  
  30. linestyle1 = line.style_solid
  31.  
  32. textsize1 = size.small
  33.  
  34. if linetype1 == 'Solid'
  35. linestyle1 := line.style_solid
  36. else if linetype1 == 'Dashed'
  37. linestyle1 := line.style_dashed
  38. else if linetype1 == 'Dotted'
  39. linestyle1 := line.style_dotted
  40.  
  41. if textsizeinput1 == 'Tiny'
  42. textsize1 := size.tiny
  43. else if textsizeinput1 == 'Small'
  44. textsize1 := size.small
  45. else if textsizeinput1 == 'Normal'
  46. textsize1 := size.normal
  47. else if textsizeinput1 == 'Large'
  48. textsize1 := size.large
  49. else if textsizeinput1 == 'Huge'
  50. textsize1 := size.huge
  51. else if textsizeinput1 == 'auto'
  52. textsize1 := size.auto
  53.  
  54. opencolor = input.color(defval = #e679a6bb, title = 'Open Color', group = 'APPEARANCE SETTINGS')
  55. textcolor2 = input.color(defval = #e679a6bb, title = 'Text Color', group = 'APPEARANCE SETTINGS')
  56. linetype2 = input.string(defval = 'Dotted', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
  57. textsizeinput2 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
  58.  
  59.  
  60. linestyle2 = line.style_dotted
  61.  
  62. textsize2 = size.small
  63.  
  64. if linetype2 == 'Solid'
  65. linestyle2 := line.style_solid
  66. else if linetype2 == 'Dashed'
  67. linestyle2 := line.style_dashed
  68. else if linetype2 == 'Dotted'
  69. linestyle2 := line.style_dotted
  70.  
  71. if textsizeinput2 == 'Tiny'
  72. textsize2 := size.tiny
  73. else if textsizeinput2 == 'Small'
  74. textsize2 := size.small
  75. else if textsizeinput2 == 'Normal'
  76. textsize2 := size.normal
  77. else if textsizeinput2 == 'Large'
  78. textsize2 := size.large
  79. else if textsizeinput2 == 'Huge'
  80. textsizeinput2 := size.huge
  81. else if textsizeinput2 == 'auto'
  82. textsize2 := size.auto
  83.  
  84.  
  85. closecolor = input.color(defval = #d68915bb, title = 'Close Color', group = 'APPEARANCE SETTINGS')
  86. textcolor3 = input.color(defval = #d68915bb, title = 'Text Color', group = 'APPEARANCE SETTINGS')
  87. linetype3= input.string(defval = 'Dotted', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
  88. textsizeinput3 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
  89.  
  90.  
  91. linestyle3 = line.style_dotted
  92.  
  93. textsize3 = size.small
  94.  
  95. auto_offset = input.bool(true, 'Auto-adjust line extend length', tooltip = 'Automatically changes the line-extend length based on the selected timeframe', group = 'OPTIONS')
  96. ticker.standard(syminfo.tickerid)
  97.  
  98. //////////////////////////////////// PWH/PWL + PDH/PDL
  99.  
  100.  
  101. /////////////////// SETTINGS
  102.  
  103.  
  104. show_pdc = input.bool(true, 'Show PD Close', group = 'DAY')
  105. show_pd = input.bool(true, 'Show PDH/PDL', group = 'DAY')
  106. show_do = input.bool(true, 'Show Day Open', group = 'DAY')
  107.  
  108. show_pwc = input.bool(true, 'Show PW Close', group = 'WEEK')
  109. show_pw = input.bool(true, 'Show PWH/PWL', group = 'WEEK')
  110. show_wo = input.bool(true, 'Show Week Open', group = 'WEEK')
  111.  
  112. show_pmc = input.bool(true, 'Show PM Close', group = 'MONTH')
  113. show_pm = input.bool(true, 'Show PMH/PML', group = 'MONTH')
  114. show_mo = input.bool(true, 'Show Month Open', group = 'MONTH')
  115.  
  116. show_pqc = input.bool(true, 'Show PQ Close', group = 'QUARTER')
  117. show_pq = input.bool(true, 'Show PQH/PQL', group = 'QUARTER')
  118. show_qo = input.bool(true, 'Show Quarter Open', group = 'QUARTER')
  119.  
  120. show_pyc = input.bool(true, 'Show PY Close', group = 'YEAR')
  121. show_py = input.bool(true, 'Show PYH/PYL', group = 'YEAR')
  122. show_yo = input.bool(true, 'Show Year Open', group = 'YEAR')
  123.  
  124. crypto = false
  125.  
  126. if syminfo.type == 'Spot crypto' or syminfo.type == 'Spot crypto defi'
  127. crypto := true
  128. else
  129. crypto := false
  130.  
  131.  
  132. /////////////////// VARIABLES & ASSINGMENTS
  133.  
  134. condition = not(timeframe.isweekly or timeframe.ismonthly)
  135.  
  136. float yo = request.security(ticker.standard(syminfo.tickerid), '12M', open)
  137. float qo = request.security(ticker.standard(syminfo.tickerid), '3M', open)
  138. float mo = request.security(ticker.standard(syminfo.tickerid), 'M', open)
  139. float wo = request.security(ticker.standard(syminfo.tickerid), 'W', open)
  140. float dyo = request.security(ticker.standard(syminfo.tickerid), 'D', open)
  141.  
  142.  
  143. float pyh = request.security(ticker.standard(syminfo.tickerid), '12M', high)
  144. float pyl = request.security(ticker.standard(syminfo.tickerid), '12M', low)
  145. float pyc = request.security(ticker.standard(syminfo.tickerid), '12M', close)
  146.  
  147. float pqh = request.security(ticker.standard(syminfo.tickerid), '3M', high)
  148. float pql = request.security(ticker.standard(syminfo.tickerid), '3M', low )
  149. float pqc = request.security(ticker.standard(syminfo.tickerid), '3M', close )
  150.  
  151. float pmh = request.security(ticker.standard(syminfo.tickerid), 'M', high )
  152. float pml = request.security(ticker.standard(syminfo.tickerid), 'M', low )
  153. float pmc = request.security(ticker.standard(syminfo.tickerid), 'M', close )
  154.  
  155. float pwh = request.security(ticker.standard(syminfo.tickerid), 'W', high )
  156. float pwl = request.security(ticker.standard(syminfo.tickerid), 'W', low )
  157. float pwc = request.security(ticker.standard(syminfo.tickerid), 'W', close )
  158.  
  159. float pdh = request.security(ticker.standard(syminfo.tickerid), 'D', high )
  160. float pdl = request.security(ticker.standard(syminfo.tickerid), 'D', low )
  161. float pdc = request.security(ticker.standard(syminfo.tickerid), 'D', close )
  162.  
  163. nw = ta.change(time('W'))
  164. nd = ta.change(time('D'))
  165. nm = ta.change(time('M'))
  166. nq = ta.change(time('3M'))
  167. ny = ta.change(time('12M'))
  168.  
  169. max_bars_back(time, 5000)
  170. _ycount = ta.barssince(bool(ny))
  171. _qcount = ta.barssince(bool(nq))
  172. _mcount = ta.barssince(bool(nm))
  173. _wcount = ta.barssince(bool(nw))
  174. _dcount = ta.barssince(bool(nd))
  175.  
  176. var line _pyh = na
  177. var line _pyl = na
  178. var line _pyc = na
  179.  
  180. var line _pqh = na
  181. var line _pql = na
  182. var line _pqc = na
  183.  
  184. var line _pmh = na
  185. var line _pml = na
  186. var line _pmc = na
  187.  
  188. var line _pwh = na
  189. var line _pwl = na
  190. var line _pwc = na
  191.  
  192. var line _pdh = na
  193. var line _pdl = na
  194. var line _pdc = na
  195.  
  196. var line _yo = na
  197. var line _qo = na
  198. var line _mo = na
  199. var line _wo = na
  200. var line _do = na
  201.  
  202. var label pyh_label = na
  203. var label pyl_label = na
  204. var label pyc_label = na
  205.  
  206. var label pqh_label = na
  207. var label pql_label = na
  208. var label pqc_label = na
  209.  
  210. var label pmh_label = na
  211. var label pml_label = na
  212. var label pmc_label = na
  213.  
  214. var label pwh_label = na
  215. var label pwl_label = na
  216. var label pwc_label = na
  217.  
  218. var label pdh_label = na
  219. var label pdl_label = na
  220. var label pdc_label = na
  221.  
  222.  
  223. var label yo_label = na
  224. var label qo_label = na
  225. var label mo_label = na
  226. var label wo_label = na
  227. var label do_label = na
  228.  
  229. offsetvalinput = input.int(20, 'Line-Extend Length', group = 'SETTINGS')
  230. offsetmult = input.int(10, 'Auto-Extend Multiplier', group = 'SETTINGS')
  231. int offsetval = 0
  232.  
  233. timeframe = timeframe.period
  234.  
  235. if auto_offset == false
  236. offsetval := offsetvalinput * 200 // idk
  237. if auto_offset == true
  238. if timeframe == '1D'
  239. offsetval := offsetvalinput * 500
  240. show_do:=false
  241. show_pdc:=false
  242. show_pd:=false
  243. if timeframe == '1W'
  244. offsetval := offsetvalinput * 1700
  245. show_do:=false
  246. show_pdc:=false
  247. show_pd:=false
  248. show_wo:=false
  249. show_pwc:=false
  250. show_pw:=false
  251. if timeframe == '1M'
  252. offsetval := offsetvalinput * 8000
  253. show_do:=false
  254. show_pdc:=false
  255. show_pd:=false
  256. show_wo:=false
  257. show_pwc:=false
  258. show_pw:=false
  259. show_mo:=false
  260. show_pmc:=false
  261. show_pm:=false
  262. if timeframe == "720"
  263. offsetval := offsetmult * 5000
  264. show_do:=false
  265. show_pd:=false
  266. if timeframe == "480" or timeframe== "240"
  267. offsetval := offsetmult * 2500
  268. if timeframe == "120" or timeframe == "60"
  269. offsetval := offsetmult * 200
  270. if timeframe== "45" or timeframe == "30"
  271. offsetval :=offsetmult * 70
  272. show_yo:=false
  273. show_pyc:=false
  274. show_py:=false
  275. if timeframe == "15" or timeframe == "10"
  276. offsetval := offsetmult * 50
  277. show_mo:=false
  278. show_pmc:=false
  279. show_pm:=false
  280. show_qo:=false
  281. show_pqc:=false
  282. show_pq:=false
  283. show_yo:=false
  284. show_pyc:=false
  285. show_py:=false
  286. if timeframe== "5" or timeframe == "3"
  287. offsetval := offsetmult * 35
  288. show_mo:=false
  289. show_pmc:=false
  290. show_pm:=false
  291. show_qo:=false
  292. show_pqc:=false
  293. show_pq:=false
  294. show_yo:=false
  295. show_pyc:=false
  296. show_py:=false
  297. if timeframe == "1"
  298. offsetval := offsetmult * 10
  299. show_wo:=false
  300. show_pwc:=false
  301. show_pw:=false
  302. show_mo:=false
  303. show_pmc:=false
  304. show_pm:=false
  305. show_qo:=false
  306. show_pqc:=false
  307. show_pq:=false
  308. show_yo:=false
  309. show_pyc:=false
  310. show_py:=false
  311. f_round(_val, _decimals) =>
  312.  
  313. // Rounds _val to _decimals places.
  314. _p = math.pow(10, _decimals)
  315. math.round(math.abs(_val) * _p) / _p * math.sign(_val)
  316.  
  317.  
  318. /////////////////// LEVELS
  319.  
  320.  
  321. //////// DAY
  322.  
  323. if bool(nd) and show_pd
  324. // Create lines at previous day high/low
  325. _pdh := line.new(bar_index, pdh[1], bar_index, pdh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  326. _pdl := line.new(bar_index, pdl[1], bar_index, pdl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  327. line.delete(_pdh[1])
  328. line.delete(_pdl[1])
  329.  
  330. // Create labels at same previous day high/low price
  331. pdh_label := label.new(bar_index, pdh[1], ' PDH: ' + str.tostring(f_round(pdh[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  332. label.set_size(pdh_label, textsize1)
  333. label.set_textalign(pdh_label, text.align_left)
  334.  
  335. pdl_label := label.new(bar_index, pdl[1], ' PDL: ' + str.tostring(f_round(pdl[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  336. label.set_size(pdl_label, textsize1)
  337. label.set_textalign(pdl_label, text.align_left)
  338.  
  339. label.delete(pdh_label[1])
  340. label.delete(pdl_label[1])
  341.  
  342. if not barstate.islast
  343. if show_pd
  344. line.set_x2(_pdh, bar_index)
  345. line.set_x2(_pdl, bar_index)
  346. else
  347. if show_pd
  348. // Extend lines and move labels to the right with proper time coordinates
  349. line.set_xloc(_pdh, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  350. line.set_xloc(_pdl, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  351. label.set_xloc(pdh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  352. label.set_xloc(pdl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  353.  
  354. if bool(nd) and show_pdc and not crypto
  355. // Create lines at previous day high/low
  356. _pdc := line.new(bar_index, pdc[1], bar_index, pdc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
  357. line.delete(_pdc[1])
  358.  
  359. // Create labels at same previous day high/low price
  360. pdc_label := label.new(bar_index, pdc[1], ' PD CLOSE: ' + str.tostring(f_round(pdc[1], 2), '#.00'), style = label.style_none, textcolor = textcolor3, yloc = yloc.price, xloc = xloc.bar_index)
  361. label.set_size(pdc_label, textsize3)
  362. label.set_textalign(pdc_label, text.align_left)
  363.  
  364. label.delete(pdc_label[1])
  365.  
  366. if not barstate.islast
  367. if show_pdc
  368. line.set_x2(_pdc, bar_index)
  369. else
  370. if show_pdc
  371. // Extend lines and move labels to the right with proper time coordinates
  372. line.set_xloc(_pdc, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  373. label.set_xloc(pdc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  374.  
  375. //////// WEEK
  376.  
  377. if bool(nw) and show_pw
  378. // Create lines at previous day high/low
  379. _pwh := line.new(bar_index, pwh[1], bar_index, pwh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  380. _pwl := line.new(bar_index, pwl[1], bar_index, pwl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  381. line.delete(_pwh[1])
  382. line.delete(_pwl[1])
  383.  
  384. // Create labels at same previous day high/low price
  385. pwh_label := label.new(bar_index, pwh[1], ' PWH: ' + str.tostring(f_round(pwh[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  386. label.set_size(pwh_label, textsize1)
  387. label.set_textalign(pwh_label, text.align_left)
  388.  
  389. pwl_label := label.new(bar_index, pwl[1], ' PWL: ' + str.tostring(f_round(pwl[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  390. label.set_size(pwl_label, textsize1)
  391. label.set_textalign(pwl_label, text.align_left)
  392.  
  393. label.delete(pwh_label[1])
  394. label.delete(pwl_label[1])
  395.  
  396. if not barstate.islast
  397. if show_pw
  398. line.set_x2(_pwh, bar_index)
  399. line.set_x2(_pwl, bar_index)
  400. else
  401. if show_pw
  402. // Extend lines and move labels to the right with proper time coordinates
  403. line.set_xloc(_pwh, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  404. line.set_xloc(_pwl, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  405. label.set_xloc(pwh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  406. label.set_xloc(pwl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  407.  
  408. if bool(nw) and show_pwc and not crypto
  409. // Create lines at previous day high/low
  410. _pwc := line.new(bar_index, pwc[1], bar_index, pwc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
  411. line.delete(_pwc[1])
  412.  
  413. // Create labels at same previous day high/low price
  414. pwc_label := label.new(bar_index, pwc[1], ' PW CLOSE: ' + str.tostring(f_round(pwc[1], 2), '#.00'), style = label.style_none, textcolor = textcolor3, yloc = yloc.price, xloc = xloc.bar_index)
  415. label.set_size(pwc_label, textsize3)
  416. label.set_textalign(pwc_label, text.align_left)
  417.  
  418. label.delete(pwc_label[1])
  419.  
  420. if not barstate.islast
  421. if show_pwc
  422. line.set_x2(_pwc, bar_index)
  423. else
  424. if show_pwc
  425. // Extend lines and move labels to the right with proper time coordinates
  426. line.set_xloc(_pwc, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  427. label.set_xloc(pwc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  428.  
  429.  
  430.  
  431. //////// MONTH
  432.  
  433. if bool(nm) and show_pm
  434. // Create lines at previous day high/low
  435. _pmh := line.new(bar_index, pmh[1], bar_index, pmh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  436. _pml := line.new(bar_index, pml[1], bar_index, pml[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  437. line.delete(_pmh[1])
  438. line.delete(_pml[1])
  439.  
  440. // Create labels at same previous day high/low price
  441. pmh_label := label.new(bar_index, pmh[1], ' PMH: ' + str.tostring(f_round(pmh[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  442. label.set_size(pmh_label, textsize1)
  443. label.set_textalign(pmh_label, text.align_left)
  444.  
  445. pml_label := label.new(bar_index, pml[1], ' PML: ' + str.tostring(f_round(pml[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  446. label.set_size(pml_label, textsize1)
  447. label.set_textalign(pml_label, text.align_left)
  448.  
  449. label.delete(pmh_label[1])
  450. label.delete(pml_label[1])
  451.  
  452. if not barstate.islast
  453. if show_pm
  454. line.set_x2(_pmh, bar_index)
  455. line.set_x2(_pml, bar_index)
  456. else
  457. if show_pm
  458. // Extend lines and move labels to the right with proper time coordinates
  459. line.set_xloc(_pmh, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  460. line.set_xloc(_pml, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  461. label.set_xloc(pmh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  462. label.set_xloc(pml_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  463.  
  464. if bool(nm) and show_pmc and not crypto
  465. // Create lines at previous day high/low
  466. _pmc := line.new(bar_index, pmc[1], bar_index, pmc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
  467. line.delete(_pmc[1])
  468.  
  469. // Create labels at same previous day high/low price
  470. pmc_label := label.new(bar_index, pmc[1], ' PM CLOSE: ' + str.tostring(f_round(pmc[1], 2), '#.00'), style = label.style_none, textcolor = textcolor3, yloc = yloc.price, xloc = xloc.bar_index)
  471. label.set_size(pmc_label, textsize3)
  472. label.set_textalign(pmc_label, text.align_left)
  473.  
  474. label.delete(pmc_label[1])
  475.  
  476. if not barstate.islast
  477. if show_pmc
  478. line.set_x2(_pmc, bar_index)
  479. else
  480. if show_pmc
  481. // Extend lines and move labels to the right with proper time coordinates
  482. line.set_xloc(_pmc, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  483. label.set_xloc(pmc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  484.  
  485.  
  486. //////// QUARTER
  487. if bool(nq) and show_pq
  488. // Create lines at previous day high/low
  489. _pqh := line.new(bar_index, pqh[1], bar_index, pqh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  490. _pql := line.new(bar_index, pql[1], bar_index, pql[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  491. line.delete(_pqh[1])
  492. line.delete(_pql[1])
  493.  
  494. // Create labels at same previous day high/low price
  495. pqh_label := label.new(bar_index, pqh[1], ' PQH: ' + str.tostring(f_round(pqh[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  496. label.set_size(pqh_label, textsize1)
  497. label.set_textalign(pqh_label, text.align_left)
  498.  
  499. pql_label := label.new(bar_index, pql[1], ' PQL: ' + str.tostring(f_round(pql[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  500. label.set_size(pql_label, textsize1)
  501. label.set_textalign(pql_label, text.align_left)
  502.  
  503. label.delete(pqh_label[1])
  504. label.delete(pql_label[1])
  505.  
  506. if not barstate.islast
  507. if show_pq
  508. line.set_x2(_pqh, bar_index)
  509. line.set_x2(_pql, bar_index)
  510. else
  511. if show_pq
  512. // Extend lines and move labels to the right with proper time coordinates
  513. line.set_xloc(_pqh, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  514. line.set_xloc(_pql, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  515. label.set_xloc(pqh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  516. label.set_xloc(pql_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  517.  
  518. if bool(nq) and show_pqc and not crypto
  519. // Create lines at previous day high/low
  520. _pqc := line.new(bar_index, pqc[1], bar_index, pqc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
  521. line.delete(_pqc[1])
  522.  
  523. // Create labels at same previous day high/low price
  524. pqc_label := label.new(bar_index, pqc[1], ' PQ CLOSE: ' + str.tostring(f_round(pqc[1], 2), '#.00'), style = label.style_none, textcolor = textcolor3, yloc = yloc.price, xloc = xloc.bar_index)
  525. label.set_size(pqc_label, textsize3)
  526. label.set_textalign(pqc_label, text.align_left)
  527.  
  528. label.delete(pqc_label[1])
  529.  
  530. if not barstate.islast
  531. if show_pqc
  532. line.set_x2(_pqc, bar_index)
  533. else
  534. if show_pq
  535. // Extend lines and move labels to the right with proper time coordinates
  536. line.set_xloc(_pqc, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  537. label.set_xloc(pqc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  538.  
  539.  
  540. //////// YEAR
  541.  
  542. if bool(ny) and show_py
  543. // Create lines at previous day high/low
  544. _pyh := line.new(bar_index, pyh[1], bar_index, pyh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  545. _pyl := line.new(bar_index, pyl[1], bar_index, pyl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
  546. line.delete(_pyh[1])
  547. line.delete(_pyl[1])
  548.  
  549. // Create labels at same previous day high/low price
  550. pyh_label := label.new(bar_index, pyh[1], ' PYH: ' + str.tostring(f_round(pyh[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  551. label.set_size(pyh_label, textsize1)
  552. label.set_textalign(pyh_label, text.align_left)
  553.  
  554. pyl_label := label.new(bar_index, pyl[1], ' PYL: ' + str.tostring(f_round(pyl[1], 2), '#.00'), style = label.style_none, textcolor = textcolor1, yloc = yloc.price, xloc = xloc.bar_index)
  555. label.set_size(pyl_label, textsize1)
  556. label.set_textalign(pyl_label, text.align_left)
  557.  
  558. label.delete(pyh_label[1])
  559. label.delete(pyl_label[1])
  560.  
  561. if not barstate.islast
  562. if show_py
  563. line.set_x2(_pyh, bar_index)
  564. line.set_x2(_pyl, bar_index)
  565. else
  566. if show_py
  567. // Extend lines and move labels to the right with proper time coordinates
  568. line.set_xloc(_pyh, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  569. line.set_xloc(_pyl, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  570. label.set_xloc(pyh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  571. label.set_xloc(pyl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  572.  
  573.  
  574. if bool(ny) and show_pyc and not crypto
  575. // Create lines at previous day high/low
  576. _pyc := line.new(bar_index, pyc[1], bar_index, pyc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
  577. line.delete(_pyc[1])
  578.  
  579. // Create labels at same previous day high/low price
  580. pyc_label := label.new(bar_index, pyc[1], ' PY CLOSE: ' + str.tostring(f_round(pyc[1], 2), '#.00'), style = label.style_none, textcolor = textcolor3, yloc = yloc.price, xloc = xloc.bar_index)
  581. label.set_size(pyc_label, textsize3)
  582. label.set_textalign(pyc_label, text.align_left)
  583.  
  584. label.delete(pyc_label[1])
  585.  
  586. if not barstate.islast
  587. if show_pyc
  588. line.set_x2(_pyc, bar_index)
  589. else
  590. if show_pyc
  591. // Extend lines and move labels to the right with proper time coordinates
  592. line.set_xloc(_pyc, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  593. label.set_xloc(pyc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  594.  
  595.  
  596. /////////////////// OPENS
  597.  
  598.  
  599. //////// DAY
  600.  
  601. if show_do
  602. _do := line.new(x1 = bar_index, y1 = dyo, x2 = bar_index, y2 = dyo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
  603.  
  604. do_label := label.new(bar_index, y = dyo, text = tickertype == 'futures' ? ' ETH OPEN: ' + str.tostring(f_round(dyo, 2), '#.00'):' RTH OPEN: ' + str.tostring(f_round(dyo, 2), '#.00'), style = label.style_none, textcolor = textcolor2, yloc = yloc.price, xloc = xloc.bar_index)
  605. label.set_xloc(do_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  606. label.set_size(do_label, textsize2)
  607. label.set_textalign(do_label, text.align_left)
  608.  
  609. line.delete(_do[1])
  610. label.delete(do_label[1])
  611.  
  612. if not barstate.islast
  613. if show_do
  614. line.set_x2(_do, x = bar_index)
  615. else
  616. if show_do
  617. line.set_xloc(_do, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  618. label.set_xloc(do_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  619.  
  620.  
  621. //////// WEEK
  622.  
  623. if show_wo
  624. _wo := line.new(x1 = bar_index, y1 = wo, x2 = bar_index, y2 = wo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
  625.  
  626. wo_label := label.new(bar_index, y = wo, text = ' WEEK OPEN: ' + str.tostring(f_round(wo, 2), '#.00'), style = label.style_none, textcolor = textcolor2, yloc = yloc.price, xloc = xloc.bar_index)
  627. label.set_xloc(wo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  628. label.set_size(wo_label, textsize2)
  629. label.set_textalign(wo_label, text.align_left)
  630.  
  631. line.delete(_wo[1])
  632. label.delete(wo_label[1])
  633.  
  634. if not barstate.islast
  635. if show_wo
  636. line.set_x2(_wo, x = bar_index)
  637. else
  638. if show_wo
  639. line.set_xloc(_wo, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  640. label.set_xloc(wo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  641.  
  642.  
  643. //////// MONTH
  644.  
  645. if show_mo
  646. _mo := line.new(x1 = bar_index, y1 = mo, x2 = bar_index, y2 = mo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
  647.  
  648. mo_label := label.new(bar_index, y = mo, text = ' MONTH OPEN: ' + str.tostring(f_round(mo, 2), '#.00'), style = label.style_none, textcolor = textcolor2, yloc = yloc.price, xloc = xloc.bar_index)
  649. label.set_xloc(mo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  650. label.set_size(mo_label, textsize2)
  651. label.set_textalign(mo_label, text.align_left)
  652.  
  653. line.delete(_mo[1])
  654. label.delete(mo_label[1])
  655.  
  656. if not barstate.islast
  657. if show_mo
  658. line.set_x2(_mo, x = bar_index)
  659. else
  660. if show_mo
  661. line.set_xloc(_mo, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  662. label.set_xloc(mo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  663.  
  664.  
  665. //////// QUARTER
  666.  
  667. if show_qo
  668. _qo := line.new(x1 = bar_index, y1 = qo, x2 = bar_index, y2 = qo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
  669.  
  670. qo_label := label.new(bar_index, y = qo, text = ' QUARTER OPEN: ' + str.tostring(f_round(qo, 2), '#.00'), style = label.style_none, textcolor = textcolor2, yloc = yloc.price, xloc = xloc.bar_index)
  671. label.set_xloc(qo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  672. label.set_size(qo_label, textsize2)
  673. label.set_textalign(qo_label, text.align_left)
  674.  
  675. line.delete(_qo[1])
  676. label.delete(qo_label[1])
  677.  
  678. if not barstate.islast
  679. if show_qo
  680. line.set_x2(_qo, x = bar_index)
  681. else
  682. if show_qo
  683. line.set_xloc(_qo, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  684. label.set_xloc(qo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  685.  
  686.  
  687. //////// YEAR
  688.  
  689. if show_yo
  690. _yo := line.new(x1 = bar_index, y1 = yo, x2 = bar_index, y2 = yo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
  691.  
  692. line.delete(_yo[1])
  693.  
  694. yo_label := label.new(bar_index, y = yo, text = ' YEAR OPEN: ' + str.tostring(f_round(yo, 2), '#.00'), style = label.style_none, textcolor = textcolor2, yloc = yloc.price, xloc = xloc.bar_index)
  695. //label.set_xloc(yo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  696. label.set_size(yo_label, textsize2)
  697. label.set_textalign(yo_label, text.align_left)
  698.  
  699. label.delete(yo_label[1])
  700.  
  701. if not barstate.islast
  702. if show_yo
  703. line.set_x2(_yo, x = bar_index)
  704. else
  705. if show_yo
  706. line.set_xloc(_yo, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
  707. label.set_xloc(yo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
  708.  
Advertisement
Add Comment
Please, Sign In to add comment