Pine Script v4 · Strategy
Bollinger Band with Fib Golden Ratio (0.618)
A Pine Script v4 strategy built on VWMA (hlc3, 50), Stdev (hlc3, 50) and EMA (close, 200). It has 3 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 20% of equity and pays no commission. 4 settings; defaults include BB Length 50, Source hlc3 and multplier 1.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 Bollinger Band with Fib Golden Ratio (0.618) repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Bollinger Band with Fib Golden Ratio (0.618) 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; it opened a long position that was still open on the last bar, so there is no result to report. On ETHUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can Bollinger Band with Fib Golden Ratio (0.618) 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 Bollinger Band with Fib Golden Ratio (0.618) use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Bollinger Band with Fib Golden Ratio (0.618) run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 35 ms, in the browser.
BTCUSDT · 1D · default settings
- 0.618
- Plot
- 0.618 entry
- ema200
- ema50
- 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
- 7.84%
- −$783.93
One run with the author's default settings, $10,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.
-
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
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 26, 27, 30. The upgraded version below moves each call inside an if block.
-
Note
Uses long =, which v5 renamed line 26
long = on line 26. 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, ema → ta.ema, tostring → str.tostring, crossover → ta.crossover, abs → math.abs.
- 3 strategy calls use the when = argument (line 26, 27, 30). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 5 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: vwma → ta.vwma
- Line 11: stdev → ta.stdev
- Line 21: ema → ta.ema
- Line 22: ema → ta.ema
- Line 26: long = true → direction = strategy.long
4 more edits
- Line 27: tostring → str.tostring
- Line 27: crossover → ta.crossover
- Line 30: tostring → str.tostring
- Line 30: abs → math.abs
⋯// © mohanee-//@version=4+//@version=5strategy(title="Bollinger Band with Fib Golden Ratio (0.618)", shorttitle="Bollinger Band with Fib Golden Ratio" , overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) ⋯stopLoss=input(5,title="Stop Loss",minval=1)-basis = vwma(src1, length)+basis = ta.vwma(src1, length)-dev = mult * stdev(src1, length)+dev = mult * ta.stdev(src1, length)//dev3 = mult3 * stdev(src, length)⋯//plot_lower618= plot(lower_618, color=color.purple, linewidth=1, title="0.618 entry")-ema200=ema(close,200)+ema200=ta.ema(close,200)-ema50=ema(close,50)+ema50=ta.ema(close,50)plot (ema200, title="ema200", color=color.orange, linewidth=2)⋯longCondition= ema50 > ema200-strategy.entry(id="BB_Fib618", long=true, when = longCondition and ( close < lower_618 or low <= lower_618) )+strategy.entry(id="BB_Fib618", direction = strategy.long, when = longCondition and ( close < lower_618 or low <= lower_618) )-strategy.close(id="BB_Fib618", comment="points="+tostring(close - strategy.position_avg_price, "###.##") , when = strategy.position_size >= 1 and crossover(close,upper_618 )) +strategy.close(id="BB_Fib618", comment="points="+str.tostring(close - strategy.position_avg_price, "###.##") , when = strategy.position_size >= 1 and ta.crossover(close,upper_618 )) //stoploss exitstopLossVal = strategy.position_size>=1 ? strategy.position_avg_price * ( 1 - (stopLoss/100) ) : 0.00-strategy.close(id="BB_Fib618", comment="SL="+tostring(close - strategy.position_avg_price, "###.##"), when=abs(strategy.position_size)>=1 and close < stopLossVal ) //and close > strategy.position_avg_price )+strategy.close(id="BB_Fib618", comment="SL="+str.tostring(close - strategy.position_avg_price, "###.##"), when=math.abs(strategy.position_size)>=1 and close < stopLossVal ) //and close > strategy.position_avg_price )Same 5 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.source()
- Line 8: input() → input.float()
- Line 9: input() → input.int()
- Line 26: when = longCondition and ( close < lower_618 or low <= lower_618) → if block
- Line 27: when = strategy.position_size >= 1 and ta.crossover(close,upper_618 ) → if block
- Line 30: when = math.abs(strategy.position_size)>=1 and close < stopLossVal → if block
⋯strategy(title="Bollinger Band with Fib Golden Ratio (0.618)", shorttitle="Bollinger Band with Fib Golden Ratio" , overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) -length = input(50,title="BB Length" , minval=1)+length = input.int(50,title="BB Length" , minval=1)-src1 = input(hlc3, title="Source")+src1 = input.source(hlc3, title="Source")//mult1 = input(1.33, minval=0.001, maxval=50)-mult = input(1.5,title="multplier", minval=0.001, maxval=50)+mult = input.float(1.5,title="multplier", minval=0.001, maxval=50)-stopLoss=input(5,title="Stop Loss",minval=1)+stopLoss=input.int(5,title="Stop Loss",minval=1)basis = ta.vwma(src1, length)⋯longCondition= ema50 > ema200-strategy.entry(id="BB_Fib618", direction = strategy.long, when = longCondition and ( close < lower_618 or low <= lower_618) )+if longCondition and ( close < lower_618 or low <= lower_618)+ strategy.entry(id="BB_Fib618", direction = strategy.long )-strategy.close(id="BB_Fib618", comment="points="+str.tostring(close - strategy.position_avg_price, "###.##") , when = strategy.position_size >= 1 and ta.crossover(close,upper_618 )) +if strategy.position_size >= 1 and ta.crossover(close,upper_618 )+ strategy.close(id="BB_Fib618", comment="points="+str.tostring(close - strategy.position_avg_price, "###.##") ) //stoploss exitstopLossVal = strategy.position_size>=1 ? strategy.position_avg_price * ( 1 - (stopLoss/100) ) : 0.00-strategy.close(id="BB_Fib618", comment="SL="+str.tostring(close - strategy.position_avg_price, "###.##"), when=math.abs(strategy.position_size)>=1 and close < stopLossVal ) //and close > strategy.position_avg_price )+if math.abs(strategy.position_size)>=1 and close < stopLossVal+ strategy.close(id="BB_Fib618", comment="SL="+str.tostring(close - strategy.position_avg_price, "###.##") ) //and close > strategy.position_avg_price )Does it run in Pine Script v6?
Yes
Same 5 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © mohanee-//@version=5+//@version=6strategy(title="Bollinger Band with Fib Golden Ratio (0.618)", shorttitle="Bollinger Band with Fib Golden Ratio" , overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, 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 |
|---|---|---|---|
| BB Length | 50 | int · min 1 | basis dev |
| Source | hlc3 | source | basis dev |
| multplier | 1.5 | float · min 0.001 · max 50 | dev |
| Stop Loss | 5 | int · min 1 | stopLossVal |
What it calculates
- VWMA (
vwma,ta.vwmain v5)Source (hlc3), BB Length (50)basis · line 10 - Stdev (
stdev,ta.stdevin v5)Source (hlc3), BB Length (50)dev · line 11 - EMA (
ema,ta.emain v5)close, 200ema200 · line 21 - EMA (
ema,ta.emain v5)close, 50ema50 · line 22
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 BB_Fib618 long | longCondition and ( close < lower_618 or low <= lower_618) | On | 26 |
| Close BB_Fib618 | strategy.position_size >= 1 and crossover(close,upper_618 ) | On | 27 |
| Close BB_Fib618 | abs(strategy.position_size)>=1 and close < stopLossVal | On | 30 |
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% | — | 7.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 11.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.9% | +8.4% | 5 | 100% | — | 0.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −10.7% | +16.7% | 14 | 7% | 0.44 | 14.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.2% | +21.5% | 8 | 63% | 0.69 | 3.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.9% | +148.3% | 16 | 44% | 1.06 | 6.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.3% | +17.1% | 7 | 86% | 2.23 | 1.6% | 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 |
|---|---|---|---|---|---|
| Bollinger Band with Fib Golden Ratio (0.618) this page | — | v4 strategy | 0.0% | 0 | 7.8% |
| TriautoETF(TQQQ) Short Strategy B1 by BBcom | vwma ema | v5 strategy | No trades on this market | ||
| Escaping of Rate from Avarage By Mustafa OZVER Strategy by Mustafaozver | stdev ema | v4 strategy | +122.0% | 96 | 79.1% |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema stdev | v4 strategy | No trades on this market | ||
| STR-EMA Oscilator [Azzrael] by Azzrael | ema stdev | v5 strategy | +2.3% | 6 | 30.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 35 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 26) 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/// © mohanee//@version=4strategy(title="Bollinger Band with Fib Golden Ratio (0.618)", shorttitle="Bollinger Band with Fib Golden Ratio" , overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, currency=currency.USD) length = input(50,title="BB Length" , minval=1)src1 = input(hlc3, title="Source")//mult1 = input(1.33, minval=0.001, maxval=50)mult = input(1.5,title="multplier", minval=0.001, maxval=50)stopLoss=input(5,title="Stop Loss",minval=1)basis = vwma(src1, length)dev = mult * stdev(src1, length)//dev3 = mult3 * stdev(src, length)upper_618= basis + (0.618*dev)lower_618= basis - (0.618*dev)//lower_618_dev3= basis - (0.618*dev3)plot_upper618= plot(upper_618, color=color.purple, linewidth=2, title="0.618")plot(basis, color=color.purple,style=plot.style_circles, linewidth=2)plot_lower618= plot(lower_618, color=color.purple, linewidth=2, title="0.618 entry")//plot_lower618_dev3= plot(lower_618_dev3, color=color.red, linewidth=1, title="0.618 stop")//plot_lower618= plot(lower_618, color=color.purple, linewidth=1, title="0.618 entry")ema200=ema(close,200)ema50=ema(close,50)plot (ema200, title="ema200", color=color.orange, linewidth=2)plot (ema50, title="ema50", color=color.blue , linewidth=2)longCondition= ema50 > ema200strategy.entry(id="BB_Fib618", long=true, when = longCondition and ( close < lower_618 or low <= lower_618) )strategy.close(id="BB_Fib618", comment="points="+tostring(close - strategy.position_avg_price, "###.##") , when = strategy.position_size >= 1 and crossover(close,upper_618 )) //stoploss exitstopLossVal = strategy.position_size>=1 ? strategy.position_avg_price * ( 1 - (stopLoss/100) ) : 0.00strategy.close(id="BB_Fib618", comment="SL="+tostring(close - strategy.position_avg_price, "###.##"), when=abs(strategy.position_size)>=1 and close < stopLossVal ) //and close > strategy.position_avg_price )