Skip to main content

Bollinger Band Bounce — Pine Script v5 strategy

REVERSALBollinger BandsPine Script v5

This script buys when the close drops under the lower Bollinger Band and closes the position when the close rises above the upper band. It is a mean reversion rule with no stop loss, no short side and no trend filter.

Full code (free to copy)

//@version=5
strategy("BB Bounce", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
length = input.int(20)
mult = input.float(2.0)
[middle, upper, lower] = ta.bb(close, length, mult)
if (close < lower)
    strategy.entry("Long", strategy.long)
if (close > upper)
    strategy.close("Long")

Judge this code on BTCUSDT 1D →Free, in your browser, on the same candles as the table below.

Online judge verdict on BTCUSDT (measured 29 November 2026)

TimeframeSealed periodTradesReturnBuy & holdVerdict
1d2024-12-17 → 2026-10-168-4.26 %-23.25 %Not enough sealed trades
4h2026-03-12 → 2026-10-1714-5.17 %15.83 %No evidence of an edge
1h2026-08-05 → 2026-10-17221.02 %27.14 %No evidence of an edge

Past data, 10 bps per fill, last 20% of the bars sealed. Windows: full history on 1d, last 3 years on 4h, last year on 1h. Research, not advice: no result is promised.

Compared with a real TradingView run on 31 October 2026 (BINANCE:BTCUSDT, this code): identical trades 33/33 on 1D, 70/70 on 4h, same prices on all matching trades.

Measured on 29 November 2026 with the online judge’s Pine v5 engine (sa-pine-vm 0.2.1), on Binance BTCUSDT candles up to 16/10/2026 on 1D and up to 17/10/2026 on 4h and 1h. Differences with TradingView’s Strategy Tester remain possible. Binance data, CC BY-NC-SA 4.0.

Open this code in the free judge (1 click) →

Replay each verdict yourself, in your browser: 1d · 4h · 1h. The script is filled in; nothing runs until you click “Judge”.

How the script works

The opening lines set the Pine Script v5 version and declare the strategy as BB Bounce with overlay=true, so orders and levels are drawn on the price chart rather than in a separate pane. No other strategy argument is passed: initial capital, commission, slippage and order sizing stay at the platform defaults. Nothing else runs before the band calculation.

length and mult are the only inputs, an integer fixed at 20 and a float fixed at 2.0. The ta.bb call applies both to close, so each bar's closing price is the source, and returns middle, the moving average basis, plus upper and lower, each placed mult standard deviations away from that basis. The bands are recomputed on every new bar.

Entry rests on one condition: if close is below lower, strategy.entry sends a long order with the identifier Long. Exit is the mirror condition: if close is above upper, strategy.close closes that same Long position. The script defines no stop loss, no target order and no short entry, so a position stays open until the upper band condition is met.

Parameters in the code

ParameterValueRole
length20Period of the moving average basis and of the standard deviation window used by ta.bb.
mult2.0Multiplier applied to the standard deviation to place the upper and lower bands around the basis.
sourceclosePrice series handed to ta.bb; the code passes the bar close, not an input.
overlaytrueDraws the strategy on the price chart instead of a separate pane.
strategy titleBB BounceName given to the strategy in the strategy() declaration.
entry order idLongIdentifier used by strategy.entry for the long order.
exit order idLongIdentifier reused by strategy.close to flatten the long position.
Pine version5Declared by the //@version=5 annotation at the top of the script.

Known limits of this rule

Before you trust it: test it on data it never saw

A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: survives, no evidence of an edge or inconclusive.

Get the free Lab →

FAQ

Does it work on crypto?

The code only needs the close and the Bollinger Bands, so it can be applied to crypto pairs like any other symbol. Behaviour varies by market, so replay it on a period you have not seen before in Strategy Arena Lab, which is free.

How do I add a stop loss?

Add a strategy.exit call with a stop parameter, or a second close condition, after the entry block. The current code has no protective order, so the long only closes when the close is above the upper band.

Other free Pine Script v5 strategies

RSI Mean ReversionEMA Crossover 9/21EMA Ribbon 8/21/55MACD MomentumSuperTrendStochastic RSIATR BreakoutVWAP BounceRSI + EMA ComboFaber 10-Month TimingGolden Cross SMA 50/200Bollinger Squeeze BreakoutKeltner Channel Breakout 20/1.5Donchian Turtle 20/10ADX 25 & DMI 14 TrendParabolic SAR 0.02/0.2Hull Moving Average 55ALMA 20 Gaussian TrendCCI 20 (+100) BreakoutMoney Flow Index MFI 14 (20/80)ATR 14 Chandelier StopIchimoku Tenkan 9 / Kijun 26Linear Regression 20ROC 14 + EMA 200 FilterWilliams %R 14 PullbackNo-Leak Weekly EMA FilterPivot High/Low BreakoutAI-style ATR Breakout + EMA 200
TradingView Starter
Choose the account path. Prove the strategy separately.
Your first chart and price alert do not require the Lab. Strategy Arena proof remains required before trusting or exporting a strategy.
Partner attribution is for first-time users and web purchases only. Strategy Arena may earn a commission on eligible purchases; starting with a free account needs no payment.
I have never had an account · Start free I already have an account Check a strategy
More TradingView paths
Evidence-gated Pine review

Educational code on past data. No investment advice; no result is promised.