Pine Script v4 · Strategy
Fibonacci + RSI - Strategy
A Pine Script v4 strategy built on VWMA (hlc3, 200), Stdev (hlc3, 200) and RSI (close, 14). It has 4 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 commits 100% of equity and pays no commission. 8 settings; defaults include Stop Loss (%) 2, [RSI] Length 14 and [RSI] Over Sold % 30.
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 Fibonacci + RSI - 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 Fibonacci + RSI - Strategy do on BTCUSDT 1D with default settings?
- +3.36%
- From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Fibonacci + RSI - Strategy 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 Fibonacci + RSI - Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 59, 60.
- Does Fibonacci + RSI - Strategy run in Zeal Terminal?
- Yes
- It compiles in 15 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- [Fibonacci Level] Basis
- [Fibonacci Level] Short Target
- [Fibonacci Level] Top
- [Fibonacci Level] Long Target
- [Fibonacci Level] Bottom
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3.36%
- $336.46
- Buy and hold
- +102.5%
- same period
- Closed trades
- 2
- 1 won · 1 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 17.24
- gross profit ÷ gross loss
- Max drawdown
- 19.16%
- −$1,916.25
One run with the author's default settings, $10,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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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, 59, 60. The upgraded version below moves each call inside an if block.
-
Note
Uses long =, which v5 renamed line 56
long = on line 56, 57. v5 writes it as direction = strategy.long or strategy.short.
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 vwma → ta.vwma, stdev → ta.stdev, rsi → ta.rsi, valuewhen → ta.valuewhen, crossover → ta.crossover, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 56, 57, 59, 60). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: //@version=4 → //@version=5
- Line 22: vwma → ta.vwma
- Line 23: stdev → ta.stdev
- Line 29: rsi → ta.rsi
- Line 35: valuewhen → ta.valuewhen
- Line 37: valuewhen → ta.valuewhen
4 more edits
- Line 42: crossover → ta.crossover
- Line 43: crossunder → ta.crossunder
- Line 56: long = true → direction = strategy.long
- Line 57: long = false → direction = strategy.short
⋯// If you have any modifications please tell me to update it-//@version=4+//@version=5strategy(title="Fibonacci + RSI - Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD)⋯// Calculate Fibonacci-basis = vwma(src, length)+basis = ta.vwma(src, length)-dev = mult * stdev(src, length)+dev = mult * ta.stdev(src, length)fu764= basis + (0.001*level*dev)⋯// Calculate RSI-vrsi = rsi(close, len)+vrsi = ta.rsi(close, len)// Calculate the Targets⋯bought = strategy.position_size[0] > strategy.position_size[1]-exit_long = valuewhen(bought, targetUp, 0)+exit_long = ta.valuewhen(bought, targetUp, 0)sold = strategy.position_size[0] < strategy.position_size[1]-exit_short = valuewhen(sold, targetDown, 0)+exit_short = ta.valuewhen(sold, targetDown, 0)// Calculate Stop Losses⋯// Conditions to Open Trades-openLong = low < fd1 and crossover(vrsi[1], overSold)+openLong = low < fd1 and ta.crossover(vrsi[1], overSold)-openShort = high > fu1 and crossunder(vrsi[1], overBought)+openShort = high > fu1 and ta.crossunder(vrsi[1], overBought)// Conditions to Close Trades⋯ // Entry Orders- strategy.entry(id="Long", long=true, when=openLong and high < targetUp, limit=close)+ strategy.entry(id="Long", direction = strategy.long, when=openLong and high < targetUp, limit=close)- strategy.entry(id="Short", long=false, when=openShort and low > targetDown, limit=close)+ strategy.entry(id="Short", direction = strategy.short, when=openShort and low > targetDown, limit=close) // Exit Orders⋯Same 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 11: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.int()
- Line 17: input() → input.int()
- Line 18: input() → input.source()
6 more edits
- Line 19: input() → input.float()
- Line 20: input() → input.int()
- Line 56: when = openLong and high < targetUp → if block
- Line 57: when = openShort and low > targetDown → if block
- Line 59: when = closeLong and strategy.position_size > 0 → if block
- Line 60: when = closeShort and strategy.position_size < 0 → if block
⋯ // Stop Loss %-loss_percent = input(title="Stop Loss (%)", minval=0.0, step=0.1, defval=2) * 0.001+loss_percent = input.int(title="Stop Loss (%)", minval=0.0, step=0.1, defval=2) * 0.001 // RSI Inputs-len = input(title="[RSI] Length", minval=0, step=1, defval=14)+len = input.int(title="[RSI] Length", minval=0, step=1, defval=14)-overSold = input(title="[RSI] Over Sold %", defval=30)+overSold = input.int(title="[RSI] Over Sold %", defval=30)-overBought = input(title="[RSI] Over Bought %", defval=70)+overBought = input.int(title="[RSI] Over Bought %", defval=70) // Fibonacci Levels-length = input(title="[Fibonacci] Length", defval=200, minval=1)+length = input.int(title="[Fibonacci] Length", defval=200, minval=1)-src = input(hlc3, title="[Fibonacci] Source")+src = input.source(hlc3, title="[Fibonacci] Source")-mult = input(title="[Fibonacci] Multiplier", defval=3.0, minval=0.001, maxval=50)+mult = input.float(title="[Fibonacci] Multiplier", defval=3.0, minval=0.001, maxval=50)-level = input(title="[Fibonacci] Level", defval=764)+level = input.int(title="[Fibonacci] Level", defval=764)// Calculate Fibonacci⋯ // Entry Orders- strategy.entry(id="Long", direction = strategy.long, when=openLong and high < targetUp, limit=close)+ if openLong and high < targetUp+ strategy.entry(id="Long", direction = strategy.long, limit=close)- strategy.entry(id="Short", direction = strategy.short, when=openShort and low > targetDown, limit=close)+ if openShort and low > targetDown+ strategy.entry(id="Short", direction = strategy.short, limit=close) // Exit Orders- strategy.exit(id="Long", when=closeLong and strategy.position_size > 0, limit=exit_long, stop=stop_long)+ if closeLong and strategy.position_size > 0+ strategy.exit(id="Long", limit=exit_long, stop=stop_long)- strategy.exit(id="Short", when=closeShort and strategy.position_size < 0, limit=exit_short, stop=stop_short)+ if closeShort and strategy.position_size < 0+ strategy.exit(id="Short", limit=exit_short, stop=stop_short)Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L50:C51: the argument 'title' is specified more than once. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// If you have any modifications please tell me to update it-//@version=5+//@version=6strategy(title="Fibonacci + RSI - Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD)⋯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 |
|---|---|---|---|
| Stop Loss (%) | 2 | int · min 0.0 · step 0.1 | stop_long stop_short |
| [RSI] Length | 14 | int · min 0 · step 1 | vrsi |
| [RSI] Over Sold % | 30 | int | openLong |
| [RSI] Over Bought % | 70 | int | openShort |
| [Fibonacci] Length | 200 | int · min 1 | basis dev |
| [Fibonacci] Source | hlc3 | source | basis dev |
| [Fibonacci] Multiplier | 3.0 | float · min 0.001 · max 50 | dev |
| [Fibonacci] Level | 764 | int | fu764 fd764 |
What it calculates
- VWMA (
vwma,ta.vwmain v5)[Fibonacci] Source (hlc3), [Fibonacci] Length (200)basis · line 22 - Stdev (
stdev,ta.stdevin v5)[Fibonacci] Source (hlc3), [Fibonacci] Length (200)dev · line 23 - RSI (
rsi,ta.rsiin v5)close, [RSI] Length (14)vrsi · line 29 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, targetUp, 0exit_long · line 35 - Valuewhen (
valuewhen,ta.valuewhenin v5)sold, targetDown, 0exit_short · line 37
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 | openLong and high < targetUp | On | 56 |
| Open Short short | openShort and low > targetDown | On | 57 |
| Exit Long stop and limit | closeLong and strategy.position_size > 0 | On | 59 |
| Exit Short stop and limit | closeShort and strategy.position_size < 0 | 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.
- 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 | +3.4% | +102.5% | 2 | 50% | 17.24 | 19.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.9% | +5.5% | 1 | 100% | — | 0.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.6% | +8.4% | 1 | 100% | — | 2.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +9.9% | +16.7% | 1 | 100% | — | 22.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +8.3% | +148.3% | 3 | 67% | 25.78 | 66.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 1 | 0% | 0.00 | 0.5% | 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 | 1 | 100% | $357.18 |
| Sideways market | 0 | — | $0.00 |
| Falling market | 1 | 0% | −$20.71 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.2%
The 95th percentile of the worst drawdown when the same 2 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.2% to 0.2%; the tick is what actually happened, 0.2%. Order luck alone moves it this much.
All 2 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 27 Nov 2024 91,965.20 | 26 Feb 2025 88,680.40 | 91 | $357.18 |
| long | 20 Nov 2025 91,555.00 | 4 Dec 2025 91,371.90 | 14 | −$20.71 |
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 |
|---|---|---|---|---|---|
| Fibonacci + RSI - Strategy this page | — | v4 strategy | +3.4% | 2 | 19.2% |
| Reinforced RSI - The Quant Science by thequantscience | rsi valuewhen | v5 strategy | −3.9% | 7 | 3.9% |
| Volume and Moving average,will this model working in real-trade- by Ayden_C | rsi stdev valuewhen | v4 strategy | −157,995.0% | 10 | 4,752.1% |
| RSI+PA+DCA Strategy by A3Sh | rsi valuewhen | v4 strategy | +22.3% | 46 | 5.1% |
| Bollinger band & Volume based strategy V2 by Ayden_C | rsi stdev valuewhen | v4 strategy | −0.1% | 5 | 0.2% |
| Bottom catch strategy by footlz | stdev rsi | v4 strategy | +3.9% | 3 | 7.1% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | With a workaround 1,000 bars in 43 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 56, 57) so the engine trades the way the script says.
“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/// © MohamedYAbdelaziz// Intraday Trading// Best used for Short Timeframes [1-30 Minutes]// If you have any modifications please tell me to update it//@version=4strategy(title="Fibonacci + RSI - Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD)// InputstimeFilter = year >= 2000 // Stop Loss %loss_percent = input(title="Stop Loss (%)", minval=0.0, step=0.1, defval=2) * 0.001 // RSI Inputslen = input(title="[RSI] Length", minval=0, step=1, defval=14)overSold = input(title="[RSI] Over Sold %", defval=30)overBought = input(title="[RSI] Over Bought %", defval=70) // Fibonacci Levelslength = input(title="[Fibonacci] Length", defval=200, minval=1)src = input(hlc3, title="[Fibonacci] Source")mult = input(title="[Fibonacci] Multiplier", defval=3.0, minval=0.001, maxval=50)level = input(title="[Fibonacci] Level", defval=764)// Calculate Fibonaccibasis = vwma(src, length)dev = mult * stdev(src, length)fu764= basis + (0.001*level*dev)fu1= basis + (1*dev)fd764= basis - (0.001*level*dev)fd1= basis - (1*dev)// Calculate RSIvrsi = rsi(close, len)// Calculate the TargetstargetUp = fd764targetDown = fu764 // Actual Targetsbought = strategy.position_size[0] > strategy.position_size[1]exit_long = valuewhen(bought, targetUp, 0)sold = strategy.position_size[0] < strategy.position_size[1]exit_short = valuewhen(sold, targetDown, 0)// Calculate Stop Lossesstop_long = strategy.position_avg_price * (1 - loss_percent)stop_short = strategy.position_avg_price * (1 + loss_percent)// Conditions to Open TradesopenLong = low < fd1 and crossover(vrsi[1], overSold)openShort = high > fu1 and crossunder(vrsi[1], overBought)// Conditions to Close TradescloseLong = high > exit_longcloseShort = low < exit_short // Plotsplot(basis, color=color.blue, linewidth=2, title="[Fibonacci Level] Basis")plot(fu764, color=color.white, linewidth=1, title="[Fibonacci Level] Short Target")plot(fu1, color=color.red, linewidth=2, title="1", title="[Fibonacci Level] Top")plot(fd764, color=color.white, linewidth=1, title="[Fibonacci Level] Long Target")plot(fd1, color=color.green, linewidth=2, title="1", title="[Fibonacci Level] Bottom")// Strategy Ordersif timeFilter // Entry Orders strategy.entry(id="Long", long=true, when=openLong and high < targetUp, limit=close) strategy.entry(id="Short", long=false, when=openShort and low > targetDown, limit=close) // Exit Orders strategy.exit(id="Long", when=closeLong and strategy.position_size > 0, limit=exit_long, stop=stop_long) strategy.exit(id="Short", when=closeShort and strategy.position_size < 0, limit=exit_short, stop=stop_short)