All indicators
Patterns & signals / Price pane

Swing Labels

Labels each confirmed swing high and low with its price and whether it is higher or lower than the last one, and draws the latest swing high and low as levels with inline labels.

  • Swings
  • Updates at bar close
  • swings
  • swing high
  • swing low
  • labels
  • higher high
  • lower low

By Spectral examples · v1.0.0

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

Swing Labels on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

Finds swing highs and lows the way fractal pivots do: a bar whose high is above the highs of the bars on each side (a low below their lows), confirmed once those bars have closed. Each swing gets a label with its price; HH, LH, HL and LL compare it with the swing before it.

How to read it

HH (higher high) and HL (higher low) in amber describe an up-trending structure, LH and LL in violet a down-trending one. A swing is labelled only after Pivot strength bars have closed on its right, so the newest swing appears a few bars late. The dotted levels mark the latest swing high and low, the usual breakout and stop references.

Settings and limitations

Pivot strength sets how many bars on each side must stay below a swing high (above a swing low): a higher value finds fewer, more significant swings. Latest swing levels turns the two levels off.

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
Pivot strengthWhole number31 – 20Bars on each side a swing high must stand above (a swing low below) to count.
Latest swing levelsOn / offOn—Draw the latest swing high and low as levels from the bar they formed on.

What it draws

Levels

  • Swing highdotted · 1 px · label on the line#D29922
  • Swing lowdotted · 1 px · label on the line#A371F7

Text labels

  • Swing highspin label · above · colors from Swing (2 colors)#D29922 #A371F7
  • Swing lowspin label · below · colors from Swing (2 colors)#A371F7 #D29922

Source

Save it as swing-labels.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: 'swing-labels',
  name: 'Swing Labels',
  shortName: 'Swings',
  version: '1.0.0',
  author: 'Spectral examples',
  description: 'Labels each confirmed swing high and low with its price and whether it is higher or lower than the last one, and draws the latest swing high and low as levels with inline labels.',
  pane: 'price',
  live: 'none',
  inputs: {
    strength: { type: 'integer', label: 'Pivot strength', default: 3, min: 1, max: 20, description: 'Bars on each side a swing high must stand above (a swing low below) to count.' },
    showLevels: { type: 'boolean', label: 'Latest swing levels', default: true, description: 'Draw the latest swing high and low as levels from the bar they formed on.' },
  },
  palettes: {
    swing: { label: 'Swing', colors: ['#D29922', '#A371F7'] },
  },
  labels: {
    highs: { label: 'Swing highs', color: '#D29922', palette: 'swing', style: 'pin', placement: 'above', hideBelowBarWidth: 2 },
    lows: { label: 'Swing lows', color: '#A371F7', palette: 'swing', style: 'pin', placement: 'below', hideBelowBarWidth: 2 },
  },
  levels: {
    lastHigh: { label: 'Swing high', color: '#D29922', lineStyle: 'dotted', labelStyle: 'inline' },
    lastLow: { label: 'Swing low', color: '#A371F7', lineStyle: 'dotted', labelStyle: 'inline' },
  },
  docs: {
    overview: 'Finds swing highs and lows the way fractal pivots do: a bar whose high is above the highs of the bars on each side (a low below their lows), confirmed once those bars have closed. Each swing gets a label with its price; HH, LH, HL and LL compare it with the swing before it.',
    howToRead: 'HH (higher high) and HL (higher low) in amber describe an up-trending structure, LH and LL in violet a down-trending one. A swing is labelled only after Pivot strength bars have closed on its right, so the newest swing appears a few bars late. The dotted levels mark the latest swing high and low, the usual breakout and stop references.',
    settings: 'Pivot strength sets how many bars on each side must stay below a swing high (above a swing low): a higher value finds fewer, more significant swings. Latest swing levels turns the two levels off.',
  },
  calculate(ctx) {
    const { bars, inputs, format } = ctx;
    const n = inputs.strength;
    const highs = [];
    const lows = [];
    let lastHigh = null;
    let lastLow = null;
    // A swing at bar i needs n closed bars on each side.
    for (let i = n; i < bars.length - n; i += 1) {
      let isHigh = true;
      let isLow = true;
      for (let k = 1; k <= n && (isHigh || isLow); k += 1) {
        if (bars[i - k].high >= bars[i].high || bars[i + k].high > bars[i].high) isHigh = false;
        if (bars[i - k].low <= bars[i].low || bars[i + k].low < bars[i].low) isLow = false;
      }
      if (isHigh) {
        const higher = lastHigh === null || bars[i].high >= lastHigh.price;
        highs.push({ index: i, value: bars[i].high, text: `${higher ? 'HH' : 'LH'} ${format.price(bars[i].high)}`, palette: higher ? 0 : 1 });
        lastHigh = { price: bars[i].high, fromIndex: i };
      }
      if (isLow) {
        const higher = lastLow === null || bars[i].low >= lastLow.price;
        lows.push({ index: i, value: bars[i].low, text: `${higher ? 'HL' : 'LL'} ${format.price(bars[i].low)}`, palette: higher ? 0 : 1 });
        lastLow = { price: bars[i].low, fromIndex: i };
      }
    }
    // The chart keeps at most 2,000 labels per key: the most recent swings.
    return {
      labels: { highs: highs.slice(-2000), lows: lows.slice(-2000) },
      levels: inputs.showLevels ? { lastHigh, lastLow } : {},
    };
  },
};

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/swing-labels.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.