Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © taylorbray
- // NOTES
- // Add ETH open, RTH open, RTH close, ETH close
- // - could use ticker.new(x, x, session) to call specific req.sec from certain sessions
- //
- //
- //@version=6
- indicator('Auto Levels', overlay = true, precision = 2, max_bars_back = 5000)
- //////////////////////////////////// CLOSE PRICE
- prevcolor = input.color(defval = #808080c4, title = 'Level Color', group = 'APPEARANCE SETTINGS')
- textcolor1 = input.color(defval = #808080c4, title = 'Text Color', group = 'APPEARANCE SETTINGS')
- linetype1 = input.string(defval = 'Solid', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
- textsizeinput1 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
- tickertype = ''
- if syminfo.type == 'futures'
- tickertype := 'futures'
- if syminfo.type == 'stock'
- tickertype := 'stock'
- if syminfo.type == 'crypto'
- tickertype := 'crypto'
- linestyle1 = line.style_solid
- textsize1 = size.small
- if linetype1 == 'Solid'
- linestyle1 := line.style_solid
- else if linetype1 == 'Dashed'
- linestyle1 := line.style_dashed
- else if linetype1 == 'Dotted'
- linestyle1 := line.style_dotted
- if textsizeinput1 == 'Tiny'
- textsize1 := size.tiny
- else if textsizeinput1 == 'Small'
- textsize1 := size.small
- else if textsizeinput1 == 'Normal'
- textsize1 := size.normal
- else if textsizeinput1 == 'Large'
- textsize1 := size.large
- else if textsizeinput1 == 'Huge'
- textsize1 := size.huge
- else if textsizeinput1 == 'auto'
- textsize1 := size.auto
- opencolor = input.color(defval = #e679a6bb, title = 'Open Color', group = 'APPEARANCE SETTINGS')
- textcolor2 = input.color(defval = #e679a6bb, title = 'Text Color', group = 'APPEARANCE SETTINGS')
- linetype2 = input.string(defval = 'Dotted', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
- textsizeinput2 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
- linestyle2 = line.style_dotted
- textsize2 = size.small
- if linetype2 == 'Solid'
- linestyle2 := line.style_solid
- else if linetype2 == 'Dashed'
- linestyle2 := line.style_dashed
- else if linetype2 == 'Dotted'
- linestyle2 := line.style_dotted
- if textsizeinput2 == 'Tiny'
- textsize2 := size.tiny
- else if textsizeinput2 == 'Small'
- textsize2 := size.small
- else if textsizeinput2 == 'Normal'
- textsize2 := size.normal
- else if textsizeinput2 == 'Large'
- textsize2 := size.large
- else if textsizeinput2 == 'Huge'
- textsizeinput2 := size.huge
- else if textsizeinput2 == 'auto'
- textsize2 := size.auto
- closecolor = input.color(defval = #d68915bb, title = 'Close Color', group = 'APPEARANCE SETTINGS')
- textcolor3 = input.color(defval = #d68915bb, title = 'Text Color', group = 'APPEARANCE SETTINGS')
- linetype3= input.string(defval = 'Dotted', title = 'Line Style', options = ['Solid', 'Dotted', 'Dashed'], group = 'APPEARANCE SETTINGS')
- textsizeinput3 = input.string(defval = 'Small', title = 'Level Text Size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge', 'auto'], group = 'APPEARANCE SETTINGS')
- linestyle3 = line.style_dotted
- textsize3 = size.small
- auto_offset = input.bool(true, 'Auto-adjust line extend length', tooltip = 'Automatically changes the line-extend length based on the selected timeframe', group = 'OPTIONS')
- ticker.standard(syminfo.tickerid)
- //////////////////////////////////// PWH/PWL + PDH/PDL
- /////////////////// SETTINGS
- show_pdc = input.bool(true, 'Show PD Close', group = 'DAY')
- show_pd = input.bool(true, 'Show PDH/PDL', group = 'DAY')
- show_do = input.bool(true, 'Show Day Open', group = 'DAY')
- show_pwc = input.bool(true, 'Show PW Close', group = 'WEEK')
- show_pw = input.bool(true, 'Show PWH/PWL', group = 'WEEK')
- show_wo = input.bool(true, 'Show Week Open', group = 'WEEK')
- show_pmc = input.bool(true, 'Show PM Close', group = 'MONTH')
- show_pm = input.bool(true, 'Show PMH/PML', group = 'MONTH')
- show_mo = input.bool(true, 'Show Month Open', group = 'MONTH')
- show_pqc = input.bool(true, 'Show PQ Close', group = 'QUARTER')
- show_pq = input.bool(true, 'Show PQH/PQL', group = 'QUARTER')
- show_qo = input.bool(true, 'Show Quarter Open', group = 'QUARTER')
- show_pyc = input.bool(true, 'Show PY Close', group = 'YEAR')
- show_py = input.bool(true, 'Show PYH/PYL', group = 'YEAR')
- show_yo = input.bool(true, 'Show Year Open', group = 'YEAR')
- crypto = false
- if syminfo.type == 'Spot crypto' or syminfo.type == 'Spot crypto defi'
- crypto := true
- else
- crypto := false
- /////////////////// VARIABLES & ASSINGMENTS
- condition = not(timeframe.isweekly or timeframe.ismonthly)
- float yo = request.security(ticker.standard(syminfo.tickerid), '12M', open)
- float qo = request.security(ticker.standard(syminfo.tickerid), '3M', open)
- float mo = request.security(ticker.standard(syminfo.tickerid), 'M', open)
- float wo = request.security(ticker.standard(syminfo.tickerid), 'W', open)
- float dyo = request.security(ticker.standard(syminfo.tickerid), 'D', open)
- float pyh = request.security(ticker.standard(syminfo.tickerid), '12M', high)
- float pyl = request.security(ticker.standard(syminfo.tickerid), '12M', low)
- float pyc = request.security(ticker.standard(syminfo.tickerid), '12M', close)
- float pqh = request.security(ticker.standard(syminfo.tickerid), '3M', high)
- float pql = request.security(ticker.standard(syminfo.tickerid), '3M', low )
- float pqc = request.security(ticker.standard(syminfo.tickerid), '3M', close )
- float pmh = request.security(ticker.standard(syminfo.tickerid), 'M', high )
- float pml = request.security(ticker.standard(syminfo.tickerid), 'M', low )
- float pmc = request.security(ticker.standard(syminfo.tickerid), 'M', close )
- float pwh = request.security(ticker.standard(syminfo.tickerid), 'W', high )
- float pwl = request.security(ticker.standard(syminfo.tickerid), 'W', low )
- float pwc = request.security(ticker.standard(syminfo.tickerid), 'W', close )
- float pdh = request.security(ticker.standard(syminfo.tickerid), 'D', high )
- float pdl = request.security(ticker.standard(syminfo.tickerid), 'D', low )
- float pdc = request.security(ticker.standard(syminfo.tickerid), 'D', close )
- nw = ta.change(time('W'))
- nd = ta.change(time('D'))
- nm = ta.change(time('M'))
- nq = ta.change(time('3M'))
- ny = ta.change(time('12M'))
- max_bars_back(time, 5000)
- _ycount = ta.barssince(bool(ny))
- _qcount = ta.barssince(bool(nq))
- _mcount = ta.barssince(bool(nm))
- _wcount = ta.barssince(bool(nw))
- _dcount = ta.barssince(bool(nd))
- var line _pyh = na
- var line _pyl = na
- var line _pyc = na
- var line _pqh = na
- var line _pql = na
- var line _pqc = na
- var line _pmh = na
- var line _pml = na
- var line _pmc = na
- var line _pwh = na
- var line _pwl = na
- var line _pwc = na
- var line _pdh = na
- var line _pdl = na
- var line _pdc = na
- var line _yo = na
- var line _qo = na
- var line _mo = na
- var line _wo = na
- var line _do = na
- var label pyh_label = na
- var label pyl_label = na
- var label pyc_label = na
- var label pqh_label = na
- var label pql_label = na
- var label pqc_label = na
- var label pmh_label = na
- var label pml_label = na
- var label pmc_label = na
- var label pwh_label = na
- var label pwl_label = na
- var label pwc_label = na
- var label pdh_label = na
- var label pdl_label = na
- var label pdc_label = na
- var label yo_label = na
- var label qo_label = na
- var label mo_label = na
- var label wo_label = na
- var label do_label = na
- offsetvalinput = input.int(20, 'Line-Extend Length', group = 'SETTINGS')
- offsetmult = input.int(10, 'Auto-Extend Multiplier', group = 'SETTINGS')
- int offsetval = 0
- timeframe = timeframe.period
- if auto_offset == false
- offsetval := offsetvalinput * 200 // idk
- if auto_offset == true
- if timeframe == '1D'
- offsetval := offsetvalinput * 500
- show_do:=false
- show_pdc:=false
- show_pd:=false
- if timeframe == '1W'
- offsetval := offsetvalinput * 1700
- show_do:=false
- show_pdc:=false
- show_pd:=false
- show_wo:=false
- show_pwc:=false
- show_pw:=false
- if timeframe == '1M'
- offsetval := offsetvalinput * 8000
- show_do:=false
- show_pdc:=false
- show_pd:=false
- show_wo:=false
- show_pwc:=false
- show_pw:=false
- show_mo:=false
- show_pmc:=false
- show_pm:=false
- if timeframe == "720"
- offsetval := offsetmult * 5000
- show_do:=false
- show_pd:=false
- if timeframe == "480" or timeframe== "240"
- offsetval := offsetmult * 2500
- if timeframe == "120" or timeframe == "60"
- offsetval := offsetmult * 200
- if timeframe== "45" or timeframe == "30"
- offsetval :=offsetmult * 70
- show_yo:=false
- show_pyc:=false
- show_py:=false
- if timeframe == "15" or timeframe == "10"
- offsetval := offsetmult * 50
- show_mo:=false
- show_pmc:=false
- show_pm:=false
- show_qo:=false
- show_pqc:=false
- show_pq:=false
- show_yo:=false
- show_pyc:=false
- show_py:=false
- if timeframe== "5" or timeframe == "3"
- offsetval := offsetmult * 35
- show_mo:=false
- show_pmc:=false
- show_pm:=false
- show_qo:=false
- show_pqc:=false
- show_pq:=false
- show_yo:=false
- show_pyc:=false
- show_py:=false
- if timeframe == "1"
- offsetval := offsetmult * 10
- show_wo:=false
- show_pwc:=false
- show_pw:=false
- show_mo:=false
- show_pmc:=false
- show_pm:=false
- show_qo:=false
- show_pqc:=false
- show_pq:=false
- show_yo:=false
- show_pyc:=false
- show_py:=false
- f_round(_val, _decimals) =>
- // Rounds _val to _decimals places.
- _p = math.pow(10, _decimals)
- math.round(math.abs(_val) * _p) / _p * math.sign(_val)
- /////////////////// LEVELS
- //////// DAY
- if bool(nd) and show_pd
- // Create lines at previous day high/low
- _pdh := line.new(bar_index, pdh[1], bar_index, pdh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- _pdl := line.new(bar_index, pdl[1], bar_index, pdl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- line.delete(_pdh[1])
- line.delete(_pdl[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pdh_label, textsize1)
- label.set_textalign(pdh_label, text.align_left)
- 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)
- label.set_size(pdl_label, textsize1)
- label.set_textalign(pdl_label, text.align_left)
- label.delete(pdh_label[1])
- label.delete(pdl_label[1])
- if not barstate.islast
- if show_pd
- line.set_x2(_pdh, bar_index)
- line.set_x2(_pdl, bar_index)
- else
- if show_pd
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pdh, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- line.set_xloc(_pdl, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pdh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pdl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- if bool(nd) and show_pdc and not crypto
- // Create lines at previous day high/low
- _pdc := line.new(bar_index, pdc[1], bar_index, pdc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
- line.delete(_pdc[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pdc_label, textsize3)
- label.set_textalign(pdc_label, text.align_left)
- label.delete(pdc_label[1])
- if not barstate.islast
- if show_pdc
- line.set_x2(_pdc, bar_index)
- else
- if show_pdc
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pdc, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pdc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// WEEK
- if bool(nw) and show_pw
- // Create lines at previous day high/low
- _pwh := line.new(bar_index, pwh[1], bar_index, pwh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- _pwl := line.new(bar_index, pwl[1], bar_index, pwl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- line.delete(_pwh[1])
- line.delete(_pwl[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pwh_label, textsize1)
- label.set_textalign(pwh_label, text.align_left)
- 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)
- label.set_size(pwl_label, textsize1)
- label.set_textalign(pwl_label, text.align_left)
- label.delete(pwh_label[1])
- label.delete(pwl_label[1])
- if not barstate.islast
- if show_pw
- line.set_x2(_pwh, bar_index)
- line.set_x2(_pwl, bar_index)
- else
- if show_pw
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pwh, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- line.set_xloc(_pwl, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pwh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pwl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- if bool(nw) and show_pwc and not crypto
- // Create lines at previous day high/low
- _pwc := line.new(bar_index, pwc[1], bar_index, pwc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
- line.delete(_pwc[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pwc_label, textsize3)
- label.set_textalign(pwc_label, text.align_left)
- label.delete(pwc_label[1])
- if not barstate.islast
- if show_pwc
- line.set_x2(_pwc, bar_index)
- else
- if show_pwc
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pwc, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pwc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// MONTH
- if bool(nm) and show_pm
- // Create lines at previous day high/low
- _pmh := line.new(bar_index, pmh[1], bar_index, pmh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- _pml := line.new(bar_index, pml[1], bar_index, pml[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- line.delete(_pmh[1])
- line.delete(_pml[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pmh_label, textsize1)
- label.set_textalign(pmh_label, text.align_left)
- 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)
- label.set_size(pml_label, textsize1)
- label.set_textalign(pml_label, text.align_left)
- label.delete(pmh_label[1])
- label.delete(pml_label[1])
- if not barstate.islast
- if show_pm
- line.set_x2(_pmh, bar_index)
- line.set_x2(_pml, bar_index)
- else
- if show_pm
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pmh, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- line.set_xloc(_pml, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pmh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pml_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- if bool(nm) and show_pmc and not crypto
- // Create lines at previous day high/low
- _pmc := line.new(bar_index, pmc[1], bar_index, pmc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
- line.delete(_pmc[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pmc_label, textsize3)
- label.set_textalign(pmc_label, text.align_left)
- label.delete(pmc_label[1])
- if not barstate.islast
- if show_pmc
- line.set_x2(_pmc, bar_index)
- else
- if show_pmc
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pmc, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pmc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// QUARTER
- if bool(nq) and show_pq
- // Create lines at previous day high/low
- _pqh := line.new(bar_index, pqh[1], bar_index, pqh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- _pql := line.new(bar_index, pql[1], bar_index, pql[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- line.delete(_pqh[1])
- line.delete(_pql[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pqh_label, textsize1)
- label.set_textalign(pqh_label, text.align_left)
- 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)
- label.set_size(pql_label, textsize1)
- label.set_textalign(pql_label, text.align_left)
- label.delete(pqh_label[1])
- label.delete(pql_label[1])
- if not barstate.islast
- if show_pq
- line.set_x2(_pqh, bar_index)
- line.set_x2(_pql, bar_index)
- else
- if show_pq
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pqh, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- line.set_xloc(_pql, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pqh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pql_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- if bool(nq) and show_pqc and not crypto
- // Create lines at previous day high/low
- _pqc := line.new(bar_index, pqc[1], bar_index, pqc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
- line.delete(_pqc[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pqc_label, textsize3)
- label.set_textalign(pqc_label, text.align_left)
- label.delete(pqc_label[1])
- if not barstate.islast
- if show_pqc
- line.set_x2(_pqc, bar_index)
- else
- if show_pq
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pqc, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pqc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// YEAR
- if bool(ny) and show_py
- // Create lines at previous day high/low
- _pyh := line.new(bar_index, pyh[1], bar_index, pyh[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- _pyl := line.new(bar_index, pyl[1], bar_index, pyl[1], color = prevcolor, style = linestyle1, width = 1, extend = extend.none)
- line.delete(_pyh[1])
- line.delete(_pyl[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pyh_label, textsize1)
- label.set_textalign(pyh_label, text.align_left)
- 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)
- label.set_size(pyl_label, textsize1)
- label.set_textalign(pyl_label, text.align_left)
- label.delete(pyh_label[1])
- label.delete(pyl_label[1])
- if not barstate.islast
- if show_py
- line.set_x2(_pyh, bar_index)
- line.set_x2(_pyl, bar_index)
- else
- if show_py
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pyh, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- line.set_xloc(_pyl, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pyh_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pyl_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- if bool(ny) and show_pyc and not crypto
- // Create lines at previous day high/low
- _pyc := line.new(bar_index, pyc[1], bar_index, pyc[1], color = closecolor, style = linestyle3, width = 1, extend = extend.none)
- line.delete(_pyc[1])
- // Create labels at same previous day high/low price
- 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)
- label.set_size(pyc_label, textsize3)
- label.set_textalign(pyc_label, text.align_left)
- label.delete(pyc_label[1])
- if not barstate.islast
- if show_pyc
- line.set_x2(_pyc, bar_index)
- else
- if show_pyc
- // Extend lines and move labels to the right with proper time coordinates
- line.set_xloc(_pyc, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(pyc_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- /////////////////// OPENS
- //////// DAY
- if show_do
- _do := line.new(x1 = bar_index, y1 = dyo, x2 = bar_index, y2 = dyo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
- 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)
- label.set_xloc(do_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_size(do_label, textsize2)
- label.set_textalign(do_label, text.align_left)
- line.delete(_do[1])
- label.delete(do_label[1])
- if not barstate.islast
- if show_do
- line.set_x2(_do, x = bar_index)
- else
- if show_do
- line.set_xloc(_do, x1 = time[_dcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(do_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// WEEK
- if show_wo
- _wo := line.new(x1 = bar_index, y1 = wo, x2 = bar_index, y2 = wo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
- 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)
- label.set_xloc(wo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_size(wo_label, textsize2)
- label.set_textalign(wo_label, text.align_left)
- line.delete(_wo[1])
- label.delete(wo_label[1])
- if not barstate.islast
- if show_wo
- line.set_x2(_wo, x = bar_index)
- else
- if show_wo
- line.set_xloc(_wo, x1 = time[_wcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(wo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// MONTH
- if show_mo
- _mo := line.new(x1 = bar_index, y1 = mo, x2 = bar_index, y2 = mo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
- 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)
- label.set_xloc(mo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_size(mo_label, textsize2)
- label.set_textalign(mo_label, text.align_left)
- line.delete(_mo[1])
- label.delete(mo_label[1])
- if not barstate.islast
- if show_mo
- line.set_x2(_mo, x = bar_index)
- else
- if show_mo
- line.set_xloc(_mo, x1 = time[_mcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(mo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// QUARTER
- if show_qo
- _qo := line.new(x1 = bar_index, y1 = qo, x2 = bar_index, y2 = qo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
- 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)
- label.set_xloc(qo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_size(qo_label, textsize2)
- label.set_textalign(qo_label, text.align_left)
- line.delete(_qo[1])
- label.delete(qo_label[1])
- if not barstate.islast
- if show_qo
- line.set_x2(_qo, x = bar_index)
- else
- if show_qo
- line.set_xloc(_qo, x1 = time[_qcount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(qo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- //////// YEAR
- if show_yo
- _yo := line.new(x1 = bar_index, y1 = yo, x2 = bar_index, y2 = yo, color = opencolor, style = linestyle2, width = 1, extend = extend.none)
- line.delete(_yo[1])
- 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)
- //label.set_xloc(yo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_size(yo_label, textsize2)
- label.set_textalign(yo_label, text.align_left)
- label.delete(yo_label[1])
- if not barstate.islast
- if show_yo
- line.set_x2(_yo, x = bar_index)
- else
- if show_yo
- line.set_xloc(_yo, x1 = time[_ycount + 1], x2 = time_close + offsetval * 40000, xloc = xloc.bar_time)
- label.set_xloc(yo_label, x = time_close + offsetval * 40000, xloc = xloc.bar_time)
Advertisement
Add Comment
Please, Sign In to add comment