The following pine-script plots an overlay for - initial balance with extensions and previous sessions high & low. Though it is plotting correctly on hourly and higher timeframe chart. But, for lower timeframes like 15 minutes or 30 minutes it's not plotting correctly. I also can't set the lookback period to plot, therefore the chart is becoming noisy to read. I can't identify and solve these two issues. Please help me to resolve these. The code is as follows -
//@version=5
indicator(title="Initial Balance Pivots", shorttitle="IB-Pivots", overlay=true)
lookback = input.int(title="Initial Balance Lookback Period", defval=3)
//Session Rules
bartimeSess = time(timeframe = 'D')
newbarSess = bartimeSess != bartimeSess[1]
high_range = ta.valuewhen(newbarSess,high,0)
low_range = ta.valuewhen(newbarSess,low,0)
//Calcul For Opening Range
locHigh = request.security(syminfo.tickerid, "60", high_range)
locLow = request.security(syminfo.tickerid, "60", low_range)
span = locHigh - locLow
ibm = locLow + span/2
sa = locLow - (0.5*span)
sb = locLow - span
sc = locLow - (1.5*span)
sd = locLow - (2*span)
se = locLow - (3*span)
sf = locLow - (4*span)
sg = locLow - (4.5*span)
ra = locHigh + (0.5*span)
rb = locHigh + span
rc = locHigh + (1.5*span)
rd = locHigh + (2*span)
re = locHigh + (3*span)
rf = locHigh + (4*span)
rg = locHigh + (4.5*span)
//Plot Statements For Initial Balance
plot(time(timeframe.period) > 0 ? locHigh : na,title="IB High", color=locHigh != locHigh[1] ? na : color.fuchsia, style=plot.style_line, linewidth=2)
plot(time(timeframe.period) > 0 ? locLow : na,title="IB Low", color=locLow != locLow[1] ? na : color.fuchsia, style=plot.style_line, linewidth=2)
//Plot Statements For Medium of IB range
plot(ibm, title="IB Median", color=locHigh != locHigh[1] ? na : color.black, style=plot.style_line, linewidth=1)
//Plot Statements For Higher extensions or Resistance
plot(ra, title="IB High Extension 1", color=ra != ra[1] ? na : color.red, linewidth=2)
plot(rb, title="IB High Extension 2", color=rb != rb[1] ? na : color.red, linewidth=2)
plot(rc, title="IB High Extension 3", color=rc != rc[1] ? na : color.red, linewidth=2)
plot(rd, title="IB High Extension 4", color=rd != rd[1] ? na : color.red, linewidth=2)
plot(re, title="IB High Extension 5", color=re != re[1] ? na : color.red, linewidth=2)
plot(rf, title="IB High Extension 6", color=rf != rf[1] ? na : color.red, linewidth=2)
plot(rg, title="IB High Extension 7", color=rg != rg[1] ? na : color.red, linewidth=2)
//Plot Statements For Lower extensions or Support
plot(sa, title="IB Low Extension 1", color=ra != ra[1] ? na : color.green, linewidth=2)
plot(sb, title="IB Low Extension 2", color=rb != rb[1] ? na : color.green, linewidth=2)
plot(sc, title="IB Low Extension 3", color=rc != rc[1] ? na : color.green, linewidth=2)
plot(sd, title="IB Low Extension 4", color=rd != rd[1] ? na : color.green, linewidth=2)
plot(se, title="IB Low Extension 5", color=re != re[1] ? na : color.green, linewidth=2)
plot(sf, title="IB Low Extension 6", color=rf != rf[1] ? na : color.green, linewidth=2)
plot(sg, title="IB Low Extension 7", color=rg != rg[1] ? na : color.green, linewidth=2)
//High Low Yesterday
res = input(title="Resolution", defval="D")
useColors = input(title="Fill with colors?",defval=true)
plotBreakouts = input(title="Plot breakouts?",defval=true)
isess = session.regular
t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)
igaps = barmerge.gaps_off
yesterdayHigh = request.security(t,res,high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
yesterdayLow = request.security(t,res,low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
// Plot the other time frame's data
a=plot(yesterdayHigh, color=color.red, style=plot.style_cross, linewidth=2)
b=plot(yesterdayLow, color=color.green, style=plot.style_cross, linewidth=2)
Thanks for your time. Regards.