Pine Script v4 · Strategy
Bollinger Band + RSI + ADX + MACD + Heikinashi
A Pine Script v4 strategy built on SMA (dX, adxLen), Stdev (high, 3) and RSI (close, 16). 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 is one contract and pays no commission. 13 settings; defaults include Trading Session 0930-1500, Bollinger Band Source high and Bollinger Band Length 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 Bollinger Band + RSI + ADX + MACD + Heikinashi 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 + RSI + ADX + MACD + Heikinashi 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, so there is no result to report. Its code limits trading to a session window, which can leave these candles out. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can Bollinger Band + RSI + ADX + MACD + Heikinashi be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Bollinger Band + RSI + ADX + MACD + Heikinashi use a stop loss?
- Yes
- strategy.exit sets a stop on line 96.
- Does Bollinger Band + RSI + ADX + MACD + Heikinashi run in Zeal Terminal?
- Yes
- It compiles in 32 ms and runs 1,000 bars in 129 ms, in the browser.
BTCUSDT · 1D · default settings
- Bollinger Band Upper
- Bollinger Band Lower
- 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
- 0.00%
- $0.00
One run with the author's default settings, $100,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.
-
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 94, 95. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 57
transp = on line 57. v5 folds the transparency into the colour with color.new(c, transp).
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 max → math.max, abs → math.abs, sma → ta.sma, stdev → ta.stdev, rsi → ta.rsi, security → request.security, heikinashi → ticker.heikinashi, ema → ta.ema.
- 2 strategy calls use the when = argument (line 94, 95). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 2 before, 4 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 11: max → math.max
- Line 11: max → math.max
- Line 11: abs → math.abs
- Line 11: abs → math.abs
- Line 12: max → math.max
- Line 28: max → math.max
30 more edits
- Line 28: max → math.max
- Line 28: abs → math.abs
- Line 28: abs → math.abs
- Line 29: max → math.max
- Line 46: abs → math.abs
- Line 47: sma → ta.sma
- Line 52: //@version=4 → //@version=5
- Line 55: input(type = input.session) → input.session()
- Line 57: transp = 95 → color.new(sessionColor, 95)
- Line 59: input(type = input.source) → input.source()
- Line 60: input(type = input.integer) → input.int()
- Line 61: input(type = input.float) → input.float()
- Line 62: sma → ta.sma
- Line 63: stdev → ta.stdev
- Line 69: input(type = input.source) → input.source()
- Line 70: input(type = input.integer) → input.int()
- Line 71: input(type = input.float) → input.float()
- Line 72: rsi → ta.rsi
- Line 74: input(type = input.integer) → input.int()
- Line 75: input(type = input.integer) → input.int()
- Line 78: security → request.security
- Line 78: heikinashi → ticker.heikinashi
- Line 79: security → request.security
- Line 79: heikinashi → ticker.heikinashi
- Line 82: input(type = input.source) → input.source()
- Line 86: ema → ta.ema
- Line 87: ema → ta.ema
- Line 89: sma → ta.sma
- Line 92: max → math.max
- Line 93: max → math.max
⋯ - trueRange := max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))+ trueRange := math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))- directionalMovementMinus := nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0+ directionalMovementMinus := nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0 ⋯ - trueRange := max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))+ trueRange := math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))- directionalMovementPlus := high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0+ directionalMovementPlus := high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0 ⋯ dIMinus := dIMinusCalc(adxLen)- dX := abs(dIPlus-dIMinus) / (dIPlus+dIMinus)*100+ dX := math.abs(dIPlus-dIMinus) / (dIPlus+dIMinus)*100- aDX := sma(dX, adxLen)+ aDX := ta.sma(dX, adxLen) ⋯BarInSession(sess) => time(timeframe.period, sess) != 0-//@version=4+//@version=5strategy("Bollinger Band + RSI + ADX + MACD", overlay=true)//Session-session = input(title="Trading Session", type=input.session, defval="0930-1500")+session = input.session(title="Trading Session", defval="0930-1500")sessionColor = BarInSession(session) ? color.green : na-bgcolor(color=sessionColor, transp=95)+bgcolor(color=color.new(sessionColor, 95))// Bollinger Bands-src = input(high, title="Bollinger Band Source", type=input.source)+src = input.source(high, title="Bollinger Band Source")-length = input(3, minval=1, type=input.integer, title="Bollinger Band Length")+length = input.int(3, minval=1, title="Bollinger Band Length")-mult = input(4.989, minval=0.001, maxval=50, step=0.001, type=input.float, title="Bollinger Band Std Dev")+mult = input.float(4.989, minval=0.001, maxval=50, step=0.001, title="Bollinger Band Std Dev")-basis = sma(src, length)+basis = ta.sma(src, length)-dev = mult * stdev(src, length)+dev = mult * ta.stdev(src, length)upper = basis + dev⋯// RSI-rsiSrc = input(close, title="RSI Source", type=input.source)+rsiSrc = input.source(close, title="RSI Source")-rsiLength = input(16, minval=1, type=input.integer, title="RSI Length")+rsiLength = input.int(16, minval=1, title="RSI Length")-rsiComparator = input(39.2, title="RSI Comparator", type=input.float, step=0.1)+rsiComparator = input.float(39.2, title="RSI Comparator", step=0.1)-rsi = rsi(rsiSrc, rsiLength)+rsi = ta.rsi(rsiSrc, rsiLength)// ADX-adxLength = input(14, minval=1, type=input.integer, title="ADX Length")+adxLength = input.int(14, minval=1, title="ADX Length")-adxComparator = input(14, minval=1, type=input.integer, title="ADX Comparator")+adxComparator = input.int(14, minval=1, title="ADX Comparator")adx = Adx(adxLength)// Heikinashi-haClose = security(heikinashi(syminfo.ticker), timeframe.period, close)+haClose = request.security(ticker.heikinashi(syminfo.ticker), timeframe.period, close)-haOpen = security(heikinashi(syminfo.ticker), timeframe.period, open)+haOpen = request.security(ticker.heikinashi(syminfo.ticker), timeframe.period, open)nextHaOpen = (haOpen + haClose) / 2//MACD-macdCalcTypeProcessed = input(title="MACD Source", type=input.source, defval=high)+macdCalcTypeProcessed = input.source(title="MACD Source", defval=high)fast = input(12, title="MACD Fast")⋯signalLen = input(15, title="MACD Signal")-fastMA = ema(macdCalcTypeProcessed, fast)+fastMA = ta.ema(macdCalcTypeProcessed, fast)-slowMA = ema(macdCalcTypeProcessed, slow)+slowMA = ta.ema(macdCalcTypeProcessed, slow)macd = fastMA - slowMA-signal = sma(macd, signalLen)+signal = ta.sma(macd, signalLen)longCondition() => (low < lower) and (rsi[0] > rsiComparator) and (adx > adxComparator) and (close > nextHaOpen) and BarInSession(session) and macd > signal-stop = (close - max((low - (low * 0.0022)), (close - (close * 0.0032)))) / syminfo.mintick+stop = (close - math.max((low - (low * 0.0022)), (close - (close * 0.0032)))) / syminfo.mintick-target = (max(upper, (close + (close * 0.0075))) - close) / syminfo.mintick+target = (math.max(upper, (close + (close * 0.0075))) - close) / syminfo.mintickstrategy.entry("SX,LE", strategy.long, when=longCondition(), comment="SX,LE")⋯Clean v5
VerifiedSame 4 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 83: input() → input.int()
- Line 84: input() → input.int()
- Line 85: input() → input.int()
- Line 94: when = longCondition() → if block
- Line 95: when = (not BarInSession(session)) → if block
⋯macdCalcTypeProcessed = input.source(title="MACD Source", defval=high)-fast = input(12, title="MACD Fast")+fast = input.int(12, title="MACD Fast")-slow = input(20, title="MACD Slow")+slow = input.int(20, title="MACD Slow")-signalLen = input(15, title="MACD Signal")+signalLen = input.int(15, title="MACD Signal")fastMA = ta.ema(macdCalcTypeProcessed, fast)⋯target = (math.max(upper, (close + (close * 0.0075))) - close) / syminfo.mintick-strategy.entry("SX,LE", strategy.long, when=longCondition(), comment="SX,LE")+if longCondition()+ strategy.entry("SX,LE", strategy.long, comment="SX,LE")-strategy.close_all(when=(not BarInSession(session)))+if (not BarInSession(session))+ strategy.close_all()strategy.exit("LX", from_entry="SX,LE", profit=target, loss=stop)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: 4 before, 2 after on BTCUSDT 4h, 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.
⋯BarInSession(sess) => time(timeframe.period, sess) != 0-//@version=5+//@version=6strategy("Bollinger Band + RSI + ADX + MACD", overlay=true)⋯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 |
|---|---|---|---|
| Trading Session | 0930-1500 | session | sessionColor line 91 close_all |
| Bollinger Band Source | high | source | basis dev |
| Bollinger Band Length | 3 | int (written input.integer) · min 1 | basis dev |
| Bollinger Band Std Dev | 4.989 | float · min 0.001 · max 50 · step 0.001 | dev |
| RSI Source | close | source | rsi |
| RSI Length | 16 | int (written input.integer) · min 1 | rsi |
| RSI Comparator | 39.2 | float · step 0.1 | line 91 |
| ADX Length | 14 | int (written input.integer) · min 1 | adx |
| ADX Comparator | 14 | int (written input.integer) · min 1 | line 91 |
| MACD Source | high | source | fastMA slowMA |
| MACD Fast | 12 | int | fastMA |
| MACD Slow | 20 | int | slowMA |
| MACD Signal | 15 | int | signal |
What it calculates
- SMA (
sma,ta.smain v5)dX, adxLenaDX · line 47 - SMA (
sma,ta.smain v5)Bollinger Band Source (high), Bollinger Band Length (3)basis · line 62 - Stdev (
stdev,ta.stdevin v5)Bollinger Band Source (high), Bollinger Band Length (3)dev · line 63 - RSI (
rsi,ta.rsiin v5)RSI Source (close), RSI Length (16)rsi · line 72 - EMA (
ema,ta.emain v5)MACD Source (high), MACD Fast (12)fastMA · line 86 - EMA (
ema,ta.emain v5)MACD Source (high), MACD Slow (20)slowMA · line 87 - SMA (
sma,ta.smain v5)macd, MACD Signal (15)signal · line 89
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 SX,LE long | longCondition() | On | 94 |
| Close | (not BarInSession(session)) | On | 95 |
| Exit LX stop and limit | every bar | On | 96 |
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 data2 security call(s), none with lookahead on.
- 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% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.5% | +5.5% | 2 | 0% | 0.00 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 5 | 0% | 0.00 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 4 | 25% | 1.19 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 7 | 29% | 1.56 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): heikinashi:SYMBOL D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), heikinashi:BTCUSDT D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), fetched from Binance's public market data for each market.
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 + RSI + ADX + MACD + Heikinashi this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rsi stdev sma | v4 strategy | +54.8% | 9 | 13.1% |
| 5 Minute Scalping Strategy by Coachman0912 | sma ema stdev rsi | v5 strategy | No trades on this market | ||
| RSI Rising Crypto Trending Strategy by exlux99 | sma stdev ema rsi | v4 strategy | No trades on this market | ||
| [KL] Bollinger bands + RSI Strategy by DojiEmoji | sma stdev ema rsi | v4 strategy | +28.2% | 30 | 14.7% |
| [KL] Bollinger Bands Consolidation Strategy by DojiEmoji | sma stdev ema rsi | v4 strategy | +39.1% | 33 | 19.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 32 ms | With a workaround 1,000 bars in 129 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.
“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/// © abilash.s.90dIMinusCalc(adxLen) => smoothedTrueRange = 0.0 smoothedDirectionalMovementMinus = 0.0 dIMinus = 0.0 trueRange = 0.0 directionalMovementMinus = 0.0 trueRange := max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) directionalMovementMinus := nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0 smoothedTrueRange := nz(smoothedTrueRange[1]) - (nz(smoothedTrueRange[1])/adxLen) + trueRange smoothedDirectionalMovementMinus := nz(smoothedDirectionalMovementMinus[1]) - (nz(smoothedDirectionalMovementMinus[1])/adxLen) + directionalMovementMinus dIMinus := smoothedDirectionalMovementMinus / smoothedTrueRange * 100 dIMinusdIPlusCalc(adxLen) => smoothedTrueRange = 0.0 smoothedDirectionalMovementPlus = 0.0 dIPlus = 0.0 trueRange = 0.0 directionalMovementPlus = 0.0 trueRange := max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1]))) directionalMovementPlus := high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0 smoothedTrueRange := nz(smoothedTrueRange[1]) - (nz(smoothedTrueRange[1])/adxLen) + trueRange smoothedDirectionalMovementPlus := nz(smoothedDirectionalMovementPlus[1]) - (nz(smoothedDirectionalMovementPlus[1])/adxLen) + directionalMovementPlus dIPlus := smoothedDirectionalMovementPlus / smoothedTrueRange * 100 dIPlus Adx(adxLen) => dIPlus = 0.0 dIMinus = 0.0 dX = 0.0 aDX = 0.0 dIPlus := dIPlusCalc(adxLen) dIMinus := dIMinusCalc(adxLen) dX := abs(dIPlus-dIMinus) / (dIPlus+dIMinus)*100 aDX := sma(dX, adxLen) aDX BarInSession(sess) => time(timeframe.period, sess) != 0//@version=4strategy("Bollinger Band + RSI + ADX + MACD", overlay=true)//Sessionsession = input(title="Trading Session", type=input.session, defval="0930-1500")sessionColor = BarInSession(session) ? color.green : nabgcolor(color=sessionColor, transp=95)// Bollinger Bandssrc = input(high, title="Bollinger Band Source", type=input.source)length = input(3, minval=1, type=input.integer, title="Bollinger Band Length")mult = input(4.989, minval=0.001, maxval=50, step=0.001, type=input.float, title="Bollinger Band Std Dev")basis = sma(src, length)dev = mult * stdev(src, length)upper = basis + devlower = basis - devplot(upper, title="Bollinger Band Upper", color=color.red)plot(lower, title="Bollinger Band Lower", color=color.green)// RSIrsiSrc = input(close, title="RSI Source", type=input.source)rsiLength = input(16, minval=1, type=input.integer, title="RSI Length")rsiComparator = input(39.2, title="RSI Comparator", type=input.float, step=0.1)rsi = rsi(rsiSrc, rsiLength)// ADXadxLength = input(14, minval=1, type=input.integer, title="ADX Length")adxComparator = input(14, minval=1, type=input.integer, title="ADX Comparator")adx = Adx(adxLength)// HeikinashihaClose = security(heikinashi(syminfo.ticker), timeframe.period, close)haOpen = security(heikinashi(syminfo.ticker), timeframe.period, open)nextHaOpen = (haOpen + haClose) / 2//MACDmacdCalcTypeProcessed = input(title="MACD Source", type=input.source, defval=high)fast = input(12, title="MACD Fast")slow = input(20, title="MACD Slow")signalLen = input(15, title="MACD Signal")fastMA = ema(macdCalcTypeProcessed, fast)slowMA = ema(macdCalcTypeProcessed, slow)macd = fastMA - slowMAsignal = sma(macd, signalLen)longCondition() => (low < lower) and (rsi[0] > rsiComparator) and (adx > adxComparator) and (close > nextHaOpen) and BarInSession(session) and macd > signalstop = (close - max((low - (low * 0.0022)), (close - (close * 0.0032)))) / syminfo.minticktarget = (max(upper, (close + (close * 0.0075))) - close) / syminfo.mintickstrategy.entry("SX,LE", strategy.long, when=longCondition(), comment="SX,LE")strategy.close_all(when=(not BarInSession(session)))strategy.exit("LX", from_entry="SX,LE", profit=target, loss=stop)