# Volume Heatmap

> Volume Heatmap is an indicator drawn over the price chart.

Source: https://algobarsx.com/docs/ex-39-volume-heatmap/

```algobarsx
indicator "Volume Heatmap"
    pane: price

input columns = 30
input rows = 12

state heat: list<Cell> = []

top = highest(high, columns)
bottom = lowest(low, columns)
row_height = (top - bottom) / rows

if bar.confirmed:
    for i in 0..rows:
        level = bottom + row_height * i
        heat.push(Cell(bar: bar.index, price: level, value: volume * (1 - abs(close - level) / (top - bottom))))
    heat = heat.keep_last(columns * rows)

heatmap cells: heat, palette: "thermal"
```
What this script says

Volume Heatmap is an indicator drawn over the price chart.

You can change 2 inputs: `columns` (default 30) and `rows` (default 12).

It remembers `heat` from one bar to the next.

It calculates `top` as the highest high of the last `columns` bars, `bottom` as the lowest low of the last `columns` bars and `row_height` as (`top` minus `bottom`) divided by `rows`.

On each bar, it checks whether the bar has closed and, if so, goes through each `i` in 0 to `rows` and sets `level` to `bottom` plus `row_height` × `i`; it also adds `Cell(bar: bar.index, price: level, value: volume * (1 - abs(close - level) / (top - bottom)))` to `heat`; it also sets `heat` to `heat.keep_last(columns * rows)`.

On the chart, it draws a heatmap.
