//@version=5 indicator(title='Prev IG HLC', shorttitle='IG HLC', overlay=true) //last working version 150 cont = input.bool(defval=true, title='Use continuous contract values (futures only)') disp_d = input.bool(true, title='Display Daily IG HLC Levels') disp_w = input(true, title='Display Weekly IG HLC Levels') disp_m = input(true, title='Display Monthly IG HLC Levels') track = input.bool(defval = true, title='Show Horizontal Price tracking lines', group='MORE SETTINGS') showLabels = input.bool(defval=true, title='Show Custom Labels', inline='labels', group='MORE SETTINGS') l_size = input.string('small', options=['auto', 'tiny', 'small', 'normal', 'large', 'huge'], title='- size', inline='labels', group='MORE SETTINGS') col_lab_day = input.color(title='Daily Labels', defval=color.blue, inline='collab', group='MORE SETTINGS') col_lab_week = input.color(title='Weekly', defval=color.green, inline='collab', group='MORE SETTINGS') col_lab_month = input.color(title='Monthly', defval=color.fuchsia, inline='collab', group='MORE SETTINGS') display_value = input.bool(true, title='Show Price Values in Labels', group='MORE SETTINGS') nbarsforward = input.int(title='Offset labels N bars to the right', defval=20, group='MORE SETTINGS') //use continuous contract var sym_name = syminfo.type == 'futures' and cont ? syminfo.root + '1!' : syminfo.tickerid // Rounding levels to min tick nround(x) => n = math.round(x / syminfo.mintick) * syminfo.mintick n //VARIABLES //p in the prefix implies previous //m,w,d in the prefix implies daily weekly monthly pdhigh = disp_d and timeframe.isintraday ? request.security(sym_name, 'D', high[1], lookahead=barmerge.lookahead_on) : na pdlow = disp_d and timeframe.isintraday ? request.security(sym_name, 'D', low[1], lookahead=barmerge.lookahead_on) : na pdclose = disp_d and timeframe.isintraday ? request.security(sym_name, 'D', close[1], lookahead=barmerge.lookahead_on) : na pdopen = disp_d and timeframe.isintraday ? request.security(sym_name, 'D', open[1], lookahead=barmerge.lookahead_on) : na pdmid = (pdhigh + pdlow)/2 pwhigh = disp_w ? request.security(sym_name, 'W', high[1], lookahead=barmerge.lookahead_on) : na pwlow = disp_w ? request.security(sym_name, 'W', low[1], lookahead=barmerge.lookahead_on) : na pwclose = disp_w ? request.security(sym_name, 'W', close[1], lookahead=barmerge.lookahead_on) : na pwopen = disp_w ? request.security(sym_name, 'W', open[1], lookahead=barmerge.lookahead_on) : na pwmid = (pwhigh + pwlow)/2 pmhigh = disp_m ? request.security(sym_name, 'M', high[1], lookahead=barmerge.lookahead_on) : na pmlow = disp_m ? request.security(sym_name, 'M', low[1], lookahead=barmerge.lookahead_on) : na pmclose = disp_m ? request.security(sym_name, 'M', close[1], lookahead=barmerge.lookahead_on) : na pmopen = disp_m ? request.security(sym_name, 'M', open[1], lookahead=barmerge.lookahead_on) : na pmmid = (pmhigh + pmlow)/2 //current IG HLC values will not be plotted for previous days, weeks or months, only in current periods day_cur = dayofmonth(time) == dayofmonth(last_bar_time) week_cur = weekofyear(time) == weekofyear(last_bar_time) month_cur = month(time) == month(last_bar_time) dhigh = day_cur and disp_d and timeframe.isintraday ? request.security(sym_name, 'D', high, lookahead=barmerge.lookahead_on) : na dlow = day_cur and disp_d and timeframe.isintraday ? request.security(sym_name, 'D', low, lookahead=barmerge.lookahead_on) : na dopen = day_cur and disp_d and timeframe.isintraday ? request.security(sym_name, 'D', open, lookahead=barmerge.lookahead_on) : na dmid = (dhigh + dlow)/2 whigh = week_cur and disp_w ? request.security(sym_name, 'W', high, lookahead=barmerge.lookahead_on) : na wlow = week_cur and disp_w ? request.security(sym_name, 'W', low, lookahead=barmerge.lookahead_on) : na wopen = week_cur and disp_w ? request.security(sym_name, 'W', open, lookahead=barmerge.lookahead_on) : na wmid = (whigh + wlow)/2 mhigh = month_cur and disp_m ? request.security(sym_name, 'M', high, lookahead=barmerge.lookahead_on) : na mlow = month_cur and disp_m ? request.security(sym_name, 'M', low, lookahead=barmerge.lookahead_on) : na mopen = month_cur and disp_m ? request.security(sym_name, 'M', open, lookahead=barmerge.lookahead_on) : na mmid = (mhigh + mlow) / 2 //set current HiLo values to na if they equal higher timeframe values dhigh := dhigh != whigh and dhigh != mhigh ? dhigh : na dlow := dlow != wlow and dlow != mlow ? dlow : na whigh := whigh != mhigh ? whigh : na wlow := wlow != mlow ? wlow : na //PLOTS //today's plots plot(dopen == dopen[1] ? dopen : na, color=color.new(color.blue, 40), title = 'OPEN', style = plot.style_cross, linewidth = 1, trackprice = track) plot(dhigh == dhigh[1] ? dhigh : na, color=color.new(color.blue, 40), title = 'HIGH', style = plot.style_cross, linewidth = 1, trackprice = track) plot(dlow == dlow[1] ? dlow : na, color=color.new(color.blue, 40), title = 'LOW', style = plot.style_cross, linewidth = 1, trackprice = track) plot(dmid == dmid[1] ? dmid : na, color=color.new(color.blue, 40), title = 'MID', style = plot.style_cross, linewidth = 1, trackprice = track) //this week's plots plot(wopen == wopen[1] ? wopen : na, color=color.new(color.green, 40), title = 'W.OPEN', style = plot.style_cross, linewidth = 2, trackprice = track) plot(whigh == whigh[1] ? whigh : na, color=color.new(color.green, 40), title = 'W.HIGH', style = plot.style_cross, linewidth = 2, trackprice = track) plot(wlow == wlow[1] ? wlow : na, color=color.new(color.green, 40), title = 'W.LOW', style = plot.style_cross, linewidth = 2, trackprice = track) plot(wmid == wmid[1] ? wmid : na, color=color.new(color.green, 40), title = 'W.MID', style = plot.style_cross, linewidth = 2, trackprice = track) //this month's plots plot(mopen == mopen[1] ? mopen : na, color=color.new(color.fuchsia, 40), title = 'M.OPEN', style = plot.style_cross, linewidth = 2, trackprice = track) plot(mhigh == mhigh[1] ? mhigh : na, color=color.new(color.fuchsia, 40), title = 'M.HIGH', style = plot.style_cross, linewidth = 2, trackprice = track) plot(mlow == mlow[1] ? mlow : na, color=color.new(color.fuchsia, 40), title = 'M.LOW', style = plot.style_cross, linewidth = 2, trackprice = track) plot(mmid == mmid[1] ? mmid : na, color=color.new(color.fuchsia, 40), title = 'M.MID', style = plot.style_cross, linewidth = 1, trackprice = track) //yesterday's plots plot(pdopen == pdopen[1] ? pdopen : na, color=color.blue, title = 'y.OP', style = plot.style_cross, linewidth = 1, trackprice = track) plot(pdhigh == pdhigh[1] ? pdhigh : na, color=color.blue, title = 'y.HI', style = plot.style_cross, linewidth = 1, trackprice = track) plot(pdlow == pdlow[1] ? pdlow : na, color=color.blue, title = 'y.LO', style = plot.style_cross, linewidth = 1, trackprice = track) plot(pdclose == pdclose[1] ? pdclose : na, color=color.blue, title = 'y.CL', style = plot.style_cross, linewidth = 1, trackprice = track) plot(pdmid == pdmid[1] ? pdmid : na, color=color.blue, title = 'y.MID', style = plot.style_cross, linewidth = 1, trackprice = track) //last week's plots plot(pwopen == pwopen[1] ? pwopen : na, color=color.green, title = 'last.W.OP', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pwhigh == pwhigh[1] ? pwhigh : na, color=color.green, title = 'last.W.HI', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pwlow == pwlow[1] ? pwlow : na, color=color.green, title = 'last.W.LO', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pwclose == pwclose[1] ? pwclose : na, color=color.green, title = 'last.W.CL', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pwmid == pwmid[1] ? pwmid : na, color=color.green, title = 'last.W.MID', style = plot.style_cross, linewidth = 2, trackprice = track) //last week's plots plot(pmopen == pmopen[1] ? pmopen : na, color=color.fuchsia, title = 'last.M.OP', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pmhigh == pmhigh[1] ? pmhigh : na, color=color.fuchsia, title = 'last.M.HI', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pmlow == pmlow[1] ? pmlow : na, color=color.fuchsia, title = 'last.M.LO', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pmclose == pmclose[1] ? pmclose : na, color=color.fuchsia, title = 'last.M.CL', style = plot.style_cross, linewidth = 2, trackprice = track) plot(pmmid == pmmid[1] ? pmmid : na, color=color.fuchsia, title = 'last.M.MID', style = plot.style_cross, linewidth = 2, trackprice = track) //LABELS //create labels in last bar and update its position if barstate.islast and showLabels //yersterday's labels var lab_pdo = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, pdopen, xloc=xloc.bar_index, text= 'y.OP', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_pdh = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, pdhigh, xloc=xloc.bar_index, text= 'y.HI', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_pdl = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, pdlow, xloc=xloc.bar_index, text= 'y.LO', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_pdc = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, pdclose, xloc=xloc.bar_index, text= 'y.CL', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_pdm = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, pdmid, xloc=xloc.bar_index, text= 'y.MID', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na //last week's labels var lab_pwo = disp_w ? label.new(bar_index + nbarsforward, pwopen, xloc=xloc.bar_index, text= 'last.W.OP', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_pwh = disp_w ? label.new(bar_index + nbarsforward, pwhigh, xloc=xloc.bar_index, text= 'last.W.HI', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_pwl = disp_w ? label.new(bar_index + nbarsforward, pwlow, xloc=xloc.bar_index, text= 'last.W.LO', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_pwc = disp_w ? label.new(bar_index + nbarsforward, pwclose, xloc=xloc.bar_index, text= 'last.W.CL', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_pwm = disp_w ? label.new(bar_index + nbarsforward, pwmid, xloc=xloc.bar_index, text= 'last.W.MID', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na //last month's labels var lab_pmo = disp_m ? label.new(bar_index + nbarsforward, pmopen, xloc=xloc.bar_index, text= 'last.M.OP', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_pmh = disp_m ? label.new(bar_index + nbarsforward, pmhigh, xloc=xloc.bar_index, text= 'last.M.HI', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_pml = disp_m ? label.new(bar_index + nbarsforward, pmlow, xloc=xloc.bar_index, text= 'last.M.LO', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_pmc = disp_m ? label.new(bar_index + nbarsforward, pmclose, xloc=xloc.bar_index, text= 'last.M.CL', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_pmm = disp_m ? label.new(bar_index + nbarsforward, pmmid, xloc=xloc.bar_index, text= 'last.M.MID', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na //today's labels var lab_do = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, dopen, xloc=xloc.bar_index, text= 'OPEN', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_dh = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, dhigh, xloc=xloc.bar_index, text= 'HIGH', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_dl = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, dlow, xloc=xloc.bar_index, text= 'LOW', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na var lab_dm = disp_d and timeframe.isintraday ? label.new(bar_index + nbarsforward, dmid, xloc=xloc.bar_index, text= 'MID', style=label.style_none, textcolor=col_lab_day, textalign =text.align_left, size=l_size) : na //this week's labels var lab_wo = disp_w ? label.new(bar_index + nbarsforward, wopen, xloc=xloc.bar_index, text= 'W.OP', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_wh = disp_w ? label.new(bar_index + nbarsforward, whigh, xloc=xloc.bar_index, text= 'W.HI', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_wl = disp_w ? label.new(bar_index + nbarsforward, wlow, xloc=xloc.bar_index, text= 'W.LO', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na var lab_wm = disp_w ? label.new(bar_index + nbarsforward, wmid, xloc=xloc.bar_index, text= 'W.MID', style=label.style_none, textcolor=col_lab_week, textalign =text.align_left, size=l_size) : na //this month's labels var lab_mo = disp_m ? label.new(bar_index + nbarsforward, mopen, xloc=xloc.bar_index, text= 'M.OP', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_mh = disp_m ? label.new(bar_index + nbarsforward, mhigh, xloc=xloc.bar_index, text= 'M.HI', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_ml = disp_m ? label.new(bar_index + nbarsforward, mlow, xloc=xloc.bar_index, text= 'M.LO', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na var lab_mm = disp_m ? label.new(bar_index + nbarsforward, mmid, xloc=xloc.bar_index, text= 'M.MID', style=label.style_none, textcolor=col_lab_month, textalign =text.align_left, size=l_size) : na //move labels horizontally each bar label.set_x(lab_pdo, bar_index + nbarsforward) label.set_x(lab_pdh, bar_index + nbarsforward) label.set_x(lab_pdl, bar_index + nbarsforward) label.set_x(lab_pdc, bar_index + nbarsforward) label.set_x(lab_pdm, bar_index + nbarsforward) label.set_x(lab_pwo, bar_index + nbarsforward) label.set_x(lab_pwh, bar_index + nbarsforward) label.set_x(lab_pwl, bar_index + nbarsforward) label.set_x(lab_pwc, bar_index + nbarsforward) label.set_x(lab_pwm, bar_index + nbarsforward) label.set_x(lab_pmo, bar_index + nbarsforward) label.set_x(lab_pmh, bar_index + nbarsforward) label.set_x(lab_pml, bar_index + nbarsforward) label.set_x(lab_pmc, bar_index + nbarsforward) label.set_x(lab_pmm, bar_index + nbarsforward) label.set_x(lab_do, bar_index + nbarsforward) label.set_x(lab_dh, bar_index + nbarsforward) label.set_x(lab_dl, bar_index + nbarsforward) label.set_x(lab_dm, bar_index + nbarsforward) label.set_x(lab_wo, bar_index + nbarsforward) label.set_x(lab_wh, bar_index + nbarsforward) label.set_x(lab_wl, bar_index + nbarsforward) label.set_x(lab_wm, bar_index + nbarsforward) label.set_x(lab_mo, bar_index + nbarsforward) label.set_x(lab_mh, bar_index + nbarsforward) label.set_x(lab_ml, bar_index + nbarsforward) label.set_x(lab_mm, bar_index + nbarsforward) //move each label vertically to update its price label.set_y(lab_pdo, pdopen) label.set_y(lab_pdh, pdhigh) label.set_y(lab_pdl, pdlow) label.set_y(lab_pdc, pdclose) label.set_y(lab_pdm, pdmid) label.set_y(lab_pwo, pwopen) label.set_y(lab_pwh, pwhigh) label.set_y(lab_pwl, pwlow) label.set_y(lab_pwc, pwclose) label.set_y(lab_pwm, pwmid) label.set_y(lab_pmo, pmopen) label.set_y(lab_pmh, pmhigh) label.set_y(lab_pml, pmlow) label.set_y(lab_pmc, pmclose) label.set_y(lab_pmm, pmmid) label.set_y(lab_do, dopen) label.set_y(lab_dh, dhigh) label.set_y(lab_dl, dlow) label.set_y(lab_dm, dmid) label.set_y(lab_wo, wopen) label.set_y(lab_wh, whigh) label.set_y(lab_wl, wlow) label.set_y(lab_wm, wmid) label.set_y(lab_mo, mopen) label.set_y(lab_mh, mhigh) label.set_y(lab_ml, mlow) label.set_y(lab_mm, mmid) if display_value label.set_text(lab_pdo, 'y.OP ' + str.tostring(nround(pdopen))) label.set_text(lab_pdh, 'y.HI ' + str.tostring(nround(pdhigh))) label.set_text(lab_pdl, 'y.LO ' + str.tostring(nround(pdlow))) label.set_text(lab_pdc, 'y.CL ' + str.tostring(nround(pdclose))) label.set_text(lab_pdm, 'y.MID ' + str.tostring(nround(pdmid))) label.set_text(lab_pwo, 'last.W.OP ' + str.tostring(nround(pwopen))) label.set_text(lab_pwh, 'last.W.HI ' + str.tostring(nround(pwhigh))) label.set_text(lab_pwl, 'last.W.LO ' + str.tostring(nround(pwlow))) label.set_text(lab_pwc, 'last.W.CL ' + str.tostring(nround(pwclose))) label.set_text(lab_pwm, 'last.W.MID ' + str.tostring(nround(pwmid))) label.set_text(lab_pmo, 'last.M.OP ' + str.tostring(nround(pmopen))) label.set_text(lab_pmh, 'last.M.HI ' + str.tostring(nround(pmhigh))) label.set_text(lab_pml, 'last.M.LO ' + str.tostring(nround(pmlow))) label.set_text(lab_pmc, 'last.M.CL ' + str.tostring(nround(pmclose))) label.set_text(lab_pmm, 'last.M.MID ' + str.tostring(nround(pmmid))) label.set_text(lab_do, 'OPEN ' + str.tostring(nround(dopen))) label.set_text(lab_dh, 'HIGH ' + str.tostring(nround(dhigh))) label.set_text(lab_dl, 'LOW ' + str.tostring(nround(dlow))) label.set_text(lab_dm, 'MID ' + str.tostring(nround(dmid))) label.set_text(lab_wo, 'W.OP ' + str.tostring(nround(wopen))) label.set_text(lab_wh, 'W.HI ' + str.tostring(nround(whigh))) label.set_text(lab_wl, 'W.LO ' + str.tostring(nround(wlow))) label.set_text(lab_wm, 'W.MID ' + str.tostring(nround(wmid))) label.set_text(lab_mo, 'M.OP ' + str.tostring(nround(mopen))) label.set_text(lab_mh, 'M.HI ' + str.tostring(nround(mhigh))) label.set_text(lab_ml, 'M.LO ' + str.tostring(nround(mlow))) label.set_text(lab_mm, 'M.MID ' + str.tostring(nround(mmid)))