The idea
This is LucasVivien's open-source strategy, published as MA Bollinger Bands + RSI (Strategy) (short title MABB+RSI (Strat)). Besides the MPL 2.0 header and © LucasVivien, the source credits ChartArt, Matthew J. Slabosz, and Zen & The Art of Trading. It is closer to mean reversion than to a breakout chase: it waits for price to travel outside the lower band and then close back inside it, with RSI having recently crossed up through its midline, before treating that as a long. Shorts are the mirror image, using the upper band and an RSI cross down through the midline.
Both longs and shorts are enabled by default. A volatility filter is also on: signals are dropped when Bollinger width is extremely wide or extremely narrow versus its own long baseline. Date and session filters are off by default. On the exit side, fixed take-profit and fixed stop-loss are both off; the script uses an ATR trailing stop, and the default multiplier of 9 keeps that trail relatively far from entry. The author's chart is BINANCE:BTCUSDT, 15-minute. Entries also require barstate.isconfirmed, so the signal is only valid once the bar is confirmed.

How the lines are built
- The mid-line defaults to a 200-period simple average of close. It can be switched to EMA, WMA, VWMA, or HMA; the length is set by MA Length.
- The bands are not a standard deviation around that mid-line. Width is BBdev = ta.stdev(close, BBlen) * BBX, with default length 200 and multiplier 2, then upper = mid-line + BBdev and lower = mid-line - BBdev. MA Length and BB Length are separate inputs; both happen to default to 200.
- The long band condition, BBbull, is open below the lower band and close back above it. The short condition, BBbear, is the mirror: open above the upper band and close back below it.
- RSI uses close and defaults to length 6. The midline defaults to 50. RSIbull is true if, looking back the default 10 bars, RSI has crossed up through 50; RSIbear is true if it has crossed down through 50 in that window.
- Band width is upper minus lower. A signal line is a 50-period average of that width, and a baseline is a 2000-period average. Extreme high or low volatility is width moving beyond the baseline by Volatility Factor / 10. Both filters are on by default.
Entry rules
- Longs and shorts are both on by default; either side can be switched off.
- A long needs BBbull, RSIbull, no extreme-high and no extreme-low volatility, a pass on the date and session filters (off by default), and barstate.isconfirmed. It also has to be a new direction: the previous bar was not already a valid long, or the position just went flat and re-entry after a stop or target is allowed (that switch is on by default), and it must not be the same bar that just hit the stop or target.
- Shorts are symmetric: BBbear and RSIbear, with the same volatility and re-entry rules.
- When those conditions hold, the script calls strategy.entry('Long') or strategy.entry('Short'). calc_on_order_fills=true, so the script recalculates after a fill.
Exits and position size
- A trailing stop is on by default. For a long, it starts at the lowest low of the last TSLlookback bars (default 2), minus ATR times ATR Mult (ATR length 14, multiplier 9 by default), and then only ratchets up. A short starts from the recent high plus the ATR band and only ratchets down.
- Fixed stops and fixed targets are off by default. If you turn them on, the stop distance is ATR times ATR Mult, and the target is that distance times Risk:Reward (default 1).
- In the default strategy.exit, the long stop is the trailing price TSLsaved and the limit is empty, so no fixed target is placed. A valid opposite signal can also flip the position by entering the other side.
- Orders default to a cash size of 10000, with initial_capital also 10000 and commission 0.1%. The source does not set slippage.
Inputs (defaults in the source)
| Input | Default | What it does |
|---|---|---|
| Long trades / Short trades | true / true | Whether longs and shorts are allowed. |
| Use Take Profit | false | Enables a fixed take-profit. Off by default. |
| Use Stop Loss | false | Enables a fixed stop. Off by default. |
| Use Trailing Stop | true | Enables the ATR trailing stop. On by default. |
| Re-Entry after SL/TP | true | Allows another entry in the same direction after a stop or target. |
| Trailing lookback | 2 | How many bars of highs or lows seed the trailing stop. |
| ATR Mult / ATR Length | 9.0 / 14 | ATR multiplier and length. A default of 9 keeps the trail fairly far away. |
| Risk:Reward | 1 | If a fixed target is on, its distance is the stop distance times this value. |
| High Volatility / Low Volatility | true / true | Filters extreme-high and extreme-low band width. Both on by default. |
| Volatility Factor | 5.0 | How wide the extreme-volatility bands are; lower values filter more. |
| MA Type / MA Length | SMA / 200 | Type and length of the mid-line average. |
| BB Mult / BB Length | 2.0 / 200 | Standard-deviation multiplier and length for the bands. |
| RSI Cross Lookback | 10 | How many bars back to look for an RSI cross of the midline. |
| RSI Neutral / RSI Length | 50 / 6 | Midline and RSI length. |
| Enable Date Filter / Session Filter | false / false | Date and session filters are off by default. |
| Trading Session | 1000-2200:1234567 | Session used if the session filter is turned on. |
Caveats
- This is a reversion idea, not an upper-band breakout chase. A long first has to fall outside the lower band and then close back inside it.
- RSI does not have to have been oversold first; a cross up through 50 in the last 10 bars is enough. That is looser than requiring RSI to be above 50 now.
- Both extreme-high and extreme-low volatility filters are on by default, so very tight ranges and sudden expansions can suppress signals.
- The default ATR multiplier on the trail is 9, which sits well away from entry, and the fixed target is off, so a losing trade may wait for that trail.
- The date filter's start and end default to 2022 and 2023, but the switch is off, so that window is not applied unless you turn it on.
- The first header line reads “This close code is subject to...”, but it still declares MPL 2.0 and © LucasVivien. Coinpred ships the unmodified source.
- The author's chart is 15-minute. The same 200-period bands and 6-period RSI will behave very differently on daily or 1-minute charts.
Install it on TradingView
- Download the .pine file from Coinpred (a current membership is required; see the page) or check the original publication for a newer revision.
- Open the symbol and timeframe you want in TradingView, open the Pine Editor, paste the source, and add it to the chart.
- Start with the default 200-period average and bands, 6-period RSI, and trailing-stop-only exits so you can see the lower-band recovery and the RSI cross, then change lengths, multipliers, or switches.
- The source sizes orders at 10000 in cash, sets initial capital to 10000, commission to 0.1%, and turns on calc_on_order_fills. Live order routing has to be set separately.
- Crypto trades around the clock. The tester's timezone and session settings may differ from your venue by several hours.
About backtest figures
Source, license, and version
- Source: https://www.tradingview.com/script/2MMNHl97-MA-Bollinger-Bands-RSI/
- Author: LucasVivien (header © LucasVivien; also credits ChartArt, Matthew J. Slabosz, and Zen & The Art of Trading)
- License: Mozilla Public License 2.0. Redistribution must keep the original copyright and license notices; if you modify the source file, the modified file must remain under MPL 2.0. Coinpred ships the unmodified source.
- Version: 14.0 in the publication record and pine-facade. scriptAccess is open_no_auth.



