Pine Script v5 · Strategy
Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule)
A Pine Script v5 strategy built on DMI (14, 14). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 30% of equity and pays 0.1% commission. 10 settings; defaults include Tenkan-Sen Bars 9, Kijun-Sen Bars 26 and Senkou-Span B Bars 52.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 12 of 12 trades.
- How did Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) do on BTCUSDT 1D with default settings?
- −0.06%
- From 26 Jan 2024 to 21 Oct 2026, over 51 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L34:C85: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) use a stop loss?
- Yes
- strategy.exit sets a stop on line 65.
- Does Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 58 ms, in the browser.
BTCUSDT · 1D · default settings
- Tenkan-Sen
- Kijun-Sen
- Chikou-Span
- Senkou-Span A
- Senkou-Span B
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.06%
- −$0.58
- Buy and hold
- +102.5%
- same period
- Closed trades
- 51
- 18 won · 33 lost
- Profitable
- 35.3%
- of closed trades
- Profit factor
- 1.00
- gross profit ÷ gross loss
- Max drawdown
- 8.13%
- −$83.89
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
2 settings do nothing
“Show Date Range”, “Short Entry” are declared but never read.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 64. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Show Date Range | true | bool | unused |
| Tenkan-Sen Bars | 9 | int · min 1 | tenkan |
| Kijun-Sen Bars | 26 | int · min 1 | kijun |
| Senkou-Span B Bars | 52 | int · min 1 | senkouB |
| Chikou-Span Offset | 26 | int · min 1 | cs_cross_bull cs_cross_bear Chikou-Span |
| Senkou-Span Offset | 26 | int · min 1 | Senkou-Span A Senkou-Span B ss_high ss_low |
| Long Entry | true | bool | entry Long |
| Short Entry | true | bool | unused |
| Trail Long Loss (%) | 3 | float · min 0.0 · step 0.1 | longStopPrice stopValue |
| Trail Short Loss (%) | 3 | float · min 0.0 · step 0.1 | shortStopPrice stopValue |
What it calculates
- DMI14, 14
pos_dm · line 38 - DMI14, 14
neg_dm · line 38 - DMI14, 14
avg_dm · line 38
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | bullish and long_entry and timePeriod | On | 64 |
| Exit Long stop and limit | every bar | On | 65 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −0.1% | +102.5% | 51 | 35% | 1.00 | 8.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.9% | +5.5% | 15 | 20% | 0.88 | 5.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.0% | +9.8% | 56 | 39% | 1.00 | 14.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.8% | +8.4% | 21 | 33% | 1.08 | 5.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.1% | +16.7% | 71 | 41% | 1.05 | 17.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +3.5% | +21.5% | 23 | 30% | 1.30 | 5.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +16.9% | +148.3% | 54 | 44% | 1.53 | 8.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.8% | +17.1% | 18 | 28% | 1.22 | 6.8% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 22 | 27% | $30.14 |
| Sideways market | 27 | 41% | −$39.25 |
| Falling market | 2 | 50% | $8.53 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
13.9%
The 95th percentile of the worst drawdown when the same 51 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 6.4% to 13.9%; the tick is what actually happened, 7.9%. Order luck alone moves it this much.
All 51 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 11 Apr 2024 70,006.20 | 13 Apr 2024 65,103.00 | 2 | −$21.57 |
| long | 17 May 2024 67,024.00 | 21 May 2024 69,303.20 | 4 | $9.38 |
| long | 21 May 2024 70,148.30 | 23 May 2024 67,091.60 | 2 | −$13.48 |
| long | 23 May 2024 67,969.60 | 28 May 2024 67,353.30 | 5 | −$3.23 |
| long | 28 May 2024 68,398.40 | 7 Jun 2024 68,974.80 | 10 | $1.87 |
| long | 7 Jun 2024 69,355.60 | 11 Jun 2024 67,558.70 | 4 | −$8.13 |
| long | 19 Jul 2024 66,660.00 | 23 Jul 2024 66,120.40 | 4 | −$2.92 |
| long | 23 Jul 2024 65,936.00 | 30 Jul 2024 66,202.40 | 7 | $0.59 |
| long | 30 Jul 2024 66,188.00 | 1 Aug 2024 62,689.20 | 2 | −$15.81 |
| long | 20 Sep 2024 63,201.10 | 30 Sep 2024 63,882.30 | 10 | $2.49 |
| long | 30 Sep 2024 63,327.60 | 9 Oct 2024 60,935.30 | 9 | −$11.30 |
| long | 19 Oct 2024 68,378.00 | 21 Oct 2024 66,961.00 | 2 | −$6.38 |
| long | 21 Oct 2024 67,377.50 | 23 Oct 2024 65,403.20 | 2 | −$8.73 |
| long | 23 Oct 2024 66,668.60 | 25 Oct 2024 66,152.30 | 2 | −$2.69 |
| long | 25 Oct 2024 66,698.30 | 31 Oct 2024 70,554.30 | 6 | $15.37 |
| long | 31 Oct 2024 70,292.00 | 4 Nov 2024 67,411.10 | 4 | −$12.04 |
| long | 4 Nov 2024 67,850.00 | 12 Nov 2024 85,988.60 | 8 | $73.36 |
| long | 12 Nov 2024 87,952.00 | 14 Nov 2024 87,663.90 | 2 | −$1.57 |
| long | 14 Nov 2024 87,325.60 | 24 Nov 2024 95,925.20 | 10 | $28.75 |
| long | 3 Dec 2024 95,849.70 | 5 Dec 2024 95,629.70 | 2 | −$1.32 |
| long | 5 Dec 2024 96,945.60 | 9 Dec 2024 98,076.30 | 4 | $2.96 |
| long | 9 Dec 2024 97,276.50 | 18 Dec 2024 102,950.00 | 9 | $17.29 |
| long | 18 Dec 2024 100,204.00 | 20 Dec 2024 94,538.00 | 2 | −$18.28 |
| long | 22 Jan 2025 103,707.00 | 27 Jan 2025 101,724.00 | 5 | −$6.48 |
| long | 22 Apr 2025 93,443.00 | 5 May 2025 93,980.50 | 13 | $1.14 |
| long | 5 May 2025 94,733.70 | 12 May 2025 101,665.00 | 7 | $21.72 |
| long | 12 May 2025 102,791.00 | 19 May 2025 103,261.00 | 7 | $0.80 |
| long | 19 May 2025 105,574.00 | 23 May 2025 108,345.00 | 4 | $7.56 |
| long | 23 May 2025 107,318.00 | 29 May 2025 106,152.00 | 6 | −$4.04 |
| long | 29 May 2025 105,590.00 | 5 Jun 2025 102,682.00 | 7 | −$9.24 |
| long | 2 Jul 2025 108,850.00 | 15 Jul 2025 116,246.00 | 13 | $20.46 |
| long | 15 Jul 2025 117,758.00 | 25 Jul 2025 116,356.00 | 10 | −$4.40 |
| long | 25 Jul 2025 117,614.00 | 30 Jul 2025 115,833.00 | 5 | −$5.40 |
| long | 30 Jul 2025 117,840.00 | 2 Aug 2025 112,291.00 | 3 | −$15.38 |
| long | 12 Aug 2025 120,134.00 | 14 Aug 2025 119,607.00 | 2 | −$1.97 |
| long | 14 Aug 2025 118,295.00 | 19 Aug 2025 113,883.00 | 5 | −$12.11 |
| long | 18 Sep 2025 117,074.00 | 22 Sep 2025 112,215.00 | 4 | −$13.25 |
| long | 5 Oct 2025 123,482.00 | 7 Oct 2025 120,919.00 | 2 | −$6.84 |
| long | 7 Oct 2025 121,333.00 | 10 Oct 2025 119,607.00 | 3 | −$4.84 |
| long | 14 Jan 2026 96,951.80 | 19 Jan 2026 92,736.60 | 5 | −$13.51 |
| long | 15 Apr 2026 74,810.00 | 19 Apr 2026 74,759.80 | 4 | −$0.78 |
| long | 19 Apr 2026 73,801.80 | 28 Apr 2026 76,297.80 | 9 | $9.32 |
| long | 28 Apr 2026 76,342.80 | 13 May 2026 79,743.80 | 15 | $12.58 |
| long | 13 May 2026 79,313.60 | 16 May 2026 78,657.30 | 3 | −$3.08 |
| long | 16 May 2026 78,148.10 | 23 May 2026 75,287.10 | 7 | −$11.52 |
| long | 19 Aug 2026 69,334.80 | 23 Aug 2026 75,987.90 | 4 | $27.72 |
| long | 23 Aug 2026 77,734.00 | 28 Aug 2026 77,842.10 | 5 | −$0.19 |
| long | 28 Aug 2026 77,845.90 | 4 Sep 2026 78,832.30 | 7 | $3.24 |
| long | 12 Sep 2026 77,278.70 | 15 Sep 2026 75,843.50 | 3 | −$6.26 |
| long | 24 Sep 2026 84,410.20 | 7 Oct 2026 83,934.10 | 13 | −$2.31 |
| long | 7 Oct 2026 83,321.80 | 13 Oct 2026 81,259.90 | 6 | −$8.07 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Ichimoku Cloud and ADX with Trailing Stop Loss (by Coinrule) this page | — | v5 strategy | −0.1% | 51 | 8.1% |
| Ichimoku Cloud with ADX (By Coinrule) by Coinrule | dmi | v5 strategy | −16.8% | 6 | 21.9% |
| ADX and DMI by Zeal Terminal | dmi | v5 indicator | indicator | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 1 strategy call uses the when = argument (line 64). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 3 settings use the untyped input() (line 12, 20, 21). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 51 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 12: input() → input.bool()
- Line 20: input() → input.bool()
- Line 21: input() → input.bool()
- Line 64: when = bullish and long_entry and timePeriod → if block
⋯ commission_value=0.1)-showDate = input(defval=true, title='Show Date Range')+showDate = input.bool(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2018, 1, 1, 0, 0)⋯ss_offset = input.int(26, minval=1, title='Senkou-Span Offset')-long_entry = input(true, title='Long Entry')+long_entry = input.bool(true, title='Long Entry')-short_entry = input(true, title='Short Entry')+short_entry = input.bool(true, title='Short Entry')middle(len) => math.avg(ta.lowest(len), ta.highest(len))⋯ 999999-strategy.entry('Long', strategy.long, when=bullish and long_entry and timePeriod)+if bullish and long_entry and timePeriod+ strategy.entry('Long', strategy.long)strategy.exit('Long', stop = longStopPrice, limit = shortStopPrice)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L34:C85: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Coinrule-//@version=5+//@version=6strategy('Ichimoku Cloud with ADX with Trailing Stop Loss',⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | Yes 1,000 bars in 58 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Coinrule//@version=5strategy('Ichimoku Cloud with ADX with Trailing Stop Loss', overlay=true, initial_capital=1000, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=30, commission_type=strategy.commission.percent, commission_value=0.1)showDate = input(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2018, 1, 1, 0, 0)// Inputsts_bars = input.int(9, minval=1, title='Tenkan-Sen Bars')ks_bars = input.int(26, minval=1, title='Kijun-Sen Bars')ssb_bars = input.int(52, minval=1, title='Senkou-Span B Bars')cs_offset = input.int(26, minval=1, title='Chikou-Span Offset')ss_offset = input.int(26, minval=1, title='Senkou-Span Offset')long_entry = input(true, title='Long Entry')short_entry = input(true, title='Short Entry')middle(len) => math.avg(ta.lowest(len), ta.highest(len))// Ichimoku Componentstenkan = middle(ts_bars)kijun = middle(ks_bars)senkouA = math.avg(tenkan, kijun)senkouB = middle(ssb_bars)// Plot Ichimoku Kinko Hyoplot(tenkan, color=color.new(#0496ff, 0), title='Tenkan-Sen')plot(kijun, color=color.new(#991515, 0), title='Kijun-Sen')plot(close, offset=-cs_offset + 1, color=color.new(#459915, 0), title='Chikou-Span')sa = plot(senkouA, offset=ss_offset - 1, color=color.new(color.green, 0), title='Senkou-Span A')sb = plot(senkouB, offset=ss_offset - 1, color=color.new(color.red, 0), title='Senkou-Span B')fill(sa, sb, color=senkouA > senkouB ? color.green : color.red, title='Cloud color', transp=90)ss_high = math.max(senkouA[ss_offset - 1], senkouB[ss_offset - 1])ss_low = math.min(senkouA[ss_offset - 1], senkouB[ss_offset - 1])// ADX[pos_dm, neg_dm, avg_dm] = ta.dmi(14, 14)// Entry/Exit Signalstk_cross_bull = tenkan > kijuntk_cross_bear = tenkan < kijuncs_cross_bull = ta.mom(close, cs_offset - 1) > 0cs_cross_bear = ta.mom(close, cs_offset - 1) < 0price_above_kumo = close > ss_highprice_below_kumo = close < ss_lowbullish = tk_cross_bull and cs_cross_bull and price_above_kumo and avg_dm < 45 and pos_dm > neg_dmbearish = tk_cross_bear and cs_cross_bear and price_below_kumo and avg_dm > 45 and pos_dm < neg_dm// Configure trail stop level with input optionslongTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=3) * 0.01shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=3) * 0.01// Determine trail stop loss priceslongStopPrice = 0.0shortStopPrice = 0.0longStopPrice := if strategy.position_size > 0 stopValue = close * (1 - longTrailPerc) math.max(stopValue, longStopPrice[1])else 0shortStopPrice := if strategy.position_size < 0 stopValue = close * (1 + shortTrailPerc) math.min(stopValue, shortStopPrice[1])else 999999strategy.entry('Long', strategy.long, when=bullish and long_entry and timePeriod)strategy.exit('Long', stop = longStopPrice, limit = shortStopPrice)//strategy.entry('Short', strategy.short, when=bearish and short_entry and timePeriod)//strategy.exit('Short', stop = longStopPrice, limit = shortStopPrice)