This will color the background on your condition. It uses a very wide line to do it, and because of that the indicator is occupying all the background, so some chart functions like the measuring tool cannot be used with Shift-Click, but it will work if you select its tool explicitly.
You can play with the position and width of the background if you don't want it to cover the whole chart.
The background is very light. If you want to change its brightness, you'll need to play with the transparency in the two color.new() calls, as it cannot be controlled from an input:
//@version=4
study("", "", true)
offsetCalc = input(50, "Close lookback", minval = 2)
offstBg = input(100, "Background: Horizontal Offset to its Center", minval = 0, step = 5)
lineWidth = input(10000, "Background: Width", minval = 0, step = 100)
condUp = barstate.islast and close[1] > close[offsetCalc]
condDn = barstate.islast and close[1] < close[offsetCalc]
c_lineColor = condUp ? color.new(color.green, 97) : condDn ? color.new(color.maroon, 97) : na
if barstate.islast
var line bg = na
line.delete(bg)
bg := line.new(bar_index[offstBg], low - tr, bar_index[offstBg], high + tr, color = c_lineColor, extend = extend.both, width = lineWidth)
the last closedo you mean the very last on the chart or last relative to a bar is being handled on current iteration? - Michel_T.