# Supertrend

> Trace ATR Bands, Ratchets, and Direction Flips

`D07-F02-A08` · Technical Indicators → Trend Systems · archetype `series-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/technical-indicators/trend-systems/supertrend/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { supertrend } from "fintech-algorithms/technical-indicators/trend-systems/supertrend";
```

## Signature

```ts
supertrend(high, low, close, period, multiplier)
```

An ATR-scaled band around the median price that ratchets in the direction of the trend and only flips when close crosses it. The band never loosens while the trend holds.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `high` | `number[]` | yes | Per-bar high prices, chronological. |
| `low` | `number[]` | yes | Per-bar low prices, chronological. |
| `close` | `number[]` | yes | Per-bar closing prices, chronological. |
| `period` | `number` | yes | ATR lookback. · min: 1, integer: true |
| `multiplier` | `number` | yes | Number of ATRs the band sits away from the median price. · min: 0 |

## Returns

`Record<string, (number | null)[]>` · length same-as-input

Parallel series: `atr`, `upper_band`, `lower_band`, `supertrend` and `trend`.

## Warm-up

The first `period` positions are `null`. The band cannot be placed until ATR is defined.

## Errors

- When period < 1, is not an integer, or multiplier is negative — throws RangeError
- When the input series are not all the same length — throws RangeError

## Complexity

Time `O(n)`, space `O(n)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`high`:

```json
[121.59, 122.253519, 122.988989, 123.733544, 124.428602, 125.029237]
```

Showing 6 of 180 elements.

`low`:

```json
[119.167, 119.311841, 119.836426, 120.513403, 121.303676, 122.141567]
```

Showing 6 of 180 elements.

`close`:

```json
[120.42, 120.967246, 121.618347, 122.333586, 123.062426, 123.75067]
```

Showing 6 of 180 elements.

`period`:

```json
10
```

`multiplier`:

```json
3
```

### Call

```ts
supertrend(high, low, close, period, multiplier)
```

### Returns

object with 9 fields: true_range, atr, basic_upper, basic_lower, final_upper, final_lower, supertrend, direction, …

```json
{
  "true_range": [
    2.423000000000002,
    2.941677999999996,
    3.1525630000000007,
    3.220140999999998,
    3.124926000000002,
    2.88767
  ],
  "atr": [null, null, null, null, null, null],
  "basic_upper": [null, null, null, null, null, null],
  "basic_lower": [null, null, null, null, null, null],
  "final_upper": [null, null, null, null, null, null],
  "final_lower": [null, null, null, null, null, null],
  "supertrend": [null, null, null, null, null, null],
  "direction": [null, null, null, null, null, null],
  "reversal": [null, null, null, null, null, null]
}
```

## Verification and provenance

Tier: **verified** (via scenario-fixture).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/technical-indicators/trend-systems/supertrend/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/technical-indicators/trend-systems/supertrend/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/technical-indicators/llms.txt
