Pine Script v5 · Strategy
DELAYED FIBO
A Pine Script v5 strategy built on EMA (close, 14) and SMA (TR, 14). It has 3 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 1000 in cash and pays 0.075 commission. 20 settings; defaults include From Day 1, From Month 1 and From Year 2020.
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 DELAYED FIBO repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did DELAYED FIBO do on BTCUSDT 1D with default settings?
- −7.77%
- From 26 Jan 2024 to 21 Oct 2026, over 18 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does DELAYED FIBO 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: 18 before, 1 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 DELAYED FIBO use a stop loss?
- Yes
- strategy.exit sets a stop on line 104.
- Does DELAYED FIBO run in Zeal Terminal?
- Yes
- It compiles in 32 ms and runs 1,000 bars in 89 ms, in the browser.
BTCUSDT · 1D · default settings
- FIBOTOP4
- FIBOTOP3
- FIBOTOP2
- FIBOTOP1
- FIBOBOT1
- FIBOBOT2
- FIBOBOT3
- FIBOBOT4
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −7.77%
- −$77.65
- Buy and hold
- +102.5%
- same period
- Closed trades
- 18
- 13 won · 5 lost
- Profitable
- 72.2%
- of closed trades
- Profit factor
- 0.64
- gross profit ÷ gross loss
- Max drawdown
- 16.32%
- −$173.88
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.
-
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 102, 103. 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 |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | start |
| From Month | 1 | int · min 1 · max 12 | start |
| From Year | 2020 | int | start |
| Thru Day | 1 | int · min 1 · max 31 | finish |
| Thru Month | 1 | int · min 1 · max 12 | finish |
| Thru Year | 2112 | int | finish |
| long distance level | 2 | int | lsumV |
| short distance level | 1 | int | lsumV ssumV |
| vrate level | 0.1 | float | vt |
| Fibonacci | |||
| EMAperiod | 14 | int · min 1 · max 500 | EMA |
| ATRperiod | 14 | int · min 1 · max 500 | ATR |
| Fibonacci Ratio 2 | 1.618 | float | R2 |
| Fibonacci Ratio 3 | 2.618 | float | R3 |
| Fibonacci Ratio 4 | 4.236 | float | R4 |
| Long | |||
| FiboLong | cross_FIBOBOT2(yellow) | string · options ["cross_FIBOBOT1(green)", "cross_FIBOBOT2(yellow)", "cross_FIBOBOT3(blue)", "cross_FIBOBOT4(aqua)", "Disable"] | line 72 line 74 line 76 line 79 line 81 |
| Long Code | |||
| Long Enter | Long Code | string | entry AL |
| Long Exit | Long Exit Code | string | close AL exit AL |
| ðŸ³Long | |||
| TakeProfit StopLoss Aktif Et | true | bool | line 96 |
| Stop loss | 1.9 | float · min 0.1 · step 0.1 | exit AL |
| Take profit | 0.7 | float · min 0.1 · step 0.1 | exit AL |
What it calculates
- EMAclose, EMAperiod (14)
EMA · line 42 - SMATR, ATRperiod (14)
ATR · line 45
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 AL long | longs and window() | On | 102 |
| Close AL | ta.cross(vt, FIBOTOP3) | On | 103 |
| Exit AL stop and limit | every bar | On | 104 |
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 | −7.8% | +102.5% | 18 | 72% | 0.64 | 16.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.2% | +5.5% | 23 | 74% | 0.90 | 9.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +16.6% | +9.8% | 23 | 65% | 1.62 | 13.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −3.0% | +8.4% | 28 | 64% | 0.87 | 15.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.5% | +16.7% | 23 | 65% | 1.09 | 24.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −2.5% | +21.5% | 26 | 65% | 0.86 | 13.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −10.1% | +148.3% | 12 | 58% | 0.51 | 25.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.9% | +17.1% | 22 | 77% | 1.28 | 7.0% | 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% | $10.41 |
| Sideways market | 9 | 67% | −$97.68 |
| Falling market | 8 | 75% | $9.62 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
17.1%
The 95th percentile of the worst drawdown when the same 18 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 9.4% to 17.1%; the tick is what actually happened, 14.5%. Order luck alone moves it this much.
All 18 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 1 May 2024 58,365.00 | 3 May 2024 59,060.60 | 2 | $10.41 |
| long | 24 Jun 2024 60,293.30 | 26 Jun 2024 61,806.00 | 2 | $23.57 |
| long | 26 Jun 2024 60,865.00 | 28 Jun 2024 61,706.50 | 2 | $12.31 |
| long | 4 Jul 2024 57,050.00 | 6 Jul 2024 57,449.40 | 2 | $5.49 |
| long | 7 Jul 2024 55,857.80 | 9 Jul 2024 56,714.60 | 2 | $13.83 |
| long | 4 Aug 2024 58,161.00 | 6 Aug 2024 54,018.80 | 2 | −$72.67 |
| long | 6 Sep 2024 53,963.00 | 8 Sep 2024 54,340.70 | 2 | $5.49 |
| long | 24 Feb 2025 91,552.90 | 26 Feb 2025 88,680.40 | 2 | −$32.85 |
| long | 25 Sep 2025 108,994.00 | 28 Sep 2025 109,757.00 | 3 | $5.49 |
| long | 4 Nov 2025 101,497.00 | 6 Nov 2025 103,885.00 | 2 | $22.01 |
| long | 14 Nov 2025 94,594.00 | 16 Nov 2025 95,596.20 | 2 | $9.09 |
| long | 17 Nov 2025 92,215.10 | 19 Nov 2025 92,960.80 | 2 | $6.58 |
| long | 20 Nov 2025 86,637.20 | 22 Nov 2025 84,991.10 | 2 | −$20.49 |
| long | 20 Jan 2026 88,427.70 | 22 Jan 2026 89,454.70 | 2 | $10.11 |
| long | 29 Jan 2026 84,650.20 | 31 Jan 2026 83,041.80 | 2 | −$20.49 |
| long | 1 Jun 2026 71,408.90 | 3 Jun 2026 66,760.80 | 2 | −$66.54 |
| long | 9 Jun 2026 61,730.00 | 11 Jun 2026 62,162.10 | 2 | $5.49 |
| long | 25 Jun 2026 59,794.00 | 27 Jun 2026 60,212.60 | 2 | $5.49 |
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 |
|---|---|---|---|---|---|
| DELAYED FIBO this page | — | v5 strategy | −7.8% | 18 | 16.3% |
| 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% |
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.
- 2 strategy calls use the when = argument (line 102, 103). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 6 settings use the untyped input() (line 46, 47, 48, 87, 88, 91). 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 18 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 46: input() → input.float()
- Line 47: input() → input.float()
- Line 48: input() → input.float()
- Line 87: input() → input.string()
- Line 88: input() → input.string()
- Line 91: input() → input.bool()
- Line 102: when = longs and window() → if block
- Line 103: when = ta.cross(vt, FIBOTOP3) → if block
⋯ATR = ta.sma(TR, ATRperiod)-F2 = input(defval=1.618, title='Fibonacci Ratio 2', group="Fibonacci")+F2 = input.float(defval=1.618, title='Fibonacci Ratio 2', group="Fibonacci")-F3 = input(defval=2.618, title='Fibonacci Ratio 3', group="Fibonacci")+F3 = input.float(defval=2.618, title='Fibonacci Ratio 3', group="Fibonacci")-F4 = input(defval=4.236, title='Fibonacci Ratio 4', group="Fibonacci")+F4 = input.float(defval=4.236, title='Fibonacci Ratio 4', group="Fibonacci")R1 = ATR⋯// === Bot Codes === { -enterlong = input("Long Code", title='Long Enter', group="Long Code")+enterlong = input.string("Long Code", title='Long Enter', group="Long Code")-exitlong = input("Long Exit Code", title='Long Exit', group="Long Code")+exitlong = input.string("Long Exit Code", title='Long Exit', group="Long Code")// }// === Extra === {-tpslacL= input(true, title="TakeProfit StopLoss Aktif Et", group="ðŸ³Long")+tpslacL= input.bool(true, title="TakeProfit StopLoss Aktif Et", group="ðŸ³Long")// }⋯////////////////////////////////////////////////////////////////////////////////////////////-strategy.entry("AL", strategy.long, when= longs and window(), alert_message=enterlong, comment="Long")+if longs and window()+ strategy.entry("AL", strategy.long, alert_message=enterlong, comment="Long")-strategy.close("AL", when= ta.cross(vt, FIBOTOP3), alert_message = exitlong, comment="Cross") +if ta.cross(vt, FIBOTOP3)+ strategy.close("AL", alert_message = exitlong, comment="Cross") strategy.exit("AL", profit = per(tpL), loss = per(stoplossL), trail_points=per(tpL+0.1) , trail_offset=trof, alert_message = exitlong, comment="TPorSL")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: 18 before, 1 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.
⋯// © drhakankilic-//@version=5+//@version=6strategy("FIBONACCI BANDS Long Strategy", shorttitle="FBANDS L Strategy", overlay=true, pyramiding=1, initial_capital = 1000, default_qty_type = strategy.cash, default_qty_value = 1000, ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 32 ms | Yes 1,000 bars in 89 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/// © drhakankilic//@version=5strategy("FIBONACCI BANDS Long Strategy", shorttitle="FBANDS L Strategy", overlay=true, pyramiding=1, initial_capital = 1000, default_qty_type = strategy.cash, default_qty_value = 1000, process_orders_on_close=true, commission_value=0.075, max_bars_back=500, max_lines_count=500, currency = 'USD')// === Date === { //Backtest datesfromDay = input.int(defval=1, title='From Day',minval=1,maxval=31)fromMonth = input.int(defval=1, title='From Month',minval=1,maxval=12)fromYear = input.int(defval=2020, title='From Year')thruDay = input.int(defval=1, title='Thru Day',minval=1,maxval=31)thruMonth = input.int(defval=1, title='Thru Month',minval=1,maxval=12)thruYear = input.int(defval=2112, title='Thru Year')showDate = true // input(defval=true, title="Show Date Range")start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start windowfinish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish windowwindow() => // create function "within window of time" time >= start and time <= finish ? true : false// }// === Line === { sumd(series, distance) => sumd = 0.0 for i = 0 to distance sumd := sumd + series[i] sumdldistance_level = input.int(title="long distance level", defval=2)sdistance_level = input.int(title="short distance level", defval=1) lsumV = sumd(volume,ldistance_level+sdistance_level)ssumV = sumd(volume,sdistance_level) lsumV:=lsumV-ssumVvrate = ssumV/lsumVvrate_level = input.float(title="vrate level", defval=0.1)vt = close*(vrate>vrate_level?1:0)if(vt==0) vt:=vt[1]// plot(vt, color=color.blue, title="MPT")// plot(close, color=color.red,title="PRICE")// }// === FIBONACCI BANDS === {EMAperiod = input.int(14, title='EMAperiod', minval=1, maxval=500, group="Fibonacci")ATRperiod = input.int(14, title='ATRperiod', minval=1, maxval=500, group="Fibonacci")EMA = ta.ema(close, EMAperiod)TR1 = math.max(high - low, math.abs(high - close[1]))TR = math.max(TR1, math.abs(low - close[1]))ATR = ta.sma(TR, ATRperiod)F2 = input(defval=1.618, title='Fibonacci Ratio 2', group="Fibonacci")F3 = input(defval=2.618, title='Fibonacci Ratio 3', group="Fibonacci")F4 = input(defval=4.236, title='Fibonacci Ratio 4', group="Fibonacci")R1 = ATRR2 = ATR * F2R3 = ATR * F3R4 = ATR * F4FIBOTOP4 = EMA + R4FIBOTOP3 = EMA + R3FIBOTOP2 = EMA + R2FIBOTOP1 = EMA + R1FIBOBOT1 = EMA - R1FIBOBOT2 = EMA - R2FIBOBOT3 = EMA - R3FIBOBOT4 = EMA - R4plot(FIBOTOP4, title='FIBOTOP4', linewidth=1, color=color.new(color.orange, 0))plot(FIBOTOP3, title='FIBOTOP3', linewidth=1, color=color.new(color.aqua, 20))plot(FIBOTOP2, title='FIBOTOP2', linewidth=1, color=color.new(color.gray, 40))plot(FIBOTOP1, title='FIBOTOP1', linewidth=1, color=color.new(color.purple, 40))plot(FIBOBOT1, title='FIBOBOT1', linewidth=1, color=color.new(color.green, 40))plot(FIBOBOT2, title='FIBOBOT2', linewidth=1, color=color.new(color.yellow, 40))plot(FIBOBOT3, title='FIBOBOT3', linewidth=1, color=color.new(color.blue, 20))plot(FIBOBOT4, title='FIBOBOT4', linewidth=1, color=color.new(color.aqua, 0))// plot(EMA[1], style=plot.style_cross, title='EMA', color=color.new(color.red, 0))prefmS = input.string(title="FiboLong", options=["cross_FIBOBOT1(green)", "cross_FIBOBOT2(yellow)", "cross_FIBOBOT3(blue)", "cross_FIBOBOT4(aqua)", "Disable"] , defval="cross_FIBOBOT2(yellow)", group="Long")_prefmS = false if (prefmS == "cross_FIBOBOT1(green)" ) _prefmS := ta.crossunder(vt, FIBOBOT1)if (prefmS == "cross_FIBOBOT2(yellow)" ) _prefmS := ta.crossunder(vt, FIBOBOT2)if (prefmS == "cross_FIBOBOT3(blue)" ) _prefmS := ta.crossunder(vt, FIBOBOT3) if (prefmS == "cross_FIBOBOT4(aqua)" ) _prefmS := ta.crossunder(vt, FIBOBOT4)if (prefmS == "Disable" ) _prefmS := low<low[1] or low>low[1] // }longs= _prefmS//// === Bot Codes === { enterlong = input("Long Code", title='Long Enter', group="Long Code")exitlong = input("Long Exit Code", title='Long Exit', group="Long Code")// }// === Extra === {tpslacL= input(true, title="TakeProfit StopLoss Aktif Et", group="ðŸ³Long")// }////////////////////////////////////////////////////////////////////////////////////////////TPSL// === TP SL === {per(pcnt) => strategy.position_size > 0 and tpslacL ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)trof = 0stoplossL = input.float(title=" Stop loss", defval= 1.9, minval=0.1, step=0.1, group="ðŸ³Long")tpL = input.float(title=" Take profit", defval= 0.7, minval=0.1, step=0.1, group="ðŸ³Long")// }////////////////////////////////////////////////////////////////////////////////////////////strategy.entry("AL", strategy.long, when= longs and window(), alert_message=enterlong, comment="Long")strategy.close("AL", when= ta.cross(vt, FIBOTOP3), alert_message = exitlong, comment="Cross") strategy.exit("AL", profit = per(tpL), loss = per(stoplossL), trail_points=per(tpL+0.1) , trail_offset=trof, alert_message = exitlong, comment="TPorSL")