All indicators
Trend / Price pane

Regime Table

A table on the price pane that classifies the latest bar as trending up, trending down or ranging from ADX, the directional indicators and the slope of an EMA.

  • Regime
  • Updates every tick
  • table
  • dashboard
  • regime
  • adx
  • dmi
  • ema
  • trend strength

By Spectral examples · v1.0.0

MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.

Regime Table on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

Reads the trend state of the latest bar: the Average Directional Index (Wilder) for trend strength, +DI against -DI for its direction, and the slope of an EMA as a second opinion.

How to read it

Trend up: ADX at or above the Trend ADX setting, +DI above -DI and a rising EMA. Trend down: the mirror image. Anything else is a range. The table updates with every tick of the forming bar; hover the regime cell for the ADX and slope behind it.

Settings and limitations

ADX length sets how smooth the directional averages are. EMA length and Slope bars set the direction filter; a longer EMA or more slope bars react later but flip less often.

Settings

Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.

SettingTypeDefaultRange or optionsWhat it does
ADX lengthWhole number142 – 100Bars in the Wilder averages of the directional movement and the true range.
EMA lengthWhole number502 – 400Bars in the EMA whose slope sets the direction.
Slope barsWhole number51 – 50How many bars back the EMA slope is measured.
Trend ADXNumber2510 – 50ADX at or above this value counts as a trend.

What it draws

Tables

  • Regime2 columns · top right · cell borders#161B22

Source

Save it as regime-table.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.

// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV3} */
export default {
  schemaVersion: 3,
  id: 'regime-table',
  name: 'Regime Table',
  shortName: 'Regime',
  version: '1.0.0',
  author: 'Spectral examples',
  description: 'A table on the price pane that classifies the latest bar as trending up, trending down or ranging from ADX, the directional indicators and the slope of an EMA.',
  pane: 'price',
  live: { lookback: 'slope' },
  inputs: {
    length: { type: 'integer', label: 'ADX length', default: 14, min: 2, max: 100, description: 'Bars in the Wilder averages of the directional movement and the true range.' },
    emaLength: { type: 'integer', label: 'EMA length', default: 50, min: 2, max: 400, description: 'Bars in the EMA whose slope sets the direction.' },
    slope: { type: 'integer', label: 'Slope bars', default: 5, min: 1, max: 50, description: 'How many bars back the EMA slope is measured.' },
    threshold: { type: 'number', label: 'Trend ADX', default: 25, min: 10, max: 50, description: 'ADX at or above this value counts as a trend.' },
  },
  palettes: {
    regime: { label: 'Regime', colors: ['#2EA043', '#DA3633', '#6E7681'] },
  },
  tables: {
    regime: { label: 'Regime', position: 'top-right', columns: [{ align: 'left' }, { align: 'right', width: 12 }], border: true },
  },
  docs: {
    overview: 'Reads the trend state of the latest bar: the Average Directional Index (Wilder) for trend strength, +DI against -DI for its direction, and the slope of an EMA as a second opinion.',
    howToRead: 'Trend up: ADX at or above the Trend ADX setting, +DI above -DI and a rising EMA. Trend down: the mirror image. Anything else is a range. The table updates with every tick of the forming bar; hover the regime cell for the ADX and slope behind it.',
    settings: 'ADX length sets how smooth the directional averages are. EMA length and Slope bars set the direction filter; a longer EMA or more slope bars react later but flip less often.',
  },
  calculate(ctx) {
    const { ta, inputs, bars, format } = ctx;
    const high = ta.source(bars, 'high');
    const low = ta.source(bars, 'low');
    const upMove = ta.change(high);
    const downMove = ta.change(low);
    const plusDm = upMove.map((up, index) => {
      const down = downMove[index] === null ? null : -downMove[index];
      return up === null || down === null ? null : up > down && up > 0 ? up : 0;
    });
    const minusDm = downMove.map((change, index) => {
      const up = upMove[index];
      const down = change === null ? null : -change;
      return up === null || down === null ? null : down > up && down > 0 ? down : 0;
    });
    const range = ta.rma(ta.trueRange(bars), inputs.length);
    const plusSmooth = ta.rma(plusDm, inputs.length);
    const minusSmooth = ta.rma(minusDm, inputs.length);
    const plusDi = range.map((tr, index) => (tr === null || plusSmooth[index] === null || tr === 0 ? null : 100 * plusSmooth[index] / tr));
    const minusDi = range.map((tr, index) => (tr === null || minusSmooth[index] === null || tr === 0 ? null : 100 * minusSmooth[index] / tr));
    const dx = plusDi.map((plus, index) => {
      const minus = minusDi[index];
      if (plus === null || minus === null || plus + minus === 0) return null;
      return 100 * Math.abs(plus - minus) / (plus + minus);
    });
    const adx = ta.rma(dx, inputs.length);
    const ema = ta.ema(ta.source(bars, 'close'), inputs.emaLength);

    const last = bars.length - 1;
    const then = last - inputs.slope;
    const emaNow = last >= 0 ? ema[last] : null;
    const emaThen = then >= 0 ? ema[then] : null;
    const slope = emaNow === null || emaThen === null || emaThen === 0 ? null : (emaNow - emaThen) / emaThen;
    const strength = last >= 0 ? adx[last] : null;
    const plus = last >= 0 ? plusDi[last] : null;
    const minus = last >= 0 ? minusDi[last] : null;
    const trending = strength !== null && strength >= inputs.threshold;
    let verdict = { text: 'Range', palette: 2 };
    if (trending && plus !== null && minus !== null && slope !== null) {
      if (plus > minus && slope > 0) verdict = { text: 'Trend up', palette: 0 };
      else if (minus > plus && slope < 0) verdict = { text: 'Trend down', palette: 1 };
    }
    const lastClose = last >= 0 ? bars[last].close : null;
    return {
      tables: {
        regime: {
          palette: 'regime',
          rows: [
            ['Regime', {
              ...verdict, weight: 'bold', align: 'center',
              tooltip: `ADX ${format.number(strength, 1)}, trend from ${format.number(inputs.threshold, 0)}\nEMA slope ${format.percent(slope, 2)}`,
            }],
            ['ADX', format.number(strength, 1)],
            ['+DI / -DI', `${format.number(plus, 1)} / ${format.number(minus, 1)}`],
            ['EMA slope', format.percent(slope, 2)],
            ['Close', lastClose === null || emaNow === null ? 'n/a' : lastClose >= emaNow ? 'above EMA' : 'below EMA'],
          ],
        },
      },
    };
  },
};

Adapt it with an LLM

Paste this into your assistant and replace the second-to-last line with the change you want.

Start from this Spectral custom indicator: https://spectral.trade/indicators/regime-table.js
Format reference: https://spectral.trade/docs/custom-indicators.llm.md
Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match.
Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow.
Change I want: <describe the change>
Answer with the complete file in one code block, ready to save as <id>.js.