Strategy library

Ultimate Ichimoku Cloud strategy in Pine Script

An Ichimoku entry that needs the conversion/base cross, the cloud, the lagging span and the price to agree.

Ichimoku · long and short · by antondmt · Mozilla Public License 2.0

What is its backtest worth?

A parameter sweep finds the best setting of the Ultimate Ichimoku Cloud strategy. PineTester tells you if it holds up: whether the best result was only picked after the fact, what it makes with fees, what you could have known at the time (a walk-forward on data the pick did not see) and how deep it fell along the way. On the free start, your first own backtest gets the full evaluation; its trade list and result file come with the full report or a plan.

Creates a draft on Binance BTC/USDT 4h over about six and a half years with 0.1% commission per order and 2 ticks slippage; you start it yourself. A backtest uses credits; new accounts receive free credits.

The rules

  • Enters long when the conversion line crosses above the base line, the cloud is positive, the price is above the cloud and the conversion line, and the lagging span is above the price of its displacement.
  • Enters short on the mirror image of these conditions.
  • Closes the long when the base line crosses above the conversion line and the short on the opposite cross; the optional take profit and stop loss are off by default.

What to watch for

  • Many conditions at once make entries rare; check that the backtest has enough trades.
  • Ichimoku was built for daily charts; its periods mean other time spans on 4h bars.

How PineTester judges a backtest, with its sources: how we judge results.

The Pine Script code

The author's code with its licence notice (Mozilla Public License 2.0), with these changes marked in the code: the same test conditions for every library strategy in its strategy() line – the whole account per trade (split over the entries where it adds to a position), 0.1% commission per order and 2 ticks slippage; the trading rules are unchanged; and its default Finish Date covers the whole test period (it was December 12, 2022, which cut every backtest off there). Pine Script v5; PineTester converts it to v6 automatically, so results can differ slightly from TradingView.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © antondmt
// Modified by PineTester (2026-11-13): the default Finish Date covers the whole test period (it was Dec 12 2022,
// which cut every backtest off there). Nothing else changed.
// Modified by PineTester (2026-11-14): the same test conditions for every library strategy in strategy(): 100% of equity per entry,
// 0.1% commission per order, 2 ticks slippage, initial capital 10,000. The trading rules are unchanged.
//@version=5
strategy("Ultimate Ichimoku Cloud Strategy", "UIC Strategy", true, process_orders_on_close = true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)
// Inputs {
// Backtest Range
i_time_start =              input.time(timestamp("2015-12-12T00:00:00"), "Start Date", group = "Backtest Range")
i_time_finish =             input.time(timestamp("2099-12-31T00:00:00"), "Finish Date", group = "Backtest Range")
// Ichimoku Lines
i_show_conversion =         input.bool(false, "Show Conversion Line (Tenkan Sen)", group = "Ichimoku Lines")
i_show_base =               input.bool(false, "Show Base Line (Kijun Sen)", group = "Ichimoku Lines")
i_show_lagging =            input.bool(false, "Show Lagging Span (Chikou Span)", group = "Ichimoku Lines")
i_show_span_A =             input.bool(false, "Show Leading Span A (Senkou Span A)", group = "Ichimoku Lines")
i_show_span_B =             input.bool(false, "Show Leading Span B (Senkou Span B)", group = "Ichimoku Lines")
i_show_all =                input.bool(true, "Show All Lines", group = "Ichimoku Lines")
// Ichimoku Periods
i_conversion_line_period =  input.int(9, "Conversion Period", 1, group = "Ichimoku Periods")
i_base_line_period =        input.int(26, "Base Line Period", 1, group = "Ichimoku Periods")
i_leading_span_period =     input.int(52, "Lagging Span Period", 1, group = "Ichimoku Periods")
i_displacement =            input.int(26, "Displacement", 1, group = "Ichimoku Periods")
// Ichimoku Long Conditions
i_long_cond_1 =             input.bool(true, "Conversion Crosses Base", "Conversion line crosses up on base line.", group = "Ichimoku Long Conditions")
i_long_cond_2 =             input.bool(false, "Conversion Above Base", "Conversion line is above base line", group = "Ichimoku Long Conditions")
i_long_cond_3 =             input.bool(true, "Positive Cloud", "Cloud has to be positive. Span A > Span B.", group = "Ichimoku Long Conditions")
i_long_cond_4 =             input.bool(true, "Price Above Cloud", "Price has to be above the clouds.", group = "Ichimoku Long Conditions")
i_long_cond_5 =             input.bool(true, "Positive Chikou", "Lagging span has to be higher than price at displacement.", group = "Ichimoku Long Conditions")
i_long_cond_6 =             input.bool(true, "Price Above Conversion", "Price has to be higher than conversion line.", group = "Ichimoku Long Conditions")
i_long_cond_show =          input.bool(false, "Show Condititons Visually", "Draws lines when condition is true.", group = "Ichimoku Long Conditions")
// Ichimoku Short Conditions 
i_short_cond_1 =            input.bool(true, "Base Crosses Conversion", "Base line crosses up on conversion line.", group = "Ichimoku Short Conditions")
i_short_cond_2 =            input.bool(false, "Base Above Conversion", "Base line is above conversion line", group = "Ichimoku Short Conditions")
i_short_cond_3 =            input.bool(true, "Negative Cloud", "Cloud has to be negative. Span B > Span A.", group = "Ichimoku Short Conditions")
i_short_cond_4 =            input.bool(true, "Price Below Cloud", "Price has to be below the clouds.", group = "Ichimoku Short Conditions")
i_short_cond_5 =            input.bool(true, "Negative Chikou", "Lagging span has to be lower than price at displacement.", group = "Ichimoku Short Conditions")
i_short_cond_6 =            input.bool(true, "Price Below Base", "Price has to be lower than base line.", group = "Ichimoku Short Conditions")
i_short_cond_show =         input.bool(false, "Show Condititons Visually", "Draws lines when condition is true.", group = "Ichimoku Short Conditions")
// Ichimoku Long Exit Conditions
i_sell_long_cond_1 =        input.bool(true, "Base Crosses Conversion", "Base line crosses up on conversion line.", group = "Ichimoku Long Exit Conditions")
i_sell_long_cond_2 =        input.bool(false, "Negative Chikou", "Lagging span is lower than price at displacement.", group = "Ichimoku Long Exit Conditions")
i_sell_long_cond_show =     input.bool(false, "Show Condititons Visually", "Draws lines when condition is true.", group = "Ichimoku Long Exit Conditions")
// Ichimoku Short Exit Conditions
i_sell_short_cond_1 =       input.bool(true, "Conversion Crosses Base", "Conversion line crosses up on base line.", group = "Ichimoku Short Exit Conditions")
i_sell_short_cond_2 =       input.bool(false, "Positive Chikou", "Lagging span is higher than price at displacement.", group = "Ichimoku Short Exit Conditions")
i_sell_short_cond_show =    input.bool(false, "Show Condititons Visually", "Draws lines when condition is true.", group = "Ichimoku Short Exit Conditions")
// Exits vs TP/SL
i_use_SLTP =                input.bool(false, "Use SL and TP Instead of Exits", group = "Exits vs TP/SL")
i_TP =                      input.float(2, "Take Profit (%)", group = "Exits vs TP/SL")
i_SL =                      input.float(1, "Stop Loss (%)", group = "Exits vs TP/SL")
// }
// Ichimoku Calculations {
donchian(len) =>
    math.avg(ta.lowest(len), ta.highest(len))
conversion_line = donchian(i_conversion_line_period)
base_line = donchian(i_base_line_period)
leading_span_A = math.avg(conversion_line, base_line)
leading_span_B = donchian(i_leading_span_period)
// }
// Entries and Exits Logic { 
long_entry = false
if(i_long_cond_1 or i_long_cond_2 or i_long_cond_3 or i_long_cond_4 or i_long_cond_5 or i_long_cond_6)
    long_entry := (i_long_cond_1 ? ta.crossover(conversion_line, base_line) : true) 
         and (i_long_cond_2 ? conversion_line > base_line : true)
         and (i_long_cond_3 ? leading_span_A[i_displacement - 1] > leading_span_B[i_displacement - 1] : true) 
         and (i_long_cond_4 ? close > leading_span_A[i_displacement - 1] and close > leading_span_B[i_displacement - 1] : true) 
         and (i_long_cond_5 ? close > nz(close[i_displacement + 1], close) : true) 
         and (i_long_cond_6 ? close > conversion_line : true)
         
short_entry = false
if(i_short_cond_1 or i_short_cond_2 or i_short_cond_3 or i_short_cond_4 or i_short_cond_5)
    short_entry := (i_short_cond_1 ? ta.crossunder(conversion_line, base_line) : true) 
         and (i_short_cond_2 ? base_line > conversion_line : true)
         and (i_short_cond_3 ? leading_span_A[i_displacement - 1] < leading_span_B[i_displacement - 1] : true) 
         and (i_short_cond_4 ? close < leading_span_A[i_displacement - 1] and close < leading_span_B[i_displacement - 1] : true) 
         and (i_short_cond_5 ? close < nz(close[i_displacement + 1], close) : true) 
         and (i_short_cond_6 ? close < base_line : true)
         
long_exit = false
if(i_sell_long_cond_1 or i_sell_long_cond_2)
    long_exit := (i_sell_long_cond_1 ? ta.crossunder(conversion_line, base_line) : true) 
         and (i_sell_long_cond_2 ? close < nz(close[i_displacement + 1], close) : true) 
         
short_exit = false
if(i_sell_short_cond_1 or i_sell_short_cond_2)
    short_exit := (i_sell_short_cond_1 ? ta.crossover(conversion_line, base_line) : true) 
         and (i_sell_short_cond_2 ? close > nz(close[i_displacement + 1], close) : true) 
dateRange() => 
    i_time_start <= time and time <= i_time_finish ? true : false
// }
// Entries and Exits {
if(strategy.position_size <= 0 and long_entry and dateRange())
    strategy.entry("Long", strategy.long)
if(long_exit and not i_use_SLTP)
    strategy.close("Long")
else if(i_use_SLTP)
    strategy.exit("TP/SL", "Long", stop = strategy.position_avg_price * (1 - i_SL / 100), limit = strategy.position_avg_price * (1 + i_TP / 100))
if(strategy.position_size >= 0 and short_entry and dateRange())
    strategy.entry("Short", strategy.short)
if(short_exit and not i_use_SLTP)
    strategy.close("Short")
else if(i_use_SLTP)
    strategy.exit("TP/SL", "Short", stop = strategy.position_avg_price * (1 + i_SL / 100), limit = strategy.position_avg_price * (1 - i_TP / 100))
// }
// Plots { 
plot(i_show_all or i_show_conversion ? conversion_line : na, "Conversion Line (Tenkan Sen)", color.new(#0496ff, 0), 2)
plot(i_show_all or i_show_base ? base_line : na, "Base Line (Kijun Sen)", color.new(#991515, 0), 2)
plot(i_show_all or i_show_lagging ? close : na, "Lagging Span (Chikou Span)", color.new(color.yellow, 0), 2, offset = -i_displacement + 1)
span_A = plot(i_show_all or i_show_span_A ? leading_span_A : na, "Leading Span A (Senkou Span A)", color.new(color.green, 0), offset = i_displacement - 1)
span_B = plot(i_show_all or i_show_span_B ? leading_span_B : na, "Leading Span B (Senkou Span B)", color.new(color.red, 0), offset = i_displacement - 1)
fill(span_A, span_B, leading_span_A > leading_span_B ? color.new(color.green, 90) : color.new(color.red, 90), "Cloud Colors")
bgcolor(i_long_cond_show and long_entry ? color.new(color.green, 40) : na)
bgcolor(i_short_cond_show and short_entry ? color.new(color.red, 40) : na)
bgcolor(i_sell_long_cond_show and long_exit ? color.new(color.purple, 40) : na)
bgcolor(i_sell_short_cond_show and short_exit ? color.new(color.aqua, 40) : na)
// }
  • Ichimoku Cloud with ADX – An Ichimoku trend signal with a filter on the strength of the trend (ADX and the directional indicators).
  • Bollinger Bands Trend Following – A close outside the Bollinger Bands, in the direction of two EMAs, opens a trend trade with an ATR stop.

Open-source script by antondmt, shown under the Mozilla Public License 2.0. Not a recommendation; neither the author nor TradingView endorses PineTester. Backtests are hypothetical results on past data, not a forecast.