Trading Strategy

Ichimoku Cloud

A comprehensive trend-following system that provides data on support and resistance, trend direction, and momentum in a single glance.

The One-Look Equilibrium

Developed by Japanese journalist Goichi Hosoda, this system is designed to provide all trend, momentum, and support/resistance data in a single glance. Our version is specifically tuned for the 4h timeframe, the sweet spot for balancing signal reliability and market responsiveness in crypto assets.

Trend Type
4h Chart Timeframe
Advanced Complexity
Trending Best Market

Signal Logic

Bullish TK Cross

Triggered when price is > the Cloud, Chikou is > past price, and Tenkan-sen crosses > Kijun-sen.

Bearish TK Cross

Triggered when price is < the Cloud, Chikou is < past price, and Tenkan-sen crosses < Kijun-sen.

Implementation

//@version=6
strategy("Ichimoku Cloud Strategy", shorttitle="ICS", overlay=true, initial_capital=1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD)

// ==========================================
// 🔹 INPUTS
// ==========================================
group_ichi = "Ichimoku Settings"
tenkanLen = input.int(9, "Tenkan-sen Length", minval=1, group=group_ichi)
kijunLen  = input.int(26, "Kijun-sen Length", minval=1, group=group_ichi)
spanBLen  = input.int(52, "Senkou Span B Length", minval=1, group=group_ichi)
offset    = input.int(26, "Displacement", minval=1, group=group_ichi)

group_risk = "Risk Management"
useATR      = input.bool(true, "Use ATR Trailing Stop?", group=group_risk)
atrLen      = input.int(14, "ATR Length", group=group_risk)
atrMult     = input.float(2.0, "ATR Multiplier", step=0.1, group=group_risk)

// ==========================================
// 🔹 CALCULATIONS
// ==========================================
// Helper function for Donchian Channel (High/Low Avg)
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))

// Standard Ichimoku Lines
tenkan = donchian(tenkanLen)
kijun  = donchian(kijunLen)
spanA  = math.avg(tenkan, kijun)
spanB  = donchian(spanBLen)

// Cloud (Kumo) Calculation
// In Pine Script, we project these lines forward using `offset` in the plot, 
// but for strategy logic, we need the values that are physically *at* the current bar.
// The "Future" cloud values (26 bars ahead) are stored in variables today for validation.
futureSpanA = spanA
futureSpanB = spanB

// The "Current" cloud values (for checking if price is above/below Kumo)
// are the Span A/B values calculated 26 bars ago.
currentSpanA = spanA[offset]
currentSpanB = spanB[offset]

// Chikou Span (Lagging)
// For logic: Compare current Close to the Close of 26 bars ago.
chikouValue = close
pastPrice   = close[offset]

// ==========================================
// 🔹 LOGIC & CONDITIONS
// ==========================================

// 1. Trend Direction (Price vs Cloud)
bullishCloud = close > math.max(currentSpanA, currentSpanB)
bearishCloud = close < math.min(currentSpanA, currentSpanB)

// 2. TK Cross (Momentum)
bullishTK = ta.crossover(tenkan, kijun)
bearishTK = ta.crossunder(tenkan, kijun)

// 3. Chikou Confirmation (Momentum Persistence)
// Bullish: Current price (lagging span) is higher than price 26 bars ago
bullishChikou = chikouValue > pastPrice
// Bearish: Current price (lagging span) is lower than price 26 bars ago
bearishChikou = chikouValue < pastPrice

// 4. Future Cloud Validation (Optional but recommended)
// Ensures the cloud forming ahead is in the direction of the trade
bullishFuture = futureSpanA > futureSpanB
bearishFuture = futureSpanA < futureSpanB

// --- ENTRY SIGNALS ---
// We use a "Strong" signal approach: All conditions must be met.
longCondition  = bullishCloud and bullishTK and bullishChikou and bullishFuture
shortCondition = bearishCloud and bearishTK and bearishChikou and bearishFuture

// ==========================================
// 🔹 RISK MANAGEMENT (ATR TRAILING)
// ==========================================
// Calculate ATR
atr = ta.atr(atrLen)

// Initialize Trailing Stop variables using `var` (v6 requirement for persistent variables)
var float longStopPrice  = na
var float shortStopPrice = na

// Update Trailing Stops
if (strategy.position_size > 0)
    // For Longs: Stop moves UP only
    newStop = close - (atr * atrMult)
    longStopPrice := na(longStopPrice) ? newStop : math.max(longStopPrice, newStop)
else
    longStopPrice := na

if (strategy.position_size < 0)
    // For Shorts: Stop moves DOWN only
    newStop = close + (atr * atrMult)
    shortStopPrice := na(shortStopPrice) ? newStop : math.min(shortStopPrice, newStop)
else
    shortStopPrice := na

// ==========================================
// 🔹 STRATEGY EXECUTION
// ==========================================

if longCondition
    strategy.entry("Long", strategy.long)
    longStopPrice := close - (atr * atrMult) // Reset stop on new entry

if shortCondition
    strategy.entry("Short", strategy.short)
    shortStopPrice := close + (atr * atrMult) // Reset stop on new entry

// Exit Logic
if (strategy.position_size > 0)
    if useATR
        strategy.exit("Exit Long", "Long", stop=longStopPrice)
    // Fail-safe exit: If Price drops below Cloud
    if close < math.min(currentSpanA, currentSpanB)
        strategy.close("Long", comment="Below Cloud")

if (strategy.position_size < 0)
    if useATR
        strategy.exit("Exit Short", "Short", stop=shortStopPrice)
    // Fail-safe exit: If Price breaks above Cloud
    if close > math.max(currentSpanA, currentSpanB)
        strategy.close("Short", comment="Above Cloud")

// ==========================================
// 🔹 VISUALIZATION
// ==========================================
// Plot Tenkan and Kijun
plot(tenkan, color=color.new(#0496ff, 0), title="Tenkan-sen")
plot(kijun, color=color.new(#991515, 0), title="Kijun-sen")

// Plot Cloud (Projected forward)
p1 = plot(spanA, offset=offset, color=color.new(#009688, 90), title="Span A")
p2 = plot(spanB, offset=offset, color=color.new(#f44336, 90), title="Span B")
fill(p1, p2, color = spanA > spanB ? color.new(#009688, 85) : color.new(#f44336, 85), title="Kumo Cloud")

// Plot Trailing Stops
plot(strategy.position_size > 0 ? longStopPrice : na, style=plot.style_linebr, color=color.red, linewidth=2, title="Long Trailing SL")
plot(strategy.position_size < 0 ? shortStopPrice : na, style=plot.style_linebr, color=color.red, linewidth=2, title="Short Trailing SL")