Skip to content

Ichimoku Cloud ​

Conversion and base lines, a lagging span and the cloud projected 26 bars ahead.

Kind indicator · Drawn on the price pane

Try it ​

On the chart, press / and choose Ichimoku Cloud under Trend. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
Conversion line lengthint9
Base line lengthint26
Leading span B lengthint52
Lagging spanint26
Conversion line colorcolor"#2962FF"
Base line colorcolor"#B71C1C"
Lagging span colorcolor"#43A047"
Leading span A colorcolor"#A5D6A7"
Leading span B colorcolor"#EF9A9A"
Cloud up colorcolor"rgba(67,160,71,0.1)"
Cloud down colorcolor"rgba(244,67,54,0.1)"

Source ​

From packages/alphascript/indicators/ichimoku.as.js.

js
indicator({ name: "Ichimoku Cloud", shortTitle: "Ichimoku", overlay: true });
const conversionPeriods = input.int("Conversion line length", 9, { min: 1 });
const basePeriods = input.int("Base line length", 26, { min: 1 });
const spanBPeriods = input.int("Leading span B length", 52, { min: 1 });
const displacement = input.int("Lagging span", 26, { min: 1, max: 500 });
/** @param {number} n */
const donchian = (n) => ta.calc([ta.lowest(candle.low, n), ta.highest(candle.high, n)], (l, h) => (l + h) / 2);
const conversion = donchian(conversionPeriods), base = donchian(basePeriods);
const leadA = ta.calc([conversion, base], (a, b) => (a + b) / 2), leadB = donchian(spanBPeriods);
plot(conversion, { title: "Conversion Line", color: input.color("Conversion line color", "#2962FF", { group: "Style" }) });
plot(base, { title: "Base Line", color: input.color("Base line color", "#B71C1C", { group: "Style" }) });
plot(candle.close, { title: "Lagging Span", offset: 1 - displacement, color: input.color("Lagging span color", "#43A047", { group: "Style" }) });
plot(leadA, { title: "Leading Span A", offset: displacement - 1, color: input.color("Leading span A color", "#A5D6A7", { group: "Style" }) });
plot(leadB, { title: "Leading Span B", offset: displacement - 1, color: input.color("Leading span B color", "#EF9A9A", { group: "Style" }) });
fill(leadA, leadB, { title: "Cloud", offset: displacement - 1, color: input.color("Cloud up color", "rgba(67,160,71,0.1)", { group: "Style" }),
  colorDown: input.color("Cloud down color", "rgba(244,67,54,0.1)", { group: "Style" }) });

AlphaScript language v0.1 · runtime 0.2.0