Concept 22 / 52·Trend·Trend systems
‹ Hull Moving AverageInside Bar ›

Ichimoku Cloud in Pine Script

Ichimoku Kinko Hyo · Ichimoku · Kumo cloud · Tenkan and Kijun

A 5-line trend system whose cloud, projected 26 bars ahead, shows trend direction, support and resistance and momentum in one glance.

Reads best on: Trending markets on 4-hour, daily and weekly charts: index futures, forex majors, large-cap stocks and the main crypto pairs. It is cluttered and whipsaw-prone in ranges and on charts below 15 minutes.
On this page: the Pine v6 script, checked, drawn on real NVDA bars. Backtest it free, costs charged, every trade on the chart.
01

Definition

Ichimoku Kinko Hyo, usually shortened to Ichimoku or the Ichimoku Cloud, is a complete trend system drawn on the price chart. It has 5 lines: the conversion line (Tenkan-sen), the base line (Kijun-sen), two leading spans (Senkou Span A and B) that are shaded into a cloud, and a lagging span (Chikou Span). The name means a one-glance equilibrium chart, and that is the design: one look should tell you the trend, the momentum, the support and resistance, and whether the trend is healthy. It belongs to the trend-system family rather than to single-line indicators.

The lines are midpoints of price ranges, not averages of closes. The conversion line is the middle of the last 9 bars' range and the base line the middle of the last 26, so each marks the equilibrium of a window, the level where buyers and sellers were balanced. Price above the equilibrium means the auction has moved up from balance, and the further above, the stronger the move. The cloud takes two more midpoints and projects them 26 bars forward, which turns past equilibrium into a zone that price will meet in the future: support below a rising market, resistance above a falling one.

Goichi Hosoda, a Japanese journalist, developed the system over several decades and published it in the 1960s. The standard settings are 9, 26 and 52, taken from the 6-day trading week of his time: 9 for a week and a half, 26 for a month and 52 for two months. The displacement is 26 in both directions, the cloud shifted forward and the lagging span shifted back. Most traders keep the original numbers even on 5-day markets and on intraday charts, because the settings have become the shared reference and every chart then compares like with like.

On the chart the conversion line follows price closely and the base line moves in flat steps, staying level while the 26-bar high and low hold. Flat base lines and flat span B levels act as magnets, because they mark the centre of a range that price has not left. The cloud is thin after a fast move and thick after a long trend, and a thin cloud is easy to cross. Where span A crosses span B ahead of price the cloud twists, which often coincides with a change of trend. Price inside the cloud is in no man's land, and most Ichimoku traders stand aside there.

02

Reading the chart

Read the chart from the cloud outward, because the cloud sets the regime and every other line is read against it.

  1. Locate the current bar relative to the cloud drawn under it, which was projected 26 bars ago. Above the cloud is a bullish regime, below is bearish, inside is neutral, and most rules only allow trades in the regime's direction.
  2. Read the cloud's colour and thickness ahead of price. Span A above span B is bullish, the reverse bearish, a thick cloud is strong support or resistance, and a twist ahead marks where the balance may change.
  3. Check the conversion line against the base line. Conversion above base means short-term momentum is up, and a cross is graded by where it happens: above the cloud is strong, inside neutral, below the cloud weak.
  4. Look at the lagging span, the close plotted 26 bars back. Clear above the price of 26 bars ago confirms an uptrend, clear below confirms a downtrend, and tangled in the candles means no clean trend.
  5. Mark the flat lines. A level base line or a flat span B is the middle of a range that still stands, and price tends to return to it before the next move.
  6. Wait for the bar to close before acting on a cross or a cloud break. The library script only marks a cross on a confirmed bar, when the conversion line crosses the base line with the close beyond the cloud.
03

The maths

Every Ichimoku line is the midpoint of a range, and two of the lines are displaced in time rather than in price.

Tenkant=HH9+LL92\mathrm{Tenkan}_t = \frac{\mathrm{HH}_9 + \mathrm{LL}_9}{2}
Kijunt=HH26+LL262\mathrm{Kijun}_t = \frac{\mathrm{HH}_{26} + \mathrm{LL}_{26}}{2}
SpanAt+26=Tenkant+Kijunt2\mathrm{SpanA}_{t+26} = \frac{\mathrm{Tenkan}_t + \mathrm{Kijun}_t}{2}
SpanBt+26=HH52+LL522\mathrm{SpanB}_{t+26} = \frac{\mathrm{HH}_{52} + \mathrm{LL}_{52}}{2}
Chikout−26=Ct\mathrm{Chikou}_{t-26} = C_t
HHn\mathrm{HH}_nthe highest high of the last n bars, including the current bar
LLn\mathrm{LL}_nthe lowest low of the last n bars, including the current bar
Tenkant\mathrm{Tenkan}_tthe conversion line at bar t
Kijunt\mathrm{Kijun}_tthe base line at bar t
SpanAt+26\mathrm{SpanA}_{t+26}leading span A, computed at bar t and drawn 26 bars ahead
SpanBt+26\mathrm{SpanB}_{t+26}leading span B, computed at bar t and drawn 26 bars ahead
Chikout−26\mathrm{Chikou}_{t-26}the lagging span, the close of bar t drawn 26 bars back
CtC_tthe close of bar t

A midpoint behaves differently from a moving average. It stays flat while the window's high and low stand, then jumps when one of them drops out, which is why the base line moves in steps.

The cloud under the current bar was computed 26 bars ago, so the cloud a trader reads today contains no information from the last 26 bars. The cloud ahead of price is the latest calculation.

In the library script the base length doubles as the displacement, so changing the base line from 26 also shifts the cloud and the lagging span by the new number.

Some traders use 7, 22 and 44 or 10, 30 and 60 on 5-day markets. The original numbers remain the reference, and the differences on a chart are small.

04

Inputs that matter

InputTypicalWhat changing it does
Conversion length9Shorter makes the conversion line hug price and cross the base line more often; longer makes crosses rarer and later.
Base length26Longer keeps the base line flatter and, in the script, pushes the cloud further ahead; shorter brings every displaced line closer to today.
Leading span B length52Longer makes span B flatter and the cloud slower to twist; shorter gives a more responsive cloud that price crosses more often.
05

In practice

  • As a regime filter: the filter keeps longs only while price holds above the cloud and shorts only below it, and nothing while price is inside. This single rule removes most of the trades that fail in ranges.
  • As a trend entry: a conversion line cross above the base line while price is above the cloud, or the mirror image below it, which is exactly the cross the library script marks and alerts on.
  • As dynamic support and resistance: pullbacks to the base line and to the top of the cloud in an uptrend are where add and re-entry rules trigger, and a close through them is the warning.
  • As a forward map: the cloud 26 bars ahead shows where price will meet support or resistance, and a twist in the cloud ahead marks a date when the balance may turn.
  • As confirmation: the lagging span must be clear of the candles 26 bars back before a breakout is trusted, because a tangled lagging span means price is still inside old business.
  • As a volatility read: a thin cloud after a sharp move means weak support, while a thick cloud built by a long trend takes far more supply to cross.
06

Where it goes wrong

  • Trading crosses that happen inside the cloud. A cross in the cloud is a neutral event; wait for one that occurs with price clear of the cloud on the right side.
  • Reading the cloud under price as today's calculation. It was projected 26 bars ago, so judge the current balance from the cloud ahead and the lines on the current bar.
  • Tuning 9, 26 and 52 to fit one chart. The numbers are the shared reference, and a fitted set that looked perfect on last year's data rarely holds.
  • Using it on choppy low timeframes. Five lines and a cloud whipsaw constantly on 1-minute charts; the system reads best on 4-hour, daily and weekly bars.
07

Compared with

Moving Average Crossover. A conversion and base line cross looks like a fast and slow moving average cross, but the lines are midpoints of ranges, and the cross is only taken with price on the right side of the cloud. That extra filter is the difference.

SuperTrend. SuperTrend is one line that flips with an ATR band, giving one rule and no context. Ichimoku gives regime, momentum, support and a forward view, at the cost of a busier chart and slower decisions.

Donchian Channels. Ichimoku's lines are Donchian midlines: the middle of the 9, 26 and 52-bar channels. A Donchian channel trades the edges of the range and reads a breakout, while Ichimoku trades the middle, projects it ahead and reads balance.

Moving Average Ribbon. A ribbon stacks averages of closes and reads their order and spread. Ichimoku stacks range midpoints and adds displacement, so the cloud is a zone ahead of price rather than a band around it, and it carries support as well as direction.

08

Build it in Quant

Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.

Open Ichimoku Cloud on the workbench chart
Drawn on real data; then audit, backtest and refine in conversation.
Open in Quant →
09

Questions

  • Why is the cloud drawn ahead of price?

    The displacement turns past balance into a future reference. Span A and span B are computed today and plotted 26 bars forward, so the cloud under any bar was the market's equilibrium 26 bars earlier. That gives price something to meet: support below in an uptrend, resistance above in a downtrend, and a twist ahead that dates a possible change of trend.

  • Does Ichimoku work on intraday charts?

    It works on 15-minute charts and above in trending markets, with the same rules. The lines were designed for daily bars, so on intraday charts the cloud is crossed more often and the regime filter matters more. Most traders read the daily cloud for direction and use the intraday lines for timing.

  • Should I change 9, 26 and 52 for a 5-day market?

    You can, and 7, 22 and 44 or 10, 30 and 60 are the usual alternatives, but most traders keep the originals. The differences on a chart are small, and the standard numbers are what other participants watch, which is part of why the levels hold. Change them only after testing the alternative.

  • What does a thin cloud mean?

    A thin cloud means span A and span B are close together, which happens after a fast move or during a range. It is weak support or resistance and price crosses it easily, so a break through a thin cloud carries less weight than one through a thick cloud built by a long trend.

  • What is a kumo twist?

    A twist is where span A crosses span B in the projected cloud, so the cloud changes colour ahead of price. It marks the bar where the 26-bar and 52-bar balances change order. A twist is not a signal on its own, but it often coincides with a change of trend, and price near a twist tends to be volatile.

  • Is a conversion and base cross enough on its own?

    No. The cross is a momentum event and it fires in every direction inside a range. The library script requires the close to be beyond the cloud on the side of the cross, and many traders also want the lagging span clear of the candles. Rules grade the cross by its position and keep the strong ones.