Strategy · Pine Script v5 · On the chart

Ichimoku Cloud Strategy

by Basant1Saini· code credited to TradingTools

This strategy plots Ichimoku Cloud components on the price chart and generates trades based on trend confirmation.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code91
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update7 months ago4 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

91 lines of Pine Script v5 from 9_Ichimoku_Cloud/9_Ichimoku_Cloud.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

9_Ichimoku_Cloud.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © TradingTools

//@version=5
strategy("Ichimoku Cloud Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ─── Inputs ───
tenkanLen       = input.int(9, "Tenkan-Sen (Conversion)", group="Ichimoku")
kijunLen        = input.int(26, "Kijun-Sen (Base)", group="Ichimoku")
senkouBLen      = input.int(52, "Senkou Span B", group="Ichimoku")
displacement    = input.int(26, "Cloud Displacement", group="Ichimoku")
useTKCross      = input.bool(true, "Use TK Cross Entry", group="Entry Mode")
useCloudBreak   = input.bool(true, "Use Cloud Breakout Entry", group="Entry Mode")
useChikouConf   = input.bool(true, "Require Chikou Confirmation", group="Filters")
atrLength       = input.int(14, "ATR Length", group="Risk Management")
atrMult         = input.float(2.0, "ATR Multiplier for SL", step=0.1, group="Risk Management")
trailAtrMult    = input.float(3.0, "Trailing Stop ATR Mult", step=0.1, group="Risk Management")

// ─── Ichimoku Components ───
tenkan  = (ta.highest(high, tenkanLen) + ta.lowest(low, tenkanLen)) / 2
kijun   = (ta.highest(high, kijunLen) + ta.lowest(low, kijunLen)) / 2
senkouA = (tenkan + kijun) / 2
senkouB = (ta.highest(high, senkouBLen) + ta.lowest(low, senkouBLen)) / 2

// Current cloud (for position relative to cloud)
cloudTop    = math.max(senkouA[displacement], senkouB[displacement])
cloudBottom = math.min(senkouA[displacement], senkouB[displacement])

// Chikou Span (close plotted 26 bars back — compare current close to price 26 bars ago)
chikouBull = close > close[displacement]
chikouBear = close < close[displacement]

// ─── ATR ───
atrVal = ta.atr(atrLength)

// ─── Conditions ───
aboveCloud = close > cloudTop
belowCloud = close < cloudBottom

tkCrossLong  = ta.crossover(tenkan, kijun)
tkCrossShort = ta.crossunder(tenkan, kijun)

cloudBreakLong  = ta.crossover(close, cloudTop)
cloudBreakShort = ta.crossunder(close, cloudBottom)

chikouOK_long  = useChikouConf ? chikouBull : true
chikouOK_short = useChikouConf ? chikouBear : true

// ─── Entry ───
longTK    = useTKCross and tkCrossLong and aboveCloud and chikouOK_long
longCloud = useCloudBreak and cloudBreakLong and tenkan > kijun and chikouOK_long

shortTK    = useTKCross and tkCrossShort and belowCloud and chikouOK_short
shortCloud = useCloudBreak and cloudBreakShort and tenkan < kijun and chikouOK_short

longCondition  = longTK or longCloud
shortCondition = shortTK or shortCloud

// ─── Execute Trades ───
if longCondition and strategy.position_size <= 0
    sl = close - atrVal * atrMult
    strategy.entry("Ichi Long", strategy.long)
    strategy.exit("Ichi Long Exit", "Ichi Long", stop=sl, trail_offset=atrVal * trailAtrMult, trail_points=atrVal * trailAtrMult)

if shortCondition and strategy.position_size >= 0
    sl = close + atrVal * atrMult
    strategy.entry("Ichi Short", strategy.short)
    strategy.exit("Ichi Short Exit", "Ichi Short", stop=sl, trail_offset=atrVal * trailAtrMult, trail_points=atrVal * trailAtrMult)

// ─── Exit on Opposite TK Cross ───
if strategy.position_size > 0 and tkCrossShort
    strategy.close("Ichi Long", comment="TK Cross Exit")
if strategy.position_size < 0 and tkCrossLong
    strategy.close("Ichi Short", comment="TK Cross Exit")

// ─── Plotting ───
plot(tenkan, "Tenkan-Sen", color=color.new(color.blue, 0), linewidth=1)
plot(kijun, "Kijun-Sen", color=color.new(color.red, 0), linewidth=1)

senkouAPlot = plot(senkouA, "Senkou A", offset=displacement, color=color.new(color.green, 0))
senkouBPlot = plot(senkouB, "Senkou B", offset=displacement, color=color.new(color.red, 0))
fill(senkouAPlot, senkouBPlot, color=senkouA > senkouB ? color.new(color.green, 85) : color.new(color.red, 85), title="Cloud")

plot(close, "Chikou Span", offset=-displacement, color=color.new(color.purple, 20), linewidth=1)

plotshape(longCondition, title="Long", location=location.belowbar, style=shape.triangleup, color=color.green, size=size.small)
plotshape(shortCondition, title="Short", location=location.abovebar, style=shape.triangledown, color=color.red, size=size.small)

// ─── Alerts ───
alertcondition(longCondition, title="Ichimoku Long", message="Ichimoku: Bullish signal — Long entry")
alertcondition(shortCondition, title="Ichimoku Short", message="Ichimoku: Bearish signal — Short entry")

Overview

Ichimoku Cloud Strategy enters long when a bullish Tenkan-Kijun cross occurs above the cloud or upon a bullish cloud breakout, with optional Chikou Span confirmation. Short positions enter under opposite conditions below the cloud. Trades exit on an opposing Tenkan-Kijun crossover or through dynamic ATR-based initial stops and trailing stops. User settings adjust line lengths, displacement, entry mode toggles, and risk multipliers. Position sizing allocates available equity per trade.

Details

Published by

Basant1Saini on GitHub

Code credit

TradingTools, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Breakout, Moving averages

Markets

Stocks

Timeframes

M15-H1, H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tenkan-Sen (Conversion)int9tenkanLen
Kijun-Sen (Base)int26kijunLen
Senkou Span Bint52senkouBLen
Cloud Displacementint26displacement
Use TK Cross EntrybooltrueuseTKCross
Use Cloud Breakout EntrybooltrueuseCloudBreak
Require Chikou ConfirmationbooltrueuseChikouConf
ATR Lengthint14atrLength
ATR Multiplier for SLfloat2.0atrMult
Trailing Stop ATR Multfloat3.0trailAtrMult
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
43 stars

This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-

Strategy v5 TrendBreakout Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m - Strategy Candle Bar

ADA4H Optuna Strategy

by skywalker0803r
42 stars

This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy
16 stars

This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers