Pine Script v4 · Strategy
RSI Divergence X Ichimoku Cloud X 200EMA
A Pine Script v4 strategy built on EMA (close, 200), RSI (close, 14) and Pivotlow (osc, 5). 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. 12 settings; defaults include Len 14, Src close and Lb R 5.
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 RSI Divergence X Ichimoku Cloud X 200EMA repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did RSI Divergence X Ichimoku Cloud X 200EMA do on BTCUSDT 1D with default settings?
- −196,793.00%
- From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can RSI Divergence X Ichimoku Cloud X 200EMA 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 RSI Divergence X Ichimoku Cloud X 200EMA use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does RSI Divergence X Ichimoku Cloud X 200EMA run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 57 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- Pivotlow
- Pivothigh
- Crossover
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −196,793.00%
- −$196,793,000.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 7
- 4 won · 3 lost
- Profitable
- 57.1%
- of closed trades
- Profit factor
- 0.69
- gross profit ÷ gross loss
- Max drawdown
- 1,854.60%
- −$583,127,000.00
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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
1 setting does nothing
“Displacement” is declared but never read.
-
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
12 settings have no label
In the settings dialog len (line 6), src (line 7), lbR (line 8), lbL (line 9), takeProfitLevellong (line 10), takeProfitLevelshort (line 11), rangeUpper (line 12), rangeLower (line 13), conversionPeriods (line 17), basePeriods (line 18), laggingSpan2Periods (line 19), displacement (line 20) show an empty name. The labels on this page come from the variable names.
-
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 56, 57, 58, 59. 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 ema → ta.ema, avg → math.avg, lowest → ta.lowest, highest → ta.highest, max → math.max, min → math.min, rsi → ta.rsi, barssince → ta.barssince, pivotlow → ta.pivotlow, pivothigh → ta.pivothigh, valuewhen → ta.valuewhen, crossover → ta.crossover.
- 4 strategy calls use the when = argument (line 56, 57, 58, 59). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 15: ema → ta.ema
- Line 21: avg → math.avg
- Line 21: lowest → ta.lowest
- Line 21: highest → ta.highest
- Line 24: avg → math.avg
16 more edits
- Line 26: max → math.max
- Line 27: min → math.min
- Line 29: rsi → ta.rsi
- Line 31: barssince → ta.barssince
- Line 33: pivotlow → ta.pivotlow
- Line 34: pivothigh → ta.pivothigh
- Line 36: valuewhen → ta.valuewhen
- Line 37: valuewhen → ta.valuewhen
- Line 40: valuewhen → ta.valuewhen
- Line 41: valuewhen → ta.valuewhen
- Line 44: valuewhen → ta.valuewhen
- Line 45: valuewhen → ta.valuewhen
- Line 48: valuewhen → ta.valuewhen
- Line 49: valuewhen → ta.valuewhen
- Line 53: crossover → ta.crossover
- Line 55: crossover → ta.crossover
⋯// © tradethrills-//@version=4+//@version=5strategy("RSI Divergence X Ichimoku Cloud X 200EMA", overlay=true)⋯//200 EMA-ema200 = ema(close, 200)+ema200 = ta.ema(close, 200)//Ichimoku Cloud Indicator⋯displacement = input(26, minval=1)-donchian(len) => avg(lowest(len), highest(len))+donchian(len) => math.avg(ta.lowest(len), ta.highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)-leadLine1 = avg(conversionLine, baseLine)+leadLine1 = math.avg(conversionLine, baseLine)leadLine2 = donchian(laggingSpan2Periods)-abovecloud = max(leadLine1, leadLine2)+abovecloud = math.max(leadLine1, leadLine2)-belowcloud = min(leadLine1, leadLine2)+belowcloud = math.min(leadLine1, leadLine2)//RSI Divergence Strategy-osc = rsi(src, len)+osc = ta.rsi(src, len)_inrange(cond) =>- bars = barssince(cond == true)+ bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper-pricelowfound = na(pivotlow(osc, lbL, lbR)) ? false : true+pricelowfound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true-pricehighfound = na(pivothigh(osc, lbL, lbR)) ? false : true+pricehighfound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true//Regular Bullish-osc_higherlow = osc[lbR] > valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])+osc_higherlow = osc[lbR] > ta.valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])-price_lowerlow = low[lbR] < valuewhen(pricelowfound, low[lbR], 1)+price_lowerlow = low[lbR] < ta.valuewhen(pricelowfound, low[lbR], 1)bullCond = price_lowerlow and osc_higherlow and pricelowfound//Hidden Bullish-osc_lowerlow = osc[lbR] < valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])+osc_lowerlow = osc[lbR] < ta.valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])-price_higherlow = low[lbR] > valuewhen(pricelowfound, low[lbR], 1)+price_higherlow = low[lbR] > ta.valuewhen(pricelowfound, low[lbR], 1)hiddenbullCond = price_higherlow and osc_lowerlow and pricelowfound//Regular Bearish-osc_lowerhigh = osc[lbR] < valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])+osc_lowerhigh = osc[lbR] < ta.valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])-price_higherhigh = high[lbR] > valuewhen(pricehighfound, high[lbR], 1)+price_higherhigh = high[lbR] > ta.valuewhen(pricehighfound, high[lbR], 1)bearCond = price_higherhigh and osc_lowerhigh and pricehighfound//Hidden Bearish-osc_higherhigh = osc[lbR] > valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])+osc_higherhigh = osc[lbR] > ta.valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])-price_lowerhigh = high[lbR] < valuewhen(pricehighfound, high[lbR], 1)+price_lowerhigh = high[lbR] < ta.valuewhen(pricehighfound, high[lbR], 1)hiddenbearCond = price_lowerhigh and osc_higherhigh and pricehighfound⋯longCondition = (bullCond or hiddenbullCond) and (abovecloud > ema200)-closelongCondition = crossover(osc, takeProfitLevellong) +closelongCondition = ta.crossover(osc, takeProfitLevellong) shortCondition = (bearCond or hiddenbearCond) and (ema200 > belowcloud)-closeshortCondition = crossover(osc, takeProfitLevelshort)+closeshortCondition = ta.crossover(osc, takeProfitLevelshort)strategy.entry("Long", strategy.long, 10000.0, when=longCondition)⋯Same 7 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.source()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
10 more edits
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 56: when = longCondition → if block
- Line 57: when = closelongCondition → if block
- Line 58: when = shortCondition → if block
- Line 59: when = closeshortCondition → if block
⋯//RSI Indicator-len = input(defval=14, minval=1)+len = input.int(defval=14, minval=1)-src = input(defval=close)+src = input.source(defval=close)-lbR = input(defval=5)+lbR = input.int(defval=5)-lbL = input(defval=5)+lbL = input.int(defval=5)-takeProfitLevellong = input(minval = 70, defval = 75)+takeProfitLevellong = input.int(minval = 70, defval = 75)-takeProfitLevelshort = input(minval = 30, defval = 25)+takeProfitLevelshort = input.int(minval = 30, defval = 25)-rangeUpper = input(defval=60)+rangeUpper = input.int(defval=60)-rangeLower = input(defval=5)+rangeLower = input.int(defval=5)//200 EMA⋯//Ichimoku Cloud Indicator-conversionPeriods = input(9, minval=1)+conversionPeriods = input.int(9, minval=1)-basePeriods = input(26, minval=1)+basePeriods = input.int(26, minval=1)-laggingSpan2Periods = input(52, minval=1)+laggingSpan2Periods = input.int(52, minval=1)-displacement = input(26, minval=1)+displacement = input.int(26, minval=1)donchian(len) => math.avg(ta.lowest(len), ta.highest(len))⋯closeshortCondition = ta.crossover(osc, takeProfitLevelshort)-strategy.entry("Long", strategy.long, 10000.0, when=longCondition)+if longCondition+ strategy.entry("Long", strategy.long, 10000.0)-strategy.close("Long", when=closelongCondition)+if closelongCondition+ strategy.close("Long")-strategy.entry("Short", strategy.short, 10000.0, when=shortCondition)+if shortCondition+ strategy.entry("Short", strategy.short, 10000.0)-strategy.close("Short", when=closeshortCondition)+if closeshortCondition+ 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: 7 before, 0 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.
⋯// © tradethrills-//@version=5+//@version=6strategy("RSI Divergence X Ichimoku Cloud X 200EMA", overlay=true)⋯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 |
|---|---|---|---|
| Len (no label in the script) | 14 | int · min 1 | osc line 21 |
| Src (no label in the script) | close | source | osc |
| Lb R (no label in the script) | 5 | int | pricelowfound pricehighfound osc_higherlow price_lowerlow osc_lowerlow price_higherlow osc_lowerhigh price_higherhigh osc_higherhigh price_lowerhigh |
| Lb L (no label in the script) | 5 | int | pricelowfound pricehighfound |
| Take Profit Levellong (no label in the script) | 75 | int · min 70 | closelongCondition |
| Take Profit Levelshort (no label in the script) | 25 | int · min 30 | closeshortCondition |
| Range Upper (no label in the script) | 60 | int | line 32 |
| Range Lower (no label in the script) | 5 | int | line 32 |
| Conversion Periods (no label in the script) | 9 | int · min 1 | conversionLine |
| Base Periods (no label in the script) | 26 | int · min 1 | baseLine |
| Lagging Span2Periods (no label in the script) | 52 | int · min 1 | leadLine2 |
| Displacement (no label in the script) | 26 | int · min 1 | unused |
What it calculates
- EMA (
ema,ta.emain v5)close, 200ema200 · line 15 - RSI (
rsi,ta.rsiin v5)Src (close), Len (14)osc · line 29 - Pivotlow (
pivotlow,ta.pivotlowin v5)osc, Lb L (5), Lb R (5)pricelowfound · line 33 - Pivothigh (
pivothigh,ta.pivothighin v5)osc, Lb L (5), Lb R (5)pricehighfound · line 34 - Crossover (
crossover,ta.crossoverin v5)osc, Take Profit Levellong (75)closelongCondition · line 53 - Crossover (
crossover,ta.crossoverin v5)osc, Take Profit Levelshort (25)closeshortCondition · line 55
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 | longCondition(bullCond or hiddenbullCond) and (abovecloud > ema200) | On | 56 |
| Close Long | closelongCondition | On | 57 |
| Open Short short | shortCondition(bearCond or hiddenbearCond) and (ema200 > belowcloud) | On | 58 |
| Close Short | closeshortCondition | On | 59 |
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 | −196,793.0% | +102.5% | 7 | 57% | 0.69 | 1,854.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −170,420.0% | +5.5% | 6 | 50% | 0.10 | 221,260.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −62,689.8% | +9.8% | 8 | 38% | 0.18 | 71,900.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +4,395.2% | +8.4% | 5 | 80% | 3.73 | 1,894.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1,643.0% | +16.7% | 5 | 40% | 0.20 | 3,303.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +7.8% | +21.5% | 6 | 67% | 1.04 | 81.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −466.0% | +148.3% | 7 | 71% | 0.90 | 644.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +744.4% | +17.1% | 5 | 80% | 3.46 | 296.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 | 67% | $43,002,200.00 |
| Sideways market | 3 | 33% | −$358,752,000.00 |
| Falling market | 1 | 100% | $118,958,000.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
364,724.0%
The 95th percentile of the worst drawdown when the same 7 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 257.8% to 364,724.0%; the tick is what actually happened, 1,303.9%. Order luck alone moves it this much.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 10 Nov 2024 76,677.50 | 11 Nov 2024 80,370.00 | 1 | $36,925,500.00 |
| long | 2 Dec 2024 97,185.20 | 30 Mar 2025 82,648.50 | 118 | −$145,366,000.00 |
| short | 30 Mar 2025 82,648.50 | 5 Jun 2025 104,697.00 | 67 | −$220,483,000.00 |
| long | 5 Jun 2025 104,697.00 | 15 Jul 2025 119,841.00 | 40 | $151,443,000.00 |
| long | 8 Aug 2025 117,472.00 | 9 Dec 2025 90,634.40 | 123 | −$268,377,000.00 |
| short | 9 Dec 2025 90,634.40 | 3 Feb 2026 78,738.60 | 56 | $118,958,000.00 |
| short | 29 Apr 2026 76,342.80 | 8 Jun 2026 63,332.00 | 40 | $130,108,000.00 |
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 |
|---|---|---|---|---|---|
| RSI Divergence X Ichimoku Cloud X 200EMA this page | — | v4 strategy | −196,793.0% | 7 | 1,854.6% |
| RSI Centered Pivots by OztheWoz | rsi pivotlow pivothigh | v4 strategy | +98.0% | 4 | 160.2% |
| RSI5_50 with Divergence by mohanee | rsi pivotlow pivothigh | v4 strategy | +443.3% | 25 | 411.3% |
| TradePro's 2 EMA + Stoch RSI + ATR Strategy by PtGambler | ema rsi pivothigh pivotlow | v5 strategy | −2.7% | 18 | 22.0% |
| MACD 5 iN 1 [Pro-Tool] by HamidBox | ema rsi pivotlow pivothigh | v4 strategy | No trades on this market | ||
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | Yes 1,000 bars in 57 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/// © tradethrills//@version=4strategy("RSI Divergence X Ichimoku Cloud X 200EMA", overlay=true)//RSI Indicatorlen = input(defval=14, minval=1)src = input(defval=close)lbR = input(defval=5)lbL = input(defval=5)takeProfitLevellong = input(minval = 70, defval = 75)takeProfitLevelshort = input(minval = 30, defval = 25)rangeUpper = input(defval=60)rangeLower = input(defval=5)//200 EMAema200 = ema(close, 200)//Ichimoku Cloud IndicatorconversionPeriods = input(9, minval=1)basePeriods = input(26, minval=1)laggingSpan2Periods = input(52, minval=1)displacement = input(26, minval=1)donchian(len) => avg(lowest(len), highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)leadLine1 = avg(conversionLine, baseLine)leadLine2 = donchian(laggingSpan2Periods)abovecloud = max(leadLine1, leadLine2)belowcloud = min(leadLine1, leadLine2)//RSI Divergence Strategyosc = rsi(src, len)_inrange(cond) => bars = barssince(cond == true) rangeLower <= bars and bars <= rangeUpperpricelowfound = na(pivotlow(osc, lbL, lbR)) ? false : truepricehighfound = na(pivothigh(osc, lbL, lbR)) ? false : true//Regular Bullishosc_higherlow = osc[lbR] > valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])price_lowerlow = low[lbR] < valuewhen(pricelowfound, low[lbR], 1)bullCond = price_lowerlow and osc_higherlow and pricelowfound//Hidden Bullishosc_lowerlow = osc[lbR] < valuewhen(pricelowfound, osc[lbR], 1) and _inrange(pricelowfound[1])price_higherlow = low[lbR] > valuewhen(pricelowfound, low[lbR], 1)hiddenbullCond = price_higherlow and osc_lowerlow and pricelowfound//Regular Bearishosc_lowerhigh = osc[lbR] < valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])price_higherhigh = high[lbR] > valuewhen(pricehighfound, high[lbR], 1)bearCond = price_higherhigh and osc_lowerhigh and pricehighfound//Hidden Bearishosc_higherhigh = osc[lbR] > valuewhen(pricehighfound, osc[lbR], 1) and _inrange(pricehighfound[1])price_lowerhigh = high[lbR] < valuewhen(pricehighfound, high[lbR], 1)hiddenbearCond = price_lowerhigh and osc_higherhigh and pricehighfound//Entry and ExitlongCondition = (bullCond or hiddenbullCond) and (abovecloud > ema200)closelongCondition = crossover(osc, takeProfitLevellong) shortCondition = (bearCond or hiddenbearCond) and (ema200 > belowcloud)closeshortCondition = crossover(osc, takeProfitLevelshort)strategy.entry("Long", strategy.long, 10000.0, when=longCondition)strategy.close("Long", when=closelongCondition)strategy.entry("Short", strategy.short, 10000.0, when=shortCondition)strategy.close("Short", when=closeshortCondition)