---
related_nodes: ["quote_fetch", "polygon_market", "chart_plot"]
---

# Technical Indicators

Computes technical indicators over a series of OHLC bars. Purely mathematical: it takes bars
and nothing else, so any node that produces bars can feed it.

## Configuration

- `indicators` - the indicators to compute. Each carries a `name` you choose, a `type`, and
  that type's own fields. The name is the key its value appears under in the result, so the
  same indicator can be configured more than once — a fast and a slow moving average, say.
- `output_mode` — `latest` (default) returns one newest reading per indicator; `series` returns
  one nullable reading per supplied bar, at that bar's original index.

Names may hold letters, digits and underscores, and each must be used once.
All periods/spans must be positive, MACD requires `fast <= slow`, and Golden Cross requires
`short_period <= long_period`. Combined lookbacks must fit the supported index range.

| Type | Fields | Bars needed |
|---|---|---|
| `simple_moving_average` | `period` | `period` |
| `exponential_moving_average` | `period` | `period` |
| `relative_strength_index` | `period` | `period + 1` |
| `macd` | `fast`, `slow`, `signal` | `slow + signal` |
| `average_true_range` | `period` | `period + 1` |
| `stochastic_oscillator` | `k_period`, `d_period` | `k_period + d_period` |
| `fibonacci_retracement` | — | 2 |
| `volume_weighted_average_price` | — | 0 (empty input returns zero) |
| `golden_cross` | `short_period`, `long_period` | `long_period` |
| `ema_deviation` | `period` | `period` |
| `weighted_price_movement` | `period` | `period + 1` |
| `average_directional_index` | `period` (default 14) | `2 * period` |
| `bollinger_bands` | `period` (20), `standard_deviations` (2, positive) | `period` |
| `donchian_channels` | `period` (20) | `period + 1` |
| `relative_volume` | `period` (20) | `period + 1` |
| `fair_value_gaps` | `require_direction` (true) | 3 |
| `confirmed_swings` | `left_span`, `right_span` (both 2) | `left_span + right_span + 1` |
| `market_structure` | `left_span`, `right_span` (both 2) | `left_span + right_span + 1` |
| `structure_breaks` | spans (2/2), `confirmation` (`close` or `wick`, default `close`) | `left_span + right_span + 1` |
| `support_resistance_zones` | spans (2/2), `min_touches` (2), `tolerance_percent` (0.5) | `left_span + right_span + 1` |

The nine additional configurations default omitted fields. Zones require at least two touches and
`0 <= tolerance_percent < 100`. Editor ranges are suggestions, not calculation caps.

```json
[
  { "name": "fast_sma", "type": "simple_moving_average", "period": 50 },
  { "name": "slow_sma", "type": "simple_moving_average", "period": 200 },
  { "name": "rsi", "type": "relative_strength_index", "period": 14 }
]
```

## Input

A series of OHLC bars, exactly as `quote_fetch` and `polygon_market` emit them:

```json
[ { "timestamp": "2024-01-15T10:00:00Z", "open": "185.50", "high": "186.20",
    "low": "184.80", "close": "185.90", "volume": 1500000 } ]
```

Or an array of series, to compute the same indicators over several at once:

```json
[ [ { "timestamp": "...", ... } ], [ { "timestamp": "...", ... } ] ]
```

Anything else is rejected.

Supply each series newest first. RSI and ATR use Wilder smoothing: seed with the mean of
the oldest `period` changes or true ranges, then update with
`(previous_average * (period - 1) + current_value) / period` for every later bar.
Both need a positive period. Their readings depend on all supplied history, not just the
latest `period + 1` bars; fetch additional history for the smoothed values to settle.

No timestamp sorting, missing-bar synthesis, session resets, or provider calls occur.
Exclude still-forming candles when you need closed-candle confirmation. Recursive indicators
use all supplied history; convergence is not an extra fixed warm-up discard.

## Output

An object keyed by the names you configured, so a script reads a value directly:
`result.rsi`, `result.fast_sma`.

```json
{
  "fast_sma": 184.5,
  "slow_sma": 171.2,
  "rsi": 62.3,
  "macd": { "macd_line": 1.2, "signal_line": 0.8, "histogram": 0.4,
            "macd_level": "bullish" },
  "cross": { "type": "golden", "strength": "strong" }
}
```

A `golden_cross` value is `{ "type": "golden", "strength": "strong" }`, `{ "type": "death",
... }`, or `{ "type": "none" }` when the averages are equal.
It describes the current position, not a crossing event; strength uses strict 2% separation.

Several series in yields the same object for each, in an array — the output container mirrors
the input. Both cases emit on `output`.

### Aligned histories

```json
{"indicator":{"output_mode":"series","indicators":[
  {"name":"sma","type":"simple_moving_average","period":3},
  {"name":"gaps","type":"fair_value_gaps","require_direction":true}
]}}
```

Newest-first closes `[5,4,3,2,1]` produce `"sma":[4,3,2,null,null]`.
Every result array has the input length. Slot `i` uses only `bars[i..]`: warm-up is at the tail,
never shifted, shortened, or forward-filled. Insufficient history yields all-null slots.
Empty input `[]` is one empty series and produces an empty array under each indicator's name.
It is not an empty batch. Latest empty VWAP remains zero.

A ready but undefined numeric observation is also null: zero EMA deviation denominator, zero
relative-volume baseline, or a non-equal cross against a zero long SMA. Relative volume is also
unavailable while current or baseline volumes are negative; later valid windows recover.
Flat RSI/stochastic deliberately yield 50; zero-volume VWAP yields zero.

ADX returns `{adx,plus_di,minus_di}` after two full periods, with Wilder smoothing.
Bollinger returns `{middle,upper,lower,bandwidth,percent_b}` using population variance;
bandwidth is a ratio, not a percentage, and is null at zero middle. `percent_b` is null for
zero-width bands and is not clipped. Donchian returns `{middle,upper,lower,range}` over the
preceding period, excluding current; `range` is an absolute price distance. Relative volume
divides current volume by the preceding period's mean, also excluding current.

### Indexed causal events

All bar references are `{index,timestamp}` into this exact supplied series. Each batch series
has its own index space. Prepending bars shifts indices; timestamps help join but are not
guaranteed unique or durable IDs. Earlier event payloads never acquire future updates.
Once ready, an event indicator returns `{"events":[]}` on quiet bars, not null.
Latest returns only events occurring on the newest bar, not a list of all active gaps/zones.

**Fair value gaps:** for chronological A/B/C, bullish requires `A.high < C.low`, bearish
`A.low > C.high`; equality is not a gap. By default B must close above its open for bullish,
below for bearish; `require_direction:false` removes that filter. The created event belongs
to C, never retroactively to B:

```json
{"events":[{"type":"created","gap":{
  "direction":"bullish","lower":11,"upper":13,
  "start":{"index":5,"timestamp":"2024-01-01T00:00:00Z"},
  "middle":{"index":4,"timestamp":"2024-01-01T00:00:01Z"},
  "formed_at":{"index":3,"timestamp":"2024-01-01T00:00:02Z"}
}}]}
```

Later bars emit `{"type":"touched","gap_formed_at":{...},"at":{...}}` on first reach of
the near boundary, and `{"type":"filled","gap_formed_at":{...},"at":{...}}` on reach of
the far boundary. These are wick-reach rules, not proof of trades throughout the interval;
a bar wholly beyond the far boundary counts as filled. Formation bars do not touch their own
gaps. A first touch can also fill: all touches come first, then fills, each oldest-formation
first, then a new creation. No merging, session gaps, or session integration.

**Confirmed swings:** `events` contains `{kind,price,origin,confirmed_at}`. `kind` is `high`
or `low`. A pivot must be the unique extreme across its left/right window; equal neighbors
disqualify it. Publish after `right_span` later bars. An outside bar can confirm both sides,
serialized High then Low, without asserting intrabar order.

**Market structure:** returns `{trend,high_change,low_change,last_high,last_low}`.
Changes compare consecutive confirmed highs/lows separately (`higher`, `lower`, `equal`).
Before both comparisons exist, trend is `undetermined`; both higher is `bullish`, both lower
`bearish`, otherwise `mixed`. Last levels are nullable confirmed-swing objects.

**Structure breaks:** `events` contains `{direction,kind,level,swing,at}`. Test only levels
confirmed before the current bar, strictly beyond the level: `close` tests the close,
`wick` tests high/low. Each swing can break once. Classification uses the pre-bar trend:
with the established trend is `break_of_structure`, against it `change_of_character`;
undetermined/mixed gives `unclassified`. Breaks do not override the swing-derived trend.
Dual wick breaks serialize bullish then bearish against the same prior state.

**Support/resistance zones:** cluster confirmed swing lows/highs, not ordinary in-zone candles.
The first pivot at P fixes bounds `P ± abs(P)*tolerance_percent/100`; later same-kind pivots
match inclusive bounds, choosing the nearest original center and then oldest origin on a tie.
Count exactly one zone; never merge or widen. Only reaching `min_touches` emits:

- `created`: `zone` has `id:{kind,origin}`, `lower`, `upper`, `touches`, `confirmed_at`,
  `last_touch` (a confirmed swing). Kind is `support` or `resistance`.
- `touched`: `zone_id`, `pivot`, and the new `touches` count.
- `broken`: `zone_id`, `at`, and `close`.

Before current confirmations, close below support's lower bound or above resistance's upper
bound removes it. Equality does not break. Unconfirmed candidates disappear silently;
confirmed zones emit Broken, oldest-origin first (support before resistance on a tied origin),
before High/Low confirmation events. No automatic role reversal, expiry, or retained-zone cap.

These outputs are calculation data, not chart annotations. The existing `chart_plot` rejects
null numeric slots and does not render FVG/structural events directly. Do not drop nulls and
zip compact values to input index zero.

## Failure

Invalid configurations and duplicate names fail validation, creation, and direct execution in
both modes. Latest mode also fails if any reading is unavailable — for example
`RSI(14) needs 15 bars but only 9 were provided`. Series mode preserves unavailable samples as
null, rather than failing ordinary warm-up or undefined ratios.

Set `lookback` on the upstream fetch to at least the largest "bars needed" above.

For a recently listed symbol, request the desired count plus warm-up bars with `lookback` on the
Alpaca Market Data node. Set `min_bars` to the count the indicator needs. A short history fails the
fetch only if fewer than `min_bars` are available.

## Tips

- Golden Cross with a 200-period long leg needs 200 bars; fetch daily bars accordingly.
- VWAP and weighted price movement are most meaningful on intraday bars.
- RSI above 70 is conventionally overbought, below 30 oversold.
- A MACD histogram crossing zero marks a momentum shift.
