Skip to main content

Colour the volume bars that spike

This indicator draws each bar's volume as a column in its own pane, in orange where the volume is more than a set multiple of its 20-bar average and in grey elsewhere.

You need a running Taji and a way to add an indicator to a chart: ask your connected agent to write and bind this source, or make the write and bind calls yourself as Your first indicator does.

volume_spike.ts
import { indicator, input, plot, ta } from "@taji/indicators";

export default indicator({
name: "Volume spike",
pane: "own",
inputs: { multiple: input.float(2, { min: 0.1 }) },
plots: {
volume: plot.columns({ title: "Volume", unit: "shares", colors: ["#787b86", "#ff9800"] }),
},
setup: () => ({ average: ta.sma(20) }),
next(bar, s, { inputs }) {
const average = s.average.next(bar.volume);
return { volume: bar.volume, colors: { volume: bar.volume > inputs.multiple * average ? 1 : 0 } };
},
});

A daily SPY chart with candles with the chart's own volume bars at their foot, and below them a pane titled Volume spike 2, whose grey columns follow volume and where a few columns, the last in late November, are taller and orange

  1. import { indicator, input, plot, ta } takes everything from @taji/indicators, the only module an indicator may import.
  2. pane: "own" gives the plot a pane of its own, with its own scale, since volume is in shares and the price scale is in dollars.
  3. inputs declares multiple, a number from 0.1 up, 2 by default: how many times its average a bar's volume must pass to count as a spike. The legend prints it after the name, Volume spike 2.
  4. plots declares one columns plot, bars from zero. Its colors is a palette of two colours: slot 0, grey, and slot 1, orange. Its unit is shares, so the pane's axis and legend print volume as +5.00M, not 5000000.00. The script decides which slot each bar takes; the palette only says how the slots look.
  5. setup creates the 20-bar simple moving average (ta.sma) once, before the first bar. A ta handle is created only here, because the kernel keeps its state and rolls it back on each tick of the forming bar.
  6. next feeds the bar's volume to the average, then returns the volume for the column and, under colors, slot 1 where the volume is above multiple times the average and slot 0 elsewhere. Until the average has 20 bars it is NaN, no volume is above it, and the column is grey.

The kernel serves the indicator's rows, one per bar. These are the latest ten, with the bar's palette slot beside its value as volume:color:

[
{
"start_dt": "2026-11-19T00:00:00+00:00",
"volume": 13200000.0,
"volume:color": 1
},
{
"start_dt": "2026-11-20T00:00:00+00:00",
"volume": 3800000.0,
"volume:color": 0
},
{
"start_dt": "2026-11-23T00:00:00+00:00",
"volume": 4800000.0,
"volume:color": 0
},
{
"start_dt": "2026-11-24T00:00:00+00:00",
"volume": 5500000.0,
"volume:color": 0
},
{
"start_dt": "2026-11-25T00:00:00+00:00",
"volume": 2000000.0,
"volume:color": 0
},
{
"start_dt": "2026-11-27T00:00:00+00:00",
"volume": 2400000.0,
"volume:color": 0
},
{
"start_dt": "2026-11-30T00:00:00+00:00",
"volume": 4000000.0,
"volume:color": 0
},
{
"start_dt": "2026-12-01T00:00:00+00:00",
"volume": 4400000.0,
"volume:color": 0
},
{
"start_dt": "2026-12-02T00:00:00+00:00",
"volume": 4500000.0,
"volume:color": 0
},
{
"start_dt": "2026-12-03T00:00:00+00:00",
"volume": 5000000.0,
"volume:color": 0
}
]

Captured 2026-12-04 on a headless kernel reading a made-up daily series for SPY.

  • volume is the bar's volume in shares, the number the column is drawn at.
  • volume:color is the palette slot the script returned for the bar: 0 grey, 1 orange.
  • 2026-11-19 is the spike: 13,200,000 shares, the only row with slot 1. The day after, 3.8 million, is below twice the average.
  • The last row, 2026-12-03, is the newest bar the series holds, 5,000,000 shares. On a live chart the last row is the forming bar, its volume what has traded so far, growing until the close.

Change it​

Mark only the heavier spikes by raising the default threshold:

- inputs: { multiple: input.float(2, { min: 0.1 }) },
+ inputs: { multiple: input.float(3, { min: 0.1 }) },

Compare with a 50-bar average, which reacts more slowly to a run of busy days:

- setup: () => ({ average: ta.sma(20) }),
+ setup: () => ({ average: ta.sma(50) }),

Draw thin bars instead of wide ones:

- volume: plot.columns({ title: "Volume", unit: "shares", colors: ["#787b86", "#ff9800"] }),
+ volume: plot.histogram({ title: "Volume", unit: "shares", colors: ["#787b86", "#ff9800"] }),

Next​