Pine Script v4 · Strategy
Fibonacci candle with Fibonacci ema strategy
A Pine Script v4 strategy built on EMA (volume_avg, 12), Crossover (volume_avg, ema_volume_avg) and Crossunder (volume_avg, ema_volume_avg). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 5 settings; defaults include Length ema vol 12, K 9 and D 3.
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 candle with Fibonacci ema strategy 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 Fibonacci candle with Fibonacci ema strategy do on BTCUSDT 1D with default settings?
- +27.57%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Fibonacci candle with Fibonacci ema 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 candle with Fibonacci ema strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Fibonacci candle with Fibonacci ema strategy run in Zeal Terminal?
- Yes
- It compiles in 18 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- Crossover
- Crossunder
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- SMA
- SMA
- Winning trade
- Losing trade
- Net profit
- +27.57%
- $275.75
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 1 won · 2 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 2.21
- gross profit ÷ gross loss
- Max drawdown
- 28.28%
- −$282.77
One run with the author's default settings, $1,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.
-
Likely bug
ema(src, 55) ignores the settings line 22
Line 22 hard-codes 55 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 55)ema(src, length_ema_vol) -
Likely bug
ema(src, 1) ignores the settings line 23
Line 23 hard-codes 1 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 1)ema(src, length_ema_vol) -
Likely bug
ema(src, 2) ignores the settings line 24
Line 24 hard-codes 2 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 2)ema(src, length_ema_vol) -
Likely bug
ema(src, 3) ignores the settings line 25
Line 25 hard-codes 3 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 3)ema(src, length_ema_vol) -
Likely bug
ema(src, 5) ignores the settings line 26
Line 26 hard-codes 5 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 5)ema(src, length_ema_vol) -
Likely bug
ema(src, 8) ignores the settings line 27
Line 27 hard-codes 8 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 8)ema(src, length_ema_vol) -
Likely bug
ema(src, 13) ignores the settings line 28
Line 28 hard-codes 13 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 13)ema(src, length_ema_vol) -
Likely bug
ema(src, 21) ignores the settings line 29
Line 29 hard-codes 21 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 21)ema(src, length_ema_vol) -
Likely bug
ema(src, 34) ignores the settings line 30
Line 30 hard-codes 34 where line 16 uses “Length ema vol”. Changing those settings moves one band but not this one.
ema(src, 34)ema(src, length_ema_vol) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
2 settings have no label
In the settings dialog length_ema_vol (line 14), stoch_middle (line 42) 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 47, 48. 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, crossover → ta.crossover, crossunder → ta.crossunder, sma → ta.sma, stoch → ta.stoch.
- 2 strategy calls use the when = argument (line 47, 48). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: ema → ta.ema
- Line 19: crossover → ta.crossover
- Line 20: crossunder → ta.crossunder
- Line 22: ema → ta.ema
- Line 23: ema → ta.ema
11 more edits
- Line 24: ema → ta.ema
- Line 25: ema → ta.ema
- Line 26: ema → ta.ema
- Line 27: ema → ta.ema
- Line 28: ema → ta.ema
- Line 29: ema → ta.ema
- Line 30: ema → ta.ema
- Line 38: sma → ta.sma
- Line 38: stoch → ta.stoch
- Line 39: sma → ta.sma
- Line 47: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
⋯// © SoftKill21-//@version=4+//@version=5strategy("Fibonacci candle", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )⋯volume_avg =(volume[0] + volume[1] + volume[2] + volume[3] +volume[5] + volume[8] + volume[13]+ volume[21] + volume[34] + volume[55]) / 10-ema_volume_avg = ema(volume_avg,length_ema_vol)+ema_volume_avg = ta.ema(volume_avg,length_ema_vol)// plot(volume_avg,color=color.white)// plot(ema_volume_avg)-longvol = crossover(volume_avg,ema_volume_avg)+longvol = ta.crossover(volume_avg,ema_volume_avg)-shortvol = crossunder(volume_avg, ema_volume_avg)+shortvol = ta.crossunder(volume_avg, ema_volume_avg)src = avg_close//input(avg_close, title="Source")-out55 = ema(src, 55)+out55 = ta.ema(src, 55)-out1 = ema(src, 1)+out1 = ta.ema(src, 1)-out2 = ema(src, 2)+out2 = ta.ema(src, 2)-out3 = ema(src, 3)+out3 = ta.ema(src, 3)-out5 = ema(src, 5)+out5 = ta.ema(src, 5)-out8 = ema(src, 8)+out8 = ta.ema(src, 8)-out13 = ema(src, 13)+out13 = ta.ema(src, 13)-out21 = ema(src, 21)+out21 = ta.ema(src, 21)-out34 = ema(src, 34)+out34 = ta.ema(src, 34)avg_ema = (out55 + out1 + out2 + out3+ out5 + out8 + out13 + out21 + out34)/9⋯smoothK = input(3, title="Smooth", minval=1)-k = sma(stoch(close, high, low, periodK), smoothK)+k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)avg_stoch = (k+d)/2⋯short = avg_open > avg_close and avg_close < avg_close[1] and avg_low < avg_low[1] and avg_close[1] < avg_close[2] and avg_low[1] < avg_low[2] and shortvol and avg_stoch<stoch_middle-strategy.entry("long",1,when=long and avg_close > avg_ema)+strategy.entry("long",strategy.long,when=long and avg_close > avg_ema)strategy.close('long',when=short and avg_close < avg_ema)Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 14: input() → input.int()
- Line 35: input() → input.int()
- Line 36: input() → input.int()
- Line 37: input() → input.int()
- Line 42: input() → input.int()
- Line 47: when = long and avg_close > avg_ema → if block
- Line 48: when = short and avg_close < avg_ema → if block
⋯avg_open = (open[0] + open[1] + open[2] + open[3] +open[5] + open[8] + open[13]+ open[21] + open[34] + open[55]) / 10-length_ema_vol=input(12)+length_ema_vol=input.int(12)volume_avg =(volume[0] + volume[1] + volume[2] + volume[3] +volume[5] + volume[8] + volume[13]+ volume[21] + volume[34] + volume[55]) / 10⋯//stochastic -periodK = input(9, title="K", minval=1)+periodK = input.int(9, title="K", minval=1)-periodD = input(3, title="D", minval=1)+periodD = input.int(3, title="D", minval=1)-smoothK = input(3, title="Smooth", minval=1)+smoothK = input.int(3, title="Smooth", minval=1)k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)⋯//plot(avg_stoch)-stoch_middle=input(40)+stoch_middle=input.int(40)//plot(50)⋯short = avg_open > avg_close and avg_close < avg_close[1] and avg_low < avg_low[1] and avg_close[1] < avg_close[2] and avg_low[1] < avg_low[2] and shortvol and avg_stoch<stoch_middle-strategy.entry("long",strategy.long,when=long and avg_close > avg_ema)+if long and avg_close > avg_ema+ strategy.entry("long",strategy.long)-strategy.close('long',when=short and avg_close < avg_ema)+if short and avg_close < avg_ema+ strategy.close('long')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: 3 before, 5 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.
⋯// © SoftKill21-//@version=5+//@version=6strategy("Fibonacci candle", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )⋯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 |
|---|---|---|---|
| Length ema vol (no label in the script) | 12 | int | ema_volume_avg |
| K | 9 | int · min 1 | k |
| D | 3 | int · min 1 | d |
| Smooth | 3 | int · min 1 | k |
| Stoch middle (no label in the script) | 40 | int | long short |
What it calculates
- EMA (
ema,ta.emain v5)volume_avg, Length ema vol (12)ema_volume_avg · line 16 - Crossover (
crossover,ta.crossoverin v5)volume_avg, ema_volume_avglongvol · line 19 - Crossunder (
crossunder,ta.crossunderin v5)volume_avg, ema_volume_avgshortvol · line 20 - EMA (
ema,ta.emain v5)src, 55out55 · line 22 - EMA (
ema,ta.emain v5)src, 1out1 · line 23 - EMA (
ema,ta.emain v5)src, 2out2 · line 24 - EMA (
ema,ta.emain v5)src, 3out3 · line 25 - EMA (
ema,ta.emain v5)src, 5out5 · line 26 - EMA (
ema,ta.emain v5)src, 8out8 · line 27 - EMA (
ema,ta.emain v5)src, 13out13 · line 28 - EMA (
ema,ta.emain v5)src, 21out21 · line 29 - EMA (
ema,ta.emain v5)src, 34out34 · line 30 - SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, periodK), Smooth (3)k · line 38 - SMA (
sma,ta.smain v5)k, D (3)d · line 39
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 | long and avg_close > avg_ema | On | 47 |
| Close long | short and avg_close < avg_ema | On | 48 |
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 | +27.6% | +102.5% | 3 | 33% | 2.21 | 28.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −11.6% | +5.5% | 7 | 14% | 0.12 | 14.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −4.6% | +9.8% | 3 | 33% | 0.91 | 37.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +28.0% | +8.4% | 3 | 33% | 6.20 | 8.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −17.9% | +16.7% | 7 | 29% | 0.78 | 41.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +15.3% | +21.5% | 6 | 33% | 1.97 | 10.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +31.8% | +148.3% | 3 | 33% | 2.58 | 36.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +16.4% | +17.1% | 4 | 25% | 3.28 | 9.4% | 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 | 0 | — | $0.00 |
| Sideways market | 2 | 50% | $296.25 |
| Falling market | 1 | 0% | −$19.23 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
22.0%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 20.8% to 22.0%; the tick is what actually happened, 20.8%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Jul 2024 68,249.90 | 8 Sep 2024 54,160.90 | 41 | −$208.02 |
| long | 15 Oct 2024 66,084.00 | 30 Aug 2025 108,377.00 | 319 | $504.27 |
| long | 14 Apr 2026 74,418.00 | 30 May 2026 73,460.80 | 46 | −$19.23 |
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 candle with Fibonacci ema strategy this page | — | v4 strategy | +27.6% | 3 | 28.3% |
| Stochastic Moving Average by LucasVivien | stoch sma ema | v5 strategy | +2.8% | 7 | 4.4% |
| OTT-Stoch-TP-SL by BigCoinHunter | ema sma stoch | v5 strategy | No trades on this market | ||
| Webhook Starter Kit [HullBuster] by tradingtudi | ema stoch sma | v4 strategy | does not run in Zeal Terminal | ||
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | With a workaround 1,000 bars in 46 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 47) 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/// © SoftKill21//@version=4strategy("Fibonacci candle", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )//plot of our fibonacci candle// Fibonacci // Fn = Fn-1 + Fn-2// F10 = 55// 0 1 2 3 5 8 13 21 34 55avg_close = (close[0] + close[1] + close[2] + close[3] +close[5] + close[8] + close[13]+ close[21] + close[34] + close[55]) / 10avg_high = (high[0] + high[1] + high[2] + high[3] +high[5] + high[8] + high[13]+ high[21] + high[34] + high[55]) / 10avg_low = (low[0] + low[1] + low[2] + low[3] +low[5] + low[8] + low[13]+ low[21] + low[34] + low[55]) / 10avg_open = (open[0] + open[1] + open[2] + open[3] +open[5] + open[8] + open[13]+ open[21] + open[34] + open[55]) / 10length_ema_vol=input(12)volume_avg =(volume[0] + volume[1] + volume[2] + volume[3] +volume[5] + volume[8] + volume[13]+ volume[21] + volume[34] + volume[55]) / 10ema_volume_avg = ema(volume_avg,length_ema_vol)// plot(volume_avg,color=color.white)// plot(ema_volume_avg)longvol = crossover(volume_avg,ema_volume_avg)shortvol = crossunder(volume_avg, ema_volume_avg)src = avg_close//input(avg_close, title="Source")out55 = ema(src, 55)out1 = ema(src, 1)out2 = ema(src, 2)out3 = ema(src, 3)out5 = ema(src, 5)out8 = ema(src, 8)out13 = ema(src, 13)out21 = ema(src, 21)out34 = ema(src, 34)avg_ema = (out55 + out1 + out2 + out3+ out5 + out8 + out13 + out21 + out34)/9//plot(avg_ema)//plotcandle(avg_open, avg_high, avg_low, avg_close, title='Title', color = avg_open < avg_close ? color.green : color.red, wickcolor=color.white)//stochastic periodK = input(9, title="K", minval=1)periodD = input(3, title="D", minval=1)smoothK = input(3, title="Smooth", minval=1)k = sma(stoch(close, high, low, periodK), smoothK)d = sma(k, periodD)avg_stoch = (k+d)/2//plot(avg_stoch)stoch_middle=input(40)//plot(50)//long = avg_open < avg_close and avg_close > avg_close[1] and avg_high > avg_high[1] and avg_close[1] > avg_close[2] and avg_high[1] > avg_high[2] and longvol and avg_stoch>stoch_middleshort = avg_open > avg_close and avg_close < avg_close[1] and avg_low < avg_low[1] and avg_close[1] < avg_close[2] and avg_low[1] < avg_low[2] and shortvol and avg_stoch<stoch_middlestrategy.entry("long",1,when=long and avg_close > avg_ema)strategy.close('long',when=short and avg_close < avg_ema)