Pine Script v4 · Strategy
Ichimoku with MACD- CMF- TSI
A Pine Script v4 strategy built on SMA or EMA (close, 17), EMA (close, 8) and Change (price). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 16 settings; defaults include Tenkan-Sen Bars 10, Kijun-Sen Bars 30 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 with MACD- CMF- TSI repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did Ichimoku with MACD- CMF- TSI do on BTCUSDT 1D with default settings?
- +28.62%
- From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Ichimoku with MACD- CMF- TSI be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does Ichimoku with MACD- CMF- TSI use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Ichimoku with MACD- CMF- TSI run in Zeal Terminal?
- Yes
- It compiles in 13 ms and runs 1,000 bars in 59 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +28.62%
- $28,615.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 14
- 6 won · 8 lost
- Profitable
- 42.9%
- of closed trades
- Profit factor
- 1.60
- gross profit ÷ gross loss
- Max drawdown
- 38.74%
- −$38,743.10
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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 57, 58, 59, 60. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames avg → math.avg, lowest → ta.lowest, highest → ta.highest, max → math.max, min → math.min, sma → ta.sma, ema → ta.ema, mom → ta.mom, sum → math.sum, change → ta.change, abs → math.abs.
- 4 strategy calls use the when = argument (line 57, 58, 59, 60). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 13: avg → math.avg
- Line 13: lowest → ta.lowest
- Line 13: highest → ta.highest
- Line 17: avg → math.avg
- Line 19: max → math.max
23 more edits
- Line 20: min → math.min
- Line 22: input(type = input.integer) → input.int()
- Line 23: input(type = input.integer) → input.int()
- Line 24: input(type = input.source) → input.source()
- Line 25: input(type = input.integer) → input.int()
- Line 26: input(type = input.bool) → input.bool()
- Line 27: input(type = input.bool) → input.bool()
- Line 29: sma → ta.sma
- Line 29: ema → ta.ema
- Line 30: sma → ta.sma
- Line 30: ema → ta.ema
- Line 32: sma → ta.sma
- Line 32: ema → ta.ema
- Line 36: mom → ta.mom
- Line 37: mom → ta.mom
- Line 43: sum → math.sum
- Line 43: sum → math.sum
- Line 45: input(type = input.integer) → input.int()
- Line 46: input(type = input.integer) → input.int()
- Line 49: ema → ta.ema
- Line 50: ema → ta.ema
- Line 51: change → ta.change
- Line 53: abs → math.abs
⋯// © exlux99-//@version=4+//@version=5strategy("Ichimoku with MACD/ CMF/ TSI", overlay=true, margin_long=0, margin_short=0)⋯short_entry = input(true, title="Short Entry")-middle(len) => avg(lowest(len), highest(len))+middle(len) => math.avg(ta.lowest(len), ta.highest(len))// Ichimoku Components⋯kijun = middle(ks_bars)-senkouA = avg(tenkan, kijun)+senkouA = math.avg(tenkan, kijun)senkouB = middle(ssb_bars)-ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1])+ss_high = math.max(senkouA[ss_offset-1], senkouB[ss_offset-1])-ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1])+ss_low = math.min(senkouA[ss_offset-1], senkouB[ss_offset-1])// Entry/Exit Signals-fast_length = input(title="Fast Length", type=input.integer, defval=17)+fast_length = input.int(title="Fast Length", defval=17)-slow_length = input(title="Slow Length", type=input.integer, defval=28)+slow_length = input.int(title="Slow Length", defval=28)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 5)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 5)-sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)+sma_source = input.bool(title="Simple MA(Oscillator)", defval=true)-sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=true)+sma_signal = input.bool(title="Simple MA(Signal Line)", defval=true)// Calculating-fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯tk_cross_bear = tenkan < kijun-cs_cross_bull = mom(close, cs_offset-1) > 0+cs_cross_bull = ta.mom(close, cs_offset-1) > 0-cs_cross_bear = mom(close, cs_offset-1) < 0+cs_cross_bear = ta.mom(close, cs_offset-1) < 0price_above_kumo = close > ss_high⋯ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume-mf = sum(ad, lengthA) / sum(volume, lengthA)+mf = math.sum(ad, lengthA) / math.sum(volume, lengthA)//TSI-long = input(title="Long Length", type=input.integer, defval=8)+long = input.int(title="Long Length", defval=8)-short = input(title="Short Length", type=input.integer, defval=8)+short = input.int(title="Short Length", defval=8)price = closedouble_smooth(src, long, short) =>- fist_smooth = ema(src, long)+ fist_smooth = ta.ema(src, long)- ema(fist_smooth, short)+ ta.ema(fist_smooth, short)-pc = change(price)+pc = ta.change(price)double_smoothed_pc = double_smooth(pc, long, short)-double_smoothed_abs_pc = double_smooth(abs(pc), long, short)+double_smoothed_abs_pc = double_smooth(math.abs(pc), long, short)tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)⋯Same 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.bool()
6 more edits
- Line 12: input() → input.bool()
- Line 41: input() → input.int()
- Line 57: when = bullish and long_entry → if block
- Line 58: when = bearish and short_entry → if block
- Line 59: when = bearish and not short_entry → if block
- Line 60: when = bullish and not long_entry → if block
⋯//Inputs-ts_bars = input(10, minval=1, title="Tenkan-Sen Bars")+ts_bars = input.int(10, minval=1, title="Tenkan-Sen Bars")-ks_bars = input(30, minval=1, title="Kijun-Sen Bars")+ks_bars = input.int(30, minval=1, title="Kijun-Sen Bars")-ssb_bars = input(52, minval=1, title="Senkou-Span B Bars")+ssb_bars = input.int(52, minval=1, title="Senkou-Span B Bars")-cs_offset = input(26, minval=1, title="Chikou-Span Offset")+cs_offset = input.int(26, minval=1, title="Chikou-Span Offset")-ss_offset = input(26, minval=1, title="Senkou-Span Offset")+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))⋯//CMF-lengthA = input(8, minval=1, title="CMF Length")+lengthA = input.int(8, minval=1, title="CMF Length")ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume⋯bearish = tk_cross_bear and cs_cross_bear and price_below_kumo and hist < 0 and mf < -0.1 and tsi_value < 0-strategy.entry("Long", strategy.long, when=bullish and long_entry)+if bullish and long_entry+ strategy.entry("Long", strategy.long)-strategy.entry("Short", strategy.short, when=bearish and short_entry)+if bearish and short_entry+ strategy.entry("Short", strategy.short)-strategy.close("Long", when=bearish and not short_entry)+if bearish and not short_entry+ strategy.close("Long")-strategy.close("Short", when=bullish and not long_entry)+if bullish and not long_entry+ strategy.close("Short")Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 14 before, 14 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © exlux99-//@version=5+//@version=6strategy("Ichimoku with MACD/ CMF/ TSI", overlay=true, margin_long=0, margin_short=0)⋯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 |
|---|---|---|---|
| Tenkan-Sen Bars | 10 | int · min 1 | tenkan |
| Kijun-Sen Bars | 30 | 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 |
| Senkou-Span Offset | 26 | int · min 1 | ss_high ss_low |
| Long Entry | true | bool | entry Long close Short |
| Short Entry | true | bool | entry Short close Long |
| Fast Length | 17 | int (written input.integer) | fast_ma |
| Slow Length | 28 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma fist_smooth |
| Signal Smoothing | 5 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA(Oscillator) | true | bool | fast_ma slow_ma |
| Simple MA(Signal Line) | true | bool | signal |
| CMF Length | 8 | int · min 1 | mf |
| Long Length | 8 | int (written input.integer) | fist_smooth double_smoothed_pc double_smoothed_abs_pc |
| Short Length | 8 | int (written input.integer) | double_smoothed_pc double_smoothed_abs_pc line 50 |
What it calculates
- SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (17)fast_ma · line 29 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (28)slow_ma · line 30 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (5)signal · line 32 - EMA (
ema,ta.emain v5)Source (close), Long Length (8)fist_smooth · line 49 - Change (
change,ta.changein v5)pricepc · line 51
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 | On | 57 |
| Open Short short | bearish and short_entry | On | 58 |
| Close Long | bearish and not short_entry | On | 59 |
| Close Short | bullish and not long_entry | On | 60 |
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 timingOrders fill at the next bar's open, after the signal bar has closed.
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 | +28.6% | +102.5% | 14 | 43% | 1.60 | 38.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +20.9% | +5.5% | 11 | 55% | 3.56 | 7.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.1% | +9.8% | 15 | 40% | 0.98 | 3.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.7% | +8.4% | 11 | 45% | 2.30 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 10 | 50% | 2.30 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 11 | 55% | 4.25 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 10 | 40% | 0.81 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 10 | 40% | 1.20 | 0.2% | 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 | 3 | 0% | −$18,566.60 |
| Sideways market | 8 | 63% | $45,755.10 |
| Falling market | 3 | 33% | $1,427.03 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
34.5%
The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 16.5% to 34.5%; the tick is what actually happened, 34.1%. Order luck alone moves it this much.
All 14 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 12 Apr 2024 70,006.20 | 1 May 2024 60,672.00 | 19 | −$9,334.21 |
| short | 1 May 2024 60,672.00 | 18 May 2024 67,024.00 | 17 | −$6,351.99 |
| long | 18 May 2024 67,024.00 | 22 Jun 2024 64,143.60 | 35 | −$2,880.44 |
| short | 22 Jun 2024 64,143.60 | 20 Jul 2024 66,660.00 | 28 | −$2,516.45 |
| long | 20 Jul 2024 66,660.00 | 19 Aug 2024 58,427.30 | 30 | −$8,232.66 |
| short | 19 Aug 2024 58,427.30 | 21 Sep 2024 63,201.10 | 33 | −$4,773.70 |
| long | 21 Sep 2024 63,201.10 | 9 Feb 2025 96,444.80 | 141 | $33,243.70 |
| short | 9 Feb 2025 96,444.80 | 23 Apr 2025 93,443.00 | 73 | $3,001.76 |
| long | 23 Apr 2025 93,443.00 | 22 Oct 2025 108,298.00 | 182 | $14,854.70 |
| short | 22 Oct 2025 108,298.00 | 15 Jan 2026 96,951.80 | 85 | $11,345.90 |
| long | 15 Jan 2026 96,951.80 | 26 Jan 2026 86,670.40 | 11 | −$10,281.40 |
| short | 26 Jan 2026 86,670.40 | 18 Apr 2026 77,072.00 | 82 | $9,598.35 |
| long | 18 Apr 2026 77,072.00 | 1 Jun 2026 73,674.40 | 44 | −$3,397.62 |
| short | 1 Jun 2026 73,674.40 | 20 Aug 2026 69,334.80 | 80 | $4,339.61 |
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 with MACD- CMF- TSI this page | — | v4 strategy | +28.6% | 14 | 38.7% |
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.8% |
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 13 ms | Yes 1,000 bars in 59 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. PineTS runs Pine Script v5 and v6 only.
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/// © exlux99//@version=4strategy("Ichimoku with MACD/ CMF/ TSI", overlay=true, margin_long=0, margin_short=0)//Inputsts_bars = input(10, minval=1, title="Tenkan-Sen Bars")ks_bars = input(30, minval=1, title="Kijun-Sen Bars")ssb_bars = input(52, minval=1, title="Senkou-Span B Bars")cs_offset = input(26, minval=1, title="Chikou-Span Offset")ss_offset = input(26, minval=1, title="Senkou-Span Offset")long_entry = input(true, title="Long Entry")short_entry = input(true, title="Short Entry")middle(len) => avg(lowest(len), highest(len))// Ichimoku Componentstenkan = middle(ts_bars)kijun = middle(ks_bars)senkouA = avg(tenkan, kijun)senkouB = middle(ssb_bars)ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1])ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1])// Entry/Exit Signalsfast_length = input(title="Fast Length", type=input.integer, defval=17)slow_length = input(title="Slow Length", type=input.integer, defval=28)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 5)sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=true)// Calculatingfast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signaltk_cross_bull = tenkan > kijuntk_cross_bear = tenkan < kijuncs_cross_bull = mom(close, cs_offset-1) > 0cs_cross_bear = mom(close, cs_offset-1) < 0price_above_kumo = close > ss_highprice_below_kumo = close < ss_low//CMFlengthA = input(8, minval=1, title="CMF Length")ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volumemf = sum(ad, lengthA) / sum(volume, lengthA)//TSIlong = input(title="Long Length", type=input.integer, defval=8)short = input(title="Short Length", type=input.integer, defval=8)price = closedouble_smooth(src, long, short) => fist_smooth = ema(src, long) ema(fist_smooth, short)pc = change(price)double_smoothed_pc = double_smooth(pc, long, short)double_smoothed_abs_pc = double_smooth(abs(pc), long, short)tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)bullish = tk_cross_bull and cs_cross_bull and price_above_kumo and hist > 0 and mf > 0.1 and tsi_value > 0bearish = tk_cross_bear and cs_cross_bear and price_below_kumo and hist < 0 and mf < -0.1 and tsi_value < 0strategy.entry("Long", strategy.long, when=bullish and long_entry)strategy.entry("Short", strategy.short, when=bearish and short_entry)strategy.close("Long", when=bearish and not short_entry)strategy.close("Short", when=bullish and not long_entry)