pine script cell width
//@version=4
study("Price vs Past", "", true)
var int MAX_LOOKBACK = 300
int i_lookBack = input(150, minval = 1, maxval = MAX_LOOKBACK, step = 10)
color i_c_Bull = input(#00FF00ff, "Bull", inline = "11")
color i_c_Bear = input(#FF0080ff, "Bear", inline = "11")
// ————— Function returning `_color` with `_transp` transparency.
f_colorNew(_color, _transp) =>
// color _color : base color to derive a new transparency from. Its current transparency is ignored.
// float _transp: 0-100 transparency of `_color` to return.
_r = color.r(_color)
_g = color.g(_color)
_b = color.b(_color)
color _return = color.rgb(_r, _g, _b, _transp)
// ————— Function draws a heatmap showing the position of the current `_src` relative to its past `_lookBack` values.
f_drawHeatmap(_src, _lookBack) =>
// float _src : evaluated price series.
// int _lookBack: number of past bars evaluated.
// Dependency: MAX_LOOKBACK
// Force historical buffer to a sufficient size.
max_bars_back(_src, MAX_LOOKBACK)
// Only run table code on last bar.
if barstate.islast
var _heatmap = table.new(position.bottom_center, _lookBack, 1)
for _i = 1 to i_lookBack
float _transp = 100. * _i / _lookBack
if _src > _src[_i]
table.cell(_heatmap, _lookBack - _i, 0, bgcolor = f_colorNew(i_c_Bull, _transp))
else
table.cell(_heatmap, _lookBack - _i, 0, bgcolor = f_colorNew(i_c_Bear, _transp))
f_drawHeatmap(high, i_lookBack)