fintech-algorithms

Ichimoku Cloud

Separate Range Midpoints from Plot-Time Displacement

Install and import

bash
npm install fintech-algorithms
ts
import { ichimoku } from "fintech-algorithms/technical-indicators/trend-systems/ichimoku-cloud";

Signature

ichimoku(high, low, close, conversionPeriod, basePeriod, spanBPeriod, displacement)

The five Ichimoku lines. Two of them are plotted shifted forward and one shifted backward, so the series a chart draws is not the series computed at that index.

Parameters

NameTypeNotes
highnumber[]Per-bar high prices, chronological.
lownumber[]Per-bar low prices, chronological.
closenumber[]Per-bar closing prices, chronological.
conversionPeriodnumberLookback for the conversion line (Tenkan-sen).
min: 1 · integer: true
basePeriodnumberLookback for the base line (Kijun-sen).
min: 1 · integer: true
spanBPeriodnumberLookback for leading span B.
min: 1 · integer: true
displacementnumberBars by which the leading spans are pushed forward and the lagging span pulled back.
min: 1 · integer: true

Returns

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

Both the values at their origin index (span_a_origin, span_b_origin) and the displaced series a chart plots (span_a_plot, span_b_plot, lagging_plot). Using the origin series for plotting is the classic Ichimoku error.

Warm-up

The first max(conversionPeriod, basePeriod, spanBPeriod) − 1, plus the displacement on the plotted spans positions are null.

Errors

  • When any period is < 1 or is not an integer — throws RangeError
  • When the input series are not all the same length — throws RangeError

Complexity: time O(n × period), space O(n).

Worked example

executed 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
[113.52, 114.177204, 114.902817, 115.638854, 116.332532, 116.944154]

Showing 6 of 220 elements.

low
[111.23, 111.374639, 111.892314, 112.558492, 113.339025, 114.174124]

Showing 6 of 220 elements.

close
[112.42, 112.960931, 113.602175, 114.308896, 115.036356, 115.735587]

Showing 6 of 220 elements.

conversionPeriod
9
basePeriod
26
spanBPeriod
52
displacement
26

Call

ichimoku(high, low, close, conversionPeriod, basePeriod, spanBPeriod, displacement)

Returns

object with 7 fields: conversion, base, span_a_origin, span_b_origin, span_a_plot, span_b_plot, lagging_plot

{
  "conversion": [null, null, null, null, null, null],
  "base": [null, null, null, null, null, null],
  "span_a_origin": [null, null, null, null, null, null],
  "span_b_origin": [null, null, null, null, null, null],
  "span_a_plot": [null, null, null, null, null, null],
  "span_b_plot": [null, null, null, null, null, null],
  "lagging_plot": [120.589736, 120.670539, 120.683594, 120.665739, 120.660508, 120.712142]
}

Diagrams

Ichimoku Cloud — canonical trace
Ichimoku Cloud — failure boundary
Ichimoku Cloud — mechanism map

Calculation flow

Ichimoku Cloud calculation flow
flowchart LR
    A["Validated finalized bar"] --> B["Causal window or recursive state"]
    B --> C["Explicit seed and boundary rule"]
    C --> D["Aligned Ichimoku Cloud output"]
    D --> E["Diagnostics and audit evidence"]

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References