All indicators
Trend / Price pane

Regime Shading

Shades the price pane by EMA trend regime, colours the fast EMA by regime and recolours the candles that close beyond the recent closing range.

  • Regime
  • Updates every tick
  • regime
  • ema
  • trend
  • background
  • bar color
  • shading

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 Shading on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

Classifies every bar by the position of a fast EMA against a slow one: up (fast above), down (fast below) or flat (within the flat band). The pane background and the fast EMA take the regime colour; candles that close beyond the recent range are recoloured.

How to read it

Green shading and a green fast EMA mark an up regime, red a down regime, grey no trend. A bright green candle closed above every close of the prior Breakout bars, a bright red one below all of them; a breakout in the direction of the regime is the stronger signal.

Settings and limitations

Fast and Slow EMA set the regime; a wider Flat band calls more bars flat. Breakout bars sets how far back the range reaches. Every colour, the shading opacity and the candle colours are appearance settings.

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
Fast EMAWhole number202 – 200Bars in the fast EMA.
Slow EMAWhole number503 – 400Bars in the slow EMA.
Flat band %Number0.050 – 2A fast EMA within this percentage of the slow one counts as no trend.
Breakout barsWhole number202 – 200A close above the highest close (below the lowest close) of this many prior bars is a breakout.

What it draws

Lines

  • Fast EMAsolid · 2 px · primary · colored per bar from Regime (3 colors)#C4A46A #2EA043 #DA3633 #6E7681
  • Slow EMAstep line · solid · 1 px#8B949E

Candle colorings

  • Breakout candlescandles colored per bar from Breakout (2 colors)#3FB950 #F85149

Background shadings

  • Regime shadingbackground per bar from Regime (3 colors) · at 8% opacity#2EA043 #DA3633 #6E7681

Source

Save it as regime-shading.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-shading',
  name: 'Regime Shading',
  shortName: 'Regime',
  version: '1.0.0',
  author: 'Spectral examples',
  description: 'Shades the price pane by EMA trend regime, colours the fast EMA by regime and recolours the candles that close beyond the recent closing range.',
  pane: 'price',
  live: { lookback: 'breakout' },
  inputs: {
    fast: { type: 'integer', label: 'Fast EMA', default: 20, min: 2, max: 200, description: 'Bars in the fast EMA.' },
    slow: { type: 'integer', label: 'Slow EMA', default: 50, min: 3, max: 400, description: 'Bars in the slow EMA.' },
    flat: { type: 'number', label: 'Flat band %', default: 0.05, min: 0, max: 2, description: 'A fast EMA within this percentage of the slow one counts as no trend.' },
    breakout: { type: 'integer', label: 'Breakout bars', default: 20, min: 2, max: 200, description: 'A close above the highest close (below the lowest close) of this many prior bars is a breakout.' },
  },
  palettes: {
    regime: { label: 'Regime', colors: ['#2EA043', '#DA3633', '#6E7681'] },
    breakout: { label: 'Breakout', colors: ['#3FB950', '#F85149'] },
  },
  plots: {
    fast: { label: 'Fast EMA', color: '#C4A46A', lineWidth: 2, palette: 'regime', primary: true },
    slow: { label: 'Slow EMA', color: '#8B949E', lineWidth: 1, style: 'step' },
  },
  bgColors: {
    regime: { label: 'Regime shading', palette: 'regime', opacity: 0.08 },
  },
  barColors: {
    breakout: { label: 'Breakout candles', palette: 'breakout' },
  },
  docs: {
    overview: 'Classifies every bar by the position of a fast EMA against a slow one: up (fast above), down (fast below) or flat (within the flat band). The pane background and the fast EMA take the regime colour; candles that close beyond the recent range are recoloured.',
    howToRead: 'Green shading and a green fast EMA mark an up regime, red a down regime, grey no trend. A bright green candle closed above every close of the prior Breakout bars, a bright red one below all of them; a breakout in the direction of the regime is the stronger signal.',
    settings: 'Fast and Slow EMA set the regime; a wider Flat band calls more bars flat. Breakout bars sets how far back the range reaches. Every colour, the shading opacity and the candle colours are appearance settings.',
  },
  calculate(ctx) {
    const { ta, inputs, bars } = ctx;
    const close = ta.source(bars, 'close');
    const fast = ta.ema(close, inputs.fast);
    const slow = ta.ema(close, inputs.slow);
    const highest = ta.highest(close, inputs.breakout);
    const lowest = ta.lowest(close, inputs.breakout);
    const band = inputs.flat / 100;
    // Palette indexes per bar: 0 up, 1 down, 2 flat; null leaves a bar unshaded.
    const regime = fast.map((value, index) => {
      const base = slow[index];
      if (value === null || base === null || base === 0) return null;
      const spread = (value - base) / base;
      return spread > band ? 0 : spread < -band ? 1 : 2;
    });
    // A breakout compares a close with the closes of the bars before it, so the previous bar's highest and lowest.
    const breakout = close.map((value, index) => {
      if (index === 0) return null;
      const high = highest[index - 1];
      const low = lowest[index - 1];
      if (high !== null && value > high) return 0;
      if (low !== null && value < low) return 1;
      return null;
    });
    return {
      plots: { fast, slow },
      colors: { fast: regime },
      bgColors: { regime },
      barColors: { breakout },
    };
  },
};

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-shading.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.