Pine Script v5 · Strategy
B.Bands - Augmented - Intra-range - Long-Only
A Pine Script v5 strategy built on SMA (close, 20), EMA (close, 20) and Stdev (close, 20). It has 14 order rules, 2 entries 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 0.075 commission. 17 settings; defaults include Periods 20, Std 2 and Entry source close.
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 B.Bands - Augmented - Intra-range - Long-Only repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did B.Bands - Augmented - Intra-range - Long-Only 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 date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does B.Bands - Augmented - Intra-range - Long-Only run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does B.Bands - Augmented - Intra-range - Long-Only use a stop loss?
- Yes
- strategy.exit sets a stop on line 76, 78, 82, 84, 100, 102, 107, 109.
- Does B.Bands - Augmented - Intra-range - Long-Only run in Zeal Terminal?
- Yes
- It compiles in 41 ms and runs 1,000 bars in 95 ms, in the browser.
BTCUSDT · 1D · default settings
- Simple Upper Bollinger Band
- Simple Moving Average
- Simple Lower Bollinger Band
- 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, $1,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
1 setting does nothing
“Exit source” is declared but never read.
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 |
|---|---|---|---|
| Strategy System | |||
| Simple Bollinger Bands | true | bool | Simple Upper Bollinger Band Simple Lower Bollinger Band close Entry line 68 line 73 line 79 line 85 Simple Moving Average |
| Augmented Bollinger BandsSelect Bollinger Band Indicator to trade Simple or Augmented | false | bool | Augmented Upper Bollinger Band Simple Lower Bollinger Band close Entry_A line 92 line 97 line 104 line 110 Augmented Moving Average |
| Technical Inputs | |||
| Periods | 20 | int · min 2 · step 1 | middle_sim middle_augm middle_upp middle_low dev |
| StdTechnical inputs for indicator calculation, Periods for MA and Standard Deviation | 2 | float · min 0.1 · step 0.1 | dev |
| Strategy Inputs | |||
| Entry source | close | source | SLT stop_inicial entry_long entry_long_augm |
| Exit sourceFor entry: Activate signal if the source lies below (for Long) or above (for Short). For exit: When price reach target selected | high | source | unused |
| Max Spread Tolerance Beetween BandsMax. Tolerance beetween lower and upper band to allow trade for range systems | 99999.0 | float · step 0.1 | entry_long entry_long_augm |
| Profit Target | |||
| Profit to band: | opposite | string · options ["middle", "opposite"] | exit Target exit Target exit Target exit Target exit Target exit Target exit Target exit Target line 75 line 77 line 81 line 83 line 99 line 101 line 106 line 108 |
| Only sell in profitSell only if position is on profit, unless Stop Loss active | false | bool | line 73 line 79 line 97 line 104 |
| Risk Management | |||
| Stop Loss % | 3.00 | float · step 0.05 | SL |
| Implement Stop Loss?Activate Stop Loss | true | bool | exit Target |
| Trailing % | 6.00 | float · step 0.125 | SLT stop_inicial |
| Implement trailing stop? | false | bool | slts Trailing Stop |
| Position Size | |||
| % of available capitalUse a % of the total capital selected for strategy | 5 | float · max 100 · step 0.25 | position |
| Limit strategy capital?If activated, only uses the percentage of capital selected from the properties tab. Default 1000$ | false | bool | position |
| BACKTEST RANGE | |||
| Starting Date | timestamp("2019-11-01T00:00:00") | time | from_date |
| Ending DateSelect the range for backtest and live strategy | timestamp("2023-12-12T00:00:00") | time | to_date |
What it calculates
- SMAclose, Periods (20)
middle_sim · line 48 - EMAclose, Periods (20)
middle_augm · line 50 - EMAhigh, Periods (20)
middle_upp · line 51 - EMAlow, Periods (20)
middle_low · line 52 - Stdevclose, Periods (20)
dev · line 54
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 Entry long | entry_long | On | 71 |
| Exit Target stop and limit | take_profit == "middle" | On | 76 |
| Exit Target stop and limit | take_profit == "opposite" | On | 78 |
| Exit Target stop and limit | take_profit == "middle" | On | 82 |
| Exit Target stop and limit | take_profit == "opposite" | On | 84 |
| Close Entry | in_position and show_simp and slts and In_date() | On | 87 |
| Close Entry | not In_date() | On | 90 |
| Open Entry_A long | entry_long_augm | On | 95 |
| Exit Target stop and limit | take_profit == "middle" | On | 100 |
| Exit Target stop and limit | take_profit == "opposite" | On | 102 |
| Exit Target stop and limit | take_profit == "middle" | On | 107 |
| Exit Target stop and limit | take_profit == "opposite" | On | 109 |
| Close Entry_A | in_position and show_augm and slts and In_date() | On | 112 |
| Close Entry_A | not In_date() | On | 116 |
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% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 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% | 0 | 0% | — | 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% | 0 | 0% | — | 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% | 0 | 0% | — | 0.0% | 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 |
|---|---|---|---|---|---|
| B.Bands - Augmented - Intra-range - Long-Only this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| Super Breakout day trading by beststockalert | stdev sma ema | v4 strategy | No trades on this market | ||
| Super Auto Breakout Day Trade Volatile stocks by beststockalert | stdev sma ema | v4 strategy | −6.1% | 51 | 29.1% |
| VFI strategy [based on VFI indicator published by UTS] by mohanee | sma stdev ema | v4 strategy | +181.4% | 8 | 154.2% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 5 settings use the untyped input() (line 13, 14, 18, 21, 23). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 13: input() → input.source()
- Line 14: input() → input.source()
- Line 18: input() → input.bool()
- Line 21: input() → input.bool()
- Line 23: input() → input.bool()
⋯// Strategy data-entry_source = input(close, title="Entry source", group="Strategy Inputs", inline='3')+entry_source = input.source(close, title="Entry source", group="Strategy Inputs", inline='3')-exit_source = input(high, title="Exit source", group="Strategy Inputs", inline='3',tooltip='For entry: Activate signal if the source lies below (for Long) or above (for Short). For exit: When price reach target selected')+exit_source = input.source(high, title="Exit source", group="Strategy Inputs", inline='3',tooltip='For entry: Activate signal if the source lies below (for Long) or above (for Short). For exit: When price reach target selected')max_spread_bb = input.float(99999.0, title="Max Spread Tolerance Beetween Bands", step=0.1, group="Strategy Inputs",tooltip='Max. Tolerance beetween lower and upper band to allow trade for range systems')⋯take_profit = input.string("opposite", title = "Profit to band:", inline='4', options = ["middle", "opposite"], group="Profit Target")-sell_profit = input(false, title="Only sell in profit", group="Profit Target", inline='4', tooltip='Sell only if position is on profit, unless Stop Loss active')+sell_profit = input.bool(false, title="Only sell in profit", group="Profit Target", inline='4', tooltip='Sell only if position is on profit, unless Stop Loss active')// Risk Managementstop_loss = input.float(3.00, title="Stop Loss %", inline='5', step=0.05, group="Risk Management")-isStopLoss = input(true, 'Implement Stop Loss?', inline='5', group="Risk Management", tooltip='Activate Stop Loss')+isStopLoss = input.bool(true, 'Implement Stop Loss?', inline='5', group="Risk Management", tooltip='Activate Stop Loss')stop_perc = input.float(6.00, title="Trailing %", step=0.125, inline='6', group="Risk Management") * 0.01-trailing = input(false, title="Implement trailing stop?",inline='6', group="Risk Management")+trailing = input.bool(false, title="Implement trailing stop?",inline='6', group="Risk Management")// Position Management⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © JCGMarkets -//@version=5+//@version=6strategy("B.Bands | Augmented | Intra-range | Long-Only", shorttitle = "BB|A|IR|L", initial_capital=1000, commission_value=0.075, slippage = 0, overlay = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 41 ms | Yes 1,000 bars in 95 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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.
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/// © JCGMarkets //@version=5strategy("B.Bands | Augmented | Intra-range | Long-Only", shorttitle = "BB|A|IR|L", initial_capital=1000, commission_value=0.075, slippage = 0, overlay = true)// TODO stop loss plot add short// Control Panel ============================================================================================================================================================//Technical Indicators Datashow_simp = input.bool(true, title="Simple Bollinger Bands ", inline='1', group="Strategy System")show_augm = input.bool(false, title="Augmented Bollinger Bands", inline='1', group="Strategy System",tooltip='Select Bollinger Band Indicator to trade Simple or Augmented') periods = input.int(20, title="Periods", minval = 2, step = 1,inline='2', group="Technical Inputs")std = input.float(2, title="Std", minval=0.1 , step = 0.1, group="Technical Inputs",inline='2', tooltip='Technical inputs for indicator calculation, Periods for MA and Standard Deviation')// Strategy dataentry_source = input(close, title="Entry source", group="Strategy Inputs", inline='3')exit_source = input(high, title="Exit source", group="Strategy Inputs", inline='3',tooltip='For entry: Activate signal if the source lies below (for Long) or above (for Short). For exit: When price reach target selected')max_spread_bb = input.float(99999.0, title="Max Spread Tolerance Beetween Bands", step=0.1, group="Strategy Inputs",tooltip='Max. Tolerance beetween lower and upper band to allow trade for range systems')// Profittake_profit = input.string("opposite", title = "Profit to band:", inline='4', options = ["middle", "opposite"], group="Profit Target")sell_profit = input(false, title="Only sell in profit", group="Profit Target", inline='4', tooltip='Sell only if position is on profit, unless Stop Loss active')// Risk Managementstop_loss = input.float(3.00, title="Stop Loss %", inline='5', step=0.05, group="Risk Management")isStopLoss = input(true, 'Implement Stop Loss?', inline='5', group="Risk Management", tooltip='Activate Stop Loss')stop_perc = input.float(6.00, title="Trailing %", step=0.125, inline='6', group="Risk Management") * 0.01trailing = input(false, title="Implement trailing stop?",inline='6', group="Risk Management")// Position ManagementriskPerc = input.float(title="% of available capital", maxval=100 , inline='7', group='Position Size', defval=5, step=0.25, tooltip='Use a % of the total capital selected for strategy')usePosSize = input.bool(title="Limit strategy capital?", defval=false, inline='7', group='Position Size', tooltip='If activated, only uses the percentage of capital selected from the properties tab. Default 1000$')// Backtest Range start = input.time(timestamp("2019-11-01T00:00:00"),inline='9', title="Starting Date",group="BACKTEST RANGE" )end = input.time(timestamp("2023-12-12T00:00:00"), inline='9',title="Ending Date",group="BACKTEST RANGE",tooltip='Select the range for backtest and live strategy')// Helper Functions ============================================================================================================================================================// Date ConditionIn_date() => from_date = time >= start to_date = time <= end from_date and to_dateposition = usePosSize ? math.round((strategy.equity * (riskPerc / 100) / close) , 6) : math.round((strategy.equity / close) , 6)in_position = strategy.position_size > 0 // Initialize variables ========================================================================================================================================================var SL = 0.0var SLT= 0.0SLT := if in_position and In_date() stop_inicial = entry_source * (1 - stop_perc) math.max(stop_inicial, SLT[1])else 0slts = (low <= SLT) and (trailing == true)//Simple BB Calculation -> adapt if needed with different std for upper-lower, sma-ema, etc middle_sim = ta.sma(close, periods)//Augmented BB Calculation -> adapt if needed with different std for upper lower, etcmiddle_augm = ta.ema(close, periods)middle_upp = ta.ema(high, periods)middle_low = ta.ema(low, periods)//Multiplierdev = ta.stdev(close, periods) * std//Upper & Lower Bandsupper = (middle_sim + dev)lower = (middle_sim - dev)//Augmented Bandsupper_augm = (middle_upp + dev)lower_augm = (middle_low - dev)//Bands Spreadspread = upper - lowerspread_augm = upper_augm - lower_augm//Trading Conditions entry_long = (entry_source <= lower) and (spread < max_spread_bb)entry_long_augm = (entry_source <= lower_augm) and (spread_augm < max_spread_bb)// Simple Bollingerif (not in_position and show_simp and In_date()) if entry_long // Trigger buy order strategy.entry("Entry", strategy.long, qty = position ) SL := close * (1 - (stop_loss / 100)) // You could determine wether or not implement stop loss with bool input and if condition here.if in_position and show_simp and not sell_profit and In_date() //Exits if not sell in profit if take_profit == "middle" strategy.exit("Target", "Entry", limit = middle_sim, stop = isStopLoss ? SL: na, comment="Exit") if take_profit == "opposite" strategy.exit("Target", "Entry", limit = upper, stop = isStopLoss ? SL :na , comment="Exit") if in_position and show_simp and sell_profit and In_date() //Exits if sell in profit if take_profit == "middle" strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? middle_sim: na), stop = isStopLoss ? SL: na, comment="Exit") if take_profit == "opposite" strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? upper: na), stop = isStopLoss ? SL : na, comment="Exit") if in_position and show_simp and slts and In_date() //Trailing activation strategy.close("Entry", comment="SLT")if not In_date() //Exit due out of date range strategy.close("Entry", comment="Out of date range")// Augmented Bollinger Conditionsif (not in_position and show_augm and In_date()) if entry_long_augm // Trigger buy order strategy.entry("Entry_A", strategy.long, qty = position ) SL := close * (1 - (stop_loss / 100) )if in_position and show_augm and not sell_profit and In_date() //Exits and not sell in profit if take_profit == "middle" strategy.exit("Target", "Entry_A", limit = middle_augm, stop = isStopLoss ? SL : na, comment="Exit") if take_profit == "opposite" strategy.exit("Target", "Entry_A", limit = upper_augm, stop = isStopLoss ? SL : na, comment="Exit") if in_position and show_augm and sell_profit and In_date() //Exit only in profit if take_profit == "middle" strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? middle_augm:na), stop = isStopLoss ? SL : na, comment="Exit") if take_profit == "opposite" strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? upper_augm: na) , stop = isStopLoss ? SL : na, comment="Exit") if in_position and show_augm and slts and In_date() //Trigger trailing strategy.close("Entry_A", comment="SLT") if not In_date() //Out of date trigger strategy.close("Entry_A", comment= "Out of date range")// Plotting ==========================================================================================================================plot(in_position ? SL > 0 ? SL : na : na , style = plot.style_circles, color = color.red, title = "Stop Loss")plot(in_position ? trailing ? SLT > 0 ? SLT : na : na : na , style = plot.style_circles, color = color.blue, title = "Trailing Stop" )s = plot(show_simp ? upper : na , color = color.aqua, title='Simple Upper Bollinger Band')plot(show_simp ? middle_sim : na , color=color.red, title='Simple Moving Average')i = plot(show_simp ? lower : na , color = color.aqua, title='Simple Lower Bollinger Band')fill(s,i, color=color.new(color.aqua,90))plot(show_augm ? middle_augm : na , color=color.blue, title='Augmented Moving Average')s_a = plot( show_augm ? upper_augm : na, color=color.orange, title='Augmented Upper Bollinger Band')i_a = plot( show_augm ? lower_augm : na, color= color.orange, title='Simple Lower Bollinger Band')fill(s_a,i_a, color=color.new(color.orange, 90))