What it measures
Ichimoku Kinko Hyo, usually shortened to Ichimoku or "the cloud", packs trend direction, momentum and support and resistance zones into one overlay. It was developed by the Japanese journalist Goichi Hosoda and published in the late 1960s.
It looks busy because it has five lines, but every one of them is built the same way: the midpoint of the highest high and lowest low over some window. Two of them are then shifted forward in time to form the cloud, and one is shifted back.
The formula in words
| Line | Built from | Shifted |
|---|---|---|
| Tenkan-sen (conversion line) | Midpoint of the highest high and lowest low of the last 9 bars | No |
| Kijun-sen (base line) | Midpoint of the last 26 bars | No |
| Senkou span A | Average of Tenkan-sen and Kijun-sen | 26 bars forward |
| Senkou span B | Midpoint of the last 52 bars | 26 bars forward |
| Chikou span (lagging line) | The close | 26 bars back |
The area between the two Senkou spans is the cloud (kumo). Because the spans are shifted forward, the cloud you see above or below the current bar was calculated 26 bars earlier, and the cloud to the right of the last bar is a projection of today's values.
How traders read it
- Price versus the cloud. Above the cloud is read as an uptrend, below as a downtrend, inside as no clear trend. A close through the cloud is a significant change in that reading.
- Cloud colour and thickness. Span A above span B gives a "bullish" cloud; the reverse a "bearish" one. A thick cloud is seen as a stronger support or resistance zone than a thin one.
- Tenkan / Kijun crosses. The faster line crossing the slower one works like a moving-average cross. Crosses above the cloud are considered stronger for longs than crosses inside or below it.
- Kijun-sen as a level. In trends price often pulls back to the base line, which some traders use as a trailing stop.
- Chikou span. The close drawn 26 bars back is compared with the price of that time: above it supports a bullish reading.
Common settings
| Setting | Default | Notes |
|---|---|---|
| Tenkan-sen | 9 | |
| Kijun-sen | 26 | |
| Senkou span B | 52 | |
| Displacement | 26 | How far the spans are shifted. |
The defaults date from a six-day trading week. Some crypto traders scale them up (20 / 60 / 120 / 30 is one variant) for markets that trade every day. Like any change, test it before you rely on it.
Pine Script v6 code
The complete, self-contained script is below. Copy it into a new indicator in TradingView's Pine Editor, or download the .pine file.
//@version=6
indicator("Ichimoku Cloud", shorttitle = "Ichimoku", overlay = true)
tenkanLen = input.int(9, "Tenkan-sen length", minval = 1)
kijunLen = input.int(26, "Kijun-sen length", minval = 1)
spanBLen = input.int(52, "Senkou span B length", minval = 1)
shift = input.int(26, "Displacement", minval = 1)
midpoint(len) =>
math.avg(ta.highest(high, len), ta.lowest(low, len))
tenkan = midpoint(tenkanLen)
kijun = midpoint(kijunLen)
spanA = math.avg(tenkan, kijun)
spanB = midpoint(spanBLen)
plot(tenkan, "Tenkan-sen", color = color.new(color.blue, 0))
plot(kijun, "Kijun-sen", color = color.new(color.maroon, 0))
plot(close, "Chikou span", color = color.new(color.gray, 20), offset = -shift + 1)
spanAPlot = plot(spanA, "Senkou span A", color = color.new(color.teal, 40), offset = shift - 1)
spanBPlot = plot(spanB, "Senkou span B", color = color.new(color.red, 40), offset = shift - 1)
fill(spanAPlot, spanBPlot, color = spanA > spanB ? color.new(color.teal, 85) : color.new(color.red, 85), title = "Cloud")
// The cloud under the current bar was calculated shift - 1 bars ago.
cloudTop = math.max(spanA[shift - 1], spanB[shift - 1])
cloudBottom = math.min(spanA[shift - 1], spanB[shift - 1])
aboveCloud = close > cloudTop
belowCloud = close < cloudBottom
breakUp = aboveCloud and not aboveCloud[1]
breakDown = belowCloud and not belowCloud[1]
tkCrossUp = ta.crossover(tenkan, kijun)
tkCrossDown = ta.crossunder(tenkan, kijun)
alertcondition(breakUp, "Close above the cloud", "{{ticker}} closed above the Ichimoku cloud ({{interval}})")
alertcondition(breakDown, "Close below the cloud", "{{ticker}} closed below the Ichimoku cloud ({{interval}})")
alertcondition(tkCrossUp, "Tenkan crosses above Kijun", "Tenkan-sen crossed above Kijun-sen on {{ticker}} ({{interval}})")
alertcondition(tkCrossDown, "Tenkan crosses below Kijun", "Tenkan-sen crossed below Kijun-sen on {{ticker}} ({{interval}})")All five lines are built from one small midpoint() function, which makes the structure of Ichimoku easy to see. The spans are shifted forward and the Chikou span back by displacement − 1 bars, counting the current bar as the first of the 26, which is the convention TradingView's own Ichimoku follows.
The alert conditions compare the close with the cloud under the current bar (the values from shift − 1 bars ago), not with the projected cloud to the right, and cover cloud breaks and Tenkan/Kijun crosses.
Add it to your chart
- Open any chart on TradingView and open the Pine Editor.
- Create a new indicator, delete the template code and paste the script.
- Click Save, then Add to chart. Change lengths and levels from the indicator's settings.
Stuck on an error? See how to add a Pine Script indicator to TradingView.
Pitfalls
- Reading the Chikou span as a live signal. It is the current close drawn in the past. Its last 25 values are only visible because they were shifted back; never use it as if it had been known at those bars.
- Using the projected cloud in rules. The cloud to the right of the last bar is today's calculation shown in the future. For signals, compare price with the cloud under the current bar, as the script does.
- Too many conditions. Requiring every Ichimoku condition to agree produces very few, very late signals. Decide which two or three matter to you.
- Settings from another market. The defaults come from a six-day trading week. They still work as a convention, but don't assume they are optimal anywhere.
Related reading
- Pine Script repainting: how to spot it, test for it and fix it
- Multi-timeframe Pine Script with request.security(), without repainting
- Risk/Reward Calculator (free tool)
- ATR Stop-Loss Calculator (free tool)
The script is an educational example: test it on your own markets before relying on it. Indicators describe the past; they don't predict the future. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.