Pine Script v5 · Strategy
Rainbow Oscillator [Strategy]
A Pine Script v5 strategy built on CCI or RSI or Stoch (close, 16), Crossunder (sampledMagicSlow, sampledMagicFast) and Crossover (sampledMagicSlow, sampledMagicFast). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 16 settings; defaults include RSI Weight 0.33, CCI Weight 0.33 and Stoch Weight 0.33.
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 Rainbow Oscillator [Strategy] repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Rainbow Oscillator [Strategy] do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. On ETHUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does Rainbow Oscillator [Strategy] 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: 0 before, 27 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Rainbow Oscillator [Strategy] use a stop loss?
- Yes
- strategy.exit sets a stop on line 102, 103.
- Does Rainbow Oscillator [Strategy] run in Zeal Terminal?
- Yes
- It compiles in 73 ms and runs 1,000 bars in 159 ms, in the browser.
BTCUSDT · 1D · default settings
- fast
- slow
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $2,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
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 98, 99, 100, 101. 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 |
|---|---|---|---|
| Use trend filter | true | bool | buySignal sellSignal |
| RSI Weight | 0.33 | float | magicFast magicSlow |
| CCI Weight | 0.33 | float | magicFast magicSlow |
| Stoch Weight | 0.33 | float | magicFast magicSlow |
| Ocillograph Fast Period | 16 | int | magicFast |
| Ocillograph Slow Period | 22 | int | magicSlow |
| Oscillograph Samples Period | 8 | int | sampledMagicFast sampledMagicSlow |
| Oscillograph Samples Count | 2 | int | sampledMagicFast sampledMagicSlow |
| Oscillograph Samples Type | RMA | string · options ["EMA", "SMA", "RMA", "WMA"] | sampledMagicFast sampledMagicSlow |
| Level Period | 26 | int | level1up level2up level3up level4up level1low level2low level3low level4low |
| Level Offset | 0 | int | level1up level2up level3up level4up level1low level2low level3low level4low |
| Level Redunant | 0.5 | float | lastUpperValue lastLowerValue |
| Level Smooth Samples | 2 | int | level1up level2up level3up level4up level1low level2low level3low level4low |
| Level MA type | RMA | string · options ["EMA", "SMA", "RMA", "WMA"] | level1up level2up level3up level4up level1low level2low level3low level4low |
| % Take profit | 5 | float · step 0.1 | long_take_level short_take_level |
| % Stop Loss | 2 | float · step 0.1 | long_stop_level short_stop_level |
What it calculates
- CCI / RSI / Stochclose, Ocillograph Fast Period (16)
magicFast · line 38 - CCI / RSI / Stochclose, Ocillograph Slow Period (22)
magicSlow · line 39 - CrossundersampledMagicSlow, sampledMagicFast
buySignal · line 87 - CrossoversampledMagicSlow, sampledMagicFast
sellSignal · line 88
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 |
|---|---|---|---|
| Close Long | sellSignal | On | 98 |
| Close Short | buySignal | On | 99 |
| Open Long long | buySignal | On | 100 |
| Open Short short | sellSignal | On | 101 |
| Exit Take Profit/ Stop Loss stop and limit | every bar | On | 102 |
| Exit Take Profit/ Stop Loss stop and limit | every bar | On | 103 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −7.7% | +8.4% | 5 | 0% | 0.00 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −2.0% | +16.7% | 8 | 25% | 0.26 | 2.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.2% | +21.5% | 15 | 27% | 0.77 | 0.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.5% | +148.3% | 16 | 25% | 0.79 | 5.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.4% | +17.1% | 12 | 42% | 0.89 | 2.3% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Rainbow Oscillator [Strategy] this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| CCI Level Zone by Naruephat | cci rsi stoch | v5 strategy | No trades on this market | ||
| Suchit RSI CCI by SuchitRaju | cci rsi | v4 strategy | +11.4% | 68 | 54.7% |
| 3RSI 3CCI BB 5orders DCA strategy+ by rrolik66 | rsi cci | v5 strategy | No trades on this market | ||
| Bitcoin Scalping Strategy (Sampled with- PMARP+MADRID MA RIBBON) by CheatCode1 | rsi stoch | v5 strategy | −3.0% | 72 | 45.4% |
| Momentum Explosion 2CCI RSI by capam | cci rsi | v4 strategy | +24.1% | 6 | 42.3% |
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.
- 4 strategy calls use the when = argument (line 98, 99, 100, 101). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 5 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 98: when = sellSignal → if block
- Line 99: when = buySignal → if block
- Line 100: when = buySignal → if block
- Line 101: when = sellSignal → if block
⋯short_stop_level = strategy.position_avg_price * (1 + stopLoss)-strategy.close(id="Long", when=sellSignal, comment = "Exit")+if sellSignal+ strategy.close(id="Long", comment = "Exit")-strategy.close(id="Short", when=buySignal, comment = "Exit")+if buySignal+ strategy.close(id="Short", comment = "Exit")-strategy.entry("Long", strategy.long, when=buySignal)+if buySignal+ strategy.entry("Long", strategy.long)-strategy.entry("Short", strategy.short, when=sellSignal)+if sellSignal+ strategy.entry("Short", strategy.short)strategy.exit("Take Profit/ Stop Loss","Long", stop=long_stop_level, limit=long_take_level)⋯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: 0 before, 27 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.
⋯// © businessduck-//@version=5+//@version=6strategy("Rainbow Oscillator [Strategy]", overlay=false, margin_long=100, margin_short=100, initial_capital = 2000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 73 ms | With a workaround 1,000 bars in 159 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © businessduck//@version=5strategy("Rainbow Oscillator [Strategy]", overlay=false, margin_long=100, margin_short=100, initial_capital = 2000)bool trendFilter = input.bool(true, 'Use trend filter')float w1 = input.float(0.33, 'RSI Weight', 0, 1, 0.01)float w2 = input.float(0.33, 'CCI Weight', 0, 1, 0.01)float w3 = input.float(0.33, 'Stoch Weight', 0, 1, 0.01)int fastPeriod = input.int(16, 'Ocillograph Fast Period', 4, 60, 1)int slowPeriod = input.int(22, 'Ocillograph Slow Period', 4, 60, 1)int oscillographSamplePeriod = input.int(8, 'Oscillograph Samples Period', 1, 30, 1)int oscillographSamplesCount = input.int(2, 'Oscillograph Samples Count', 0, 4, 1)string oscillographMAType = input.string("RMA", "Oscillograph Samples Type", options = ["EMA", "SMA", "RMA", "WMA"])int levelPeriod = input.int(26, 'Level Period', 2, 100)int levelOffset = input.int(0, 'Level Offset', 0, 200, 10)float redunant = input.float(0.5, 'Level Redunant', 0, 1, 0.01)int levelSampleCount = input.int(2, 'Level Smooth Samples', 0, 4, 1)string levelType = input.string("RMA", "Level MA type", options = ["EMA", "SMA", "RMA", "WMA"])perc(current, prev) => ((current - prev) / prev) * 100smooth(value, type, period) => float ma = switch type "EMA" => ta.ema(value, period) "SMA" => ta.sma(value, period) "RMA" => ta.rma(value, period) "WMA" => ta.wma(value, period) => runtime.error("No matching MA type found.") float(na)getSample(value, samples, type, period) => float ma = switch samples 0 => value 1 => smooth(value, type, period) 2 => smooth(smooth(value, type, period), type, period) 3 => smooth(smooth(smooth(value, type, period), type, period), type, period) 4 => smooth(smooth(smooth(smooth(value, type, period), type, period), type, period), type, period)float takeProfit = input.float(5, "% Take profit", 0.8, 100, step = 0.1) / 100float stopLoss = input.float(2, "% Stop Loss", 0.8, 100, step = 0.1) / 100float magicFast = w2 * ta.cci(close, fastPeriod) + w1 * (ta.rsi(close, fastPeriod) - 50) + w3 * (ta.stoch(close, high, low, fastPeriod) - 50)float magicSlow = w2 * ta.cci(close, slowPeriod) + w1 * (ta.rsi(close, slowPeriod) - 50) + w3 * (ta.stoch(close, high, low, slowPeriod) - 50)float sampledMagicFast = getSample(magicFast, oscillographSamplesCount, oscillographMAType, oscillographSamplePeriod)float sampledMagicSlow = getSample(magicSlow, oscillographSamplesCount, oscillographMAType, oscillographSamplePeriod)float lastUpperValue = 0float lastLowerValue = 0if (magicFast > 0) lastUpperValue := math.max(magicFast, magicFast[1])else lastUpperValue := math.max(0, lastUpperValue[1]) * redunant if (magicFast <= 0) lastLowerValue := math.min(magicFast, magicFast[1])else lastLowerValue := math.min(0, lastLowerValue[1]) * redunantfloat level1up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) / 4, levelSampleCount, levelType, levelPeriod) + levelOffsetfloat level2up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) / 2, levelSampleCount, levelType, levelPeriod) + levelOffsetfloat level3up = getSample( magicFast >= 0 ? magicFast : lastUpperValue, levelSampleCount, levelType, levelPeriod) + levelOffsetfloat level4up = getSample( (magicFast >= 0 ? magicFast : lastUpperValue) * 2, levelSampleCount, levelType, levelPeriod) + levelOffsetfloat level1low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) / 4, levelSampleCount, levelType, levelPeriod) - levelOffsetfloat level2low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) / 2, levelSampleCount, levelType, levelPeriod) - levelOffsetfloat level3low = getSample( magicFast <= 0 ? magicFast : lastLowerValue, levelSampleCount, levelType, levelPeriod) - levelOffsetfloat level4low = getSample( (magicFast <= 0 ? magicFast : lastLowerValue) * 2, levelSampleCount, levelType, levelPeriod) - levelOffsetvar transparent = color.new(color.white, 100)var overbough4Color = color.new(color.red, 75)var overbough3Color = color.new(color.orange, 75)var overbough2Color = color.new(color.yellow, 75)var oversold4Color = color.new(color.teal, 75)var oversold3Color = color.new(color.blue, 75)var oversold2Color = color.new(color.aqua, 85)upperPlotId1 = plot(level1up, 'Upper1', transparent)upperPlotId2 = plot(level2up, 'Upper2', transparent)upperPlotId3 = plot(level3up, 'Upper3', transparent)upperPlotId4 = plot(level4up, 'Upper4', transparent)fastColor = color.new(color.teal, 60)slowColor = color.new(color.red, 60)fastPlotId = plot(sampledMagicFast, 'fast', color = fastColor)slowPlotId = plot(sampledMagicSlow, 'slow', color = slowColor)lowerPlotId1 = plot(level1low, 'Lower1', transparent)lowerPlotId2 = plot(level2low, 'Lower2', transparent)lowerPlotId3 = plot(level3low, 'Lower3', transparent)lowerPlotId4 = plot(level4low, 'Lower4', transparent)fill(upperPlotId4, upperPlotId3, overbough4Color)fill(upperPlotId3, upperPlotId2, overbough3Color)fill(upperPlotId2, upperPlotId1, overbough2Color)fill(lowerPlotId4, lowerPlotId3, oversold4Color)fill(lowerPlotId3, lowerPlotId2, oversold3Color)fill(lowerPlotId2, lowerPlotId1, oversold2Color)upTrend = sampledMagicFast > sampledMagicFast[1]buySignal = ((upTrend or not trendFilter) and ta.crossunder(sampledMagicSlow, sampledMagicFast)) ? sampledMagicSlow : nasellSignal = ((not upTrend or not trendFilter) and ta.crossover(sampledMagicSlow, sampledMagicFast)) ? sampledMagicSlow : nadiff = sampledMagicSlow - sampledMagicFastfill(fastPlotId, slowPlotId, upTrend ? fastColor : slowColor)plot(buySignal, color = color.aqua, style = plot.style_circles, linewidth = 4)plot(sellSignal, color = color.red, style = plot.style_circles, linewidth = 4)// longCondition = upTrend != upTrend[1] and upTrendlong_take_level = strategy.position_avg_price * (1 + takeProfit)long_stop_level = strategy.position_avg_price * (1 - stopLoss)short_take_level = strategy.position_avg_price * (1 - takeProfit)short_stop_level = strategy.position_avg_price * (1 + stopLoss)strategy.close(id="Long", when=sellSignal, comment = "Exit")strategy.close(id="Short", when=buySignal, comment = "Exit")strategy.entry("Long", strategy.long, when=buySignal)strategy.entry("Short", strategy.short, when=sellSignal)strategy.exit("Take Profit/ Stop Loss","Long", stop=long_stop_level, limit=long_take_level)strategy.exit("Take Profit/ Stop Loss","Short", stop=short_stop_level, limit=short_take_level)// plot(long_stop_level, color=color.red, overlay=true)// plot(long_take_level, color=color.green)