Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

3Commas Bollinger Strategy

A Pine Script v4 strategy built on SMA (close, 20), Stdev (close, 20) and Crossover or Crossunder (close, lowerBand). It has 5 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 1000 in cash and pays 0.1 commission. 22 settings; defaults include Simple bot composite, Base order size 500 and Safety order size 1000.

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 3Commas Bollinger Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did 3Commas Bollinger Strategy 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.
Can 3Commas Bollinger Strategy be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does 3Commas Bollinger Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does 3Commas Bollinger Strategy run in Zeal Terminal?
Yes
It compiles in 35 ms and runs 1,000 bars in 51 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (22)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$5,000$10,126Equity from $5,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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, $5,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.

  • Likely bug

    The “over” option calculates CROSSOVER line 46

    Choosing over in “Entrry at Cross Over/Under Lower” runs ta.crossover, not ta.over. Anyone picking over gets a different average from the one they asked for.

    cross == 'over' ? ta.crossover(cross == 'over' ? ta.over(
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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 75, 77. The upgraded version below moves each call inside an if block.

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 sma → ta.sma, stdev → ta.stdev, crossover → ta.crossover, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 75, 77). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 1: //@version=4 → //@version=5
  • Line 35: sma → ta.sma
  • Line 36: sma → ta.sma
  • Line 37: stdev → ta.stdev
  • Line 46: crossover → ta.crossover
  • Line 46: crossunder → ta.crossunder
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯// VARS-short_sma        = sma(close, sma_short_val)+short_sma        = ta.sma(close, sma_short_val)-long_sma         = sma(close, sma_long_val)+long_sma         = ta.sma(close, sma_long_val)-stdDev           = stdev(close, sma_short_val)+stdDev           = ta.stdev(close, sma_short_val)upperBand        = short_sma + (stdDev * ubOffset)⋯// Market Conditions-goodBuy    = cross=="over"?crossover(close, lowerBand):crossunder(close, lowerBand) // Buy when close crossing lower band+goodBuy    = cross=="over"?ta.crossover(close, lowerBand):ta.crossunder(close, lowerBand) // Buy when close crossing lower bandsafety     = initial_deviation and (1-(close/strategy.position_avg_price))/.01 > strategy.opentrades-1 * safety_step and strategy.opentrades <= safety_max // SO when price deviates below SO threshold %⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 10: input() → input.string()
  • Line 11: input() → input.string()
  • Line 12: input() → input.string()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.float()
18 more edits
  • Line 16: input() → input.float()
  • Line 17: input() → input.int()
  • Line 18: input() → input.float()
  • Line 19: input() → input.int()
  • Line 20: input() → input.float()
  • Line 22: input() → input.int()
  • Line 23: input() → input.int()
  • Line 24: input() → input.float()
  • Line 25: input() → input.float()
  • Line 26: input() → input.string()
  • Line 28: input() → input.int()
  • Line 29: input() → input.int()
  • Line 30: input() → input.int()
  • Line 31: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 75: when = strategy.opentrades <= 0 → if block
  • Line 77: when = strategy.opentrades > 0 → if block
⋯// 3Commas Bot settinsg-bot_type                = input(title="Simple bot", defval="composite", options=["simple", "composite"])+bot_type                = input.string(title="Simple bot", defval="composite", options=["simple", "composite"])-bot_id                  = input(title="3Commas Bot ID", defval="")+bot_id                  = input.string(title="3Commas Bot ID", defval="")-email_token             = input(title="Bot Email Token", defval="")+email_token             = input.string(title="Bot Email Token", defval="")-base_order_size         = input(title="Base order size",minval=10, step=1, defval=500)+base_order_size         = input.int(title="Base order size",minval=10, step=1, defval=500)-safety_order_size       = input(title="Safety order size", minval=15, step=1, defval=1000)+safety_order_size       = input.int(title="Safety order size", minval=15, step=1, defval=1000)-volume_scale            = input(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)+volume_scale            = input.float(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)-safety_step             = input(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)+safety_step             = input.float(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)-safety_max              = input(title="Max Number of Safety Orders", minval=0, step=1, defval=4)+safety_max              = input.int(title="Max Number of Safety Orders", minval=0, step=1, defval=4)-initial_deviation_input = input(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=0.8) * 0.01+initial_deviation_input = input.float(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=0.8) * 0.01-stoploss_input          = input(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01+stoploss_input          = input.int(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01-takeprofit_input        = input(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01+takeprofit_input        = input.float(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01// USER INPUTS-sma_short_val           = input(title="Short MA Window", defval=20)+sma_short_val           = input.int(title="Short MA Window", defval=20)-sma_long_val            = input(title="Long MA Window", defval=100)+sma_long_val            = input.int(title="Long MA Window", defval=100)-ubOffset                = input(title="Upper Band Offset", defval=2.5, step=0.5)+ubOffset                = input.float(title="Upper Band Offset", defval=2.5, step=0.5)-lbOffset                = input(title="Lower Band Offset", defval=2.5, step=0.5)+lbOffset                = input.float(title="Lower Band Offset", defval=2.5, step=0.5)-cross                   = input(title="Entrry at Cross Over/Under Lower", defval="over", options=["over", "under"])+cross                   = input.string(title="Entrry at Cross Over/Under Lower", defval="over", options=["over", "under"])// Backtesting Date Ranges-startDate  = input(title="Start Date", defval=1, minval=1, maxval=31)+startDate  = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear  = input(title="Start Year", defval=2016, minval=1800, maxval=2100)+startYear  = input.int(title="Start Year", defval=2016, minval=1800, maxval=2100)-endDate    = input(title="End Date", defval=31, minval=1, maxval=31)+endDate    = input.int(title="End Date", defval=31, minval=1, maxval=31)-endMonth   = input(title="End Month", defval=12, minval=1, maxval=12)+endMonth   = input.int(title="End Month", defval=12, minval=1, maxval=12)-endYear    = input(title="End Year", defval=2022, minval=1800, maxval=2100)+endYear    = input.int(title="End Year", defval=2022, minval=1800, maxval=2100)// VARS⋯if inDateRange and goodBuy-    strategy.entry("Good Buy", strategy.long, base_order_size, when = strategy.opentrades <= 0, alert_message=enter_msg)+    if strategy.opentrades <= 0+        strategy.entry("Good Buy", strategy.long, base_order_size, alert_message=enter_msg)if inDateRange and safety-    strategy.order("Good Buy", strategy.long, actual_safety_size, when = strategy.opentrades > 0, comment = "safety order")+    if strategy.opentrades > 0+        strategy.order("Good Buy", strategy.long, actual_safety_size, comment = "safety order")if inDateRange and goodSell⋯

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.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Simple botcompositestring · options ["simple", "composite"]line 64
3Commas Bot IDstringenter_msg exit_msg close_all line 63
Bot Email Tokenstringenter_msg exit_msg close_all line 63
Base order size500int · min 10 · step 1actual_safety_size entry Good Buy
Safety order size1000int · min 15 · step 1actual_safety_size
Safety Order Vol Scale (%)1.83float · min 0.00 · step 0.01actual_safety_size
Safety Order Step Scale (%)1.55float · min 0.00 · step 0.1safety
Max Number of Safety Orders4int · min 0 · step 1safety
Initial SO Deviation (%)0.8float · min 0 · step 0.01initial_dev_val
Long Stop Loss (%)15int · min 0 · step 1stoploss_value
Long Take Profit (%)1.4float · min 0 · step 1takeprofit_value
Short MA Window20intshort_sma stdDev
Long MA Window100intlong_sma
Upper Band Offset2.5float · step 0.5upperBand
Lower Band Offset2.5float · step 0.5lowerBand
Entrry at Cross Over/Under Loweroverstring · options ["over", "under"]goodBuy
Start Date1int · min 1 · max 31inDateRange
Start Month1int · min 1 · max 12inDateRange
Start Year2016int · min 1800 · max 2100inDateRange
End Date31int · min 1 · max 31inDateRange
End Month12int · min 1 · max 12inDateRange
End Year2022int · min 1800 · max 2100inDateRange

What it calculates

  • SMA (sma, ta.sma in v5)close, Short MA Window (20)short_sma · line 35
  • SMA (sma, ta.sma in v5)close, Long MA Window (100)long_sma · line 36
  • Stdev (stdev, ta.stdev in v5)close, Short MA Window (20)stdDev · line 37
  • Crossover / Crossunder (crossover, ta.crossover in v5)close, lowerBand · chosen by Entrry at Cross Over/Under LowergoodBuy · line 46

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.

closecloseprice datasma_short_valShort MA Windowsetting · 20sma_long_valLong MA Windowsetting · 100crossEntrry at Cross Over/Un…setting · overubOffsetUpper Band Offsetsetting · 2.5lbOffsetLower Band Offsetsetting · 2.5stoploss_inputLong Stop Loss (%)setting · 15takeprofit_inputLong Take Profit (%)setting · 1.4initial_deviation_inputInitial SO Deviation (%)setting · 0.8safety_order_sizeSafety order sizesetting · 1000base_order_sizeBase order sizesetting · 500volume_scaleSafety Order Vol Scale …setting · 1.83timetimeprice datastartYearStart Yearsetting · 2016startMonthStart Monthsetting · 1startDateStart Datesetting · 1endYearEnd Yearsetting · 2022endMonthEnd Monthsetting · 12endDateEnd Datesetting · 31safety_stepSafety Order Step Scale…setting · 1.55safety_maxMax Number of Safety Or…setting · 4short_smaSMA→ short_smalong_smaSMA→ long_smastdDevStdev→ stdDevgoodBuyCrossover / Crossunder→ goodBuy · by Entrry at Cros…upperBandupperBandvaluelowerBandlowerBandvaluestoploss_valuestoploss_valuevaluetakeprofit_valuetakeprofit_valuevalueinitial_dev_valinitial_dev_valvalueactual_safety_sizeactual_safety_sizevalueinDateRangeinDateRangeconditionsafetysafetyconditionstoplossstoplossconditiontakeprofittakeprofitconditioninitial_deviationinitial_deviationconditionentry:Good BuyOpen Good Buystrategy.entryorder:Good Buyorder Good Buystrategy.orderclose_all:close_all strategy.close_allplot:55plotplotplot:56plotplotplot:57plotplotplot:58plotplot

Order rules

OrderFires whenBy defaultLine
Open Good Buy longstrategy.opentrades <= 0On75
order Good Buy longstrategy.opentrades > 0On77
Close inDateRange and goodSellOn79
Close inDateRange and stoplossOn81
Close inDateRange and takeprofitOn83

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

ScriptSharesTypeNetTradesMax drawdown
3Commas Bollinger Strategy this page—v4 strategy0.0%00.0%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 35 msYes 1,000 bars in 51 msNot measured
PineTSNo v5 and v6 only—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. 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.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © tedwardd// This strategy is intended to help users of the 3commas.io platform backtest bot performance based on a Bollinger Strategy.// It can also be used to signal a bot to open a deal by providing the Bot ID, email token and trading pair in the strategy settings screen.// As currently written, this strategy uses a basic Bollinger Band strategy, recommening a deal start when the closing price crosses under the lower band.// The thick red line plotted on the chart shows the average entry price of the current deal.strategy("3Commas Bollinger Strategy", overlay=true, default_qty_type=strategy.cash, default_qty_value=1000, initial_capital=5000, currency="USD", commission_value=0.1)// 3Commas Bot settinsgbot_type                = input(title="Simple bot", defval="composite", options=["simple", "composite"])bot_id                  = input(title="3Commas Bot ID", defval="")email_token             = input(title="Bot Email Token", defval="")base_order_size         = input(title="Base order size",minval=10, step=1, defval=500)safety_order_size       = input(title="Safety order size", minval=15, step=1, defval=1000)volume_scale            = input(title="Safety Order Vol Scale (%)", minval=0.00, step=0.01, defval=1.83)safety_step             = input(title="Safety Order Step Scale (%)", minval=0.00, step=0.1, defval=1.55)safety_max              = input(title="Max Number of Safety Orders", minval=0, step=1, defval=4)initial_deviation_input = input(title="Initial SO Deviation (%)", minval=0, step=0.01, defval=0.8) * 0.01stoploss_input          = input(title="Long Stop Loss (%)", minval=0, step=1, defval=15) * 0.01takeprofit_input        = input(title="Long Take Profit (%)", minval=0, step=1, defval=1.4) * 0.01// USER INPUTSsma_short_val           = input(title="Short MA Window", defval=20)sma_long_val            = input(title="Long MA Window", defval=100)ubOffset                = input(title="Upper Band Offset", defval=2.5, step=0.5)lbOffset                = input(title="Lower Band Offset", defval=2.5, step=0.5)cross                   = input(title="Entrry at Cross Over/Under Lower", defval="over", options=["over", "under"])// Backtesting Date RangesstartDate  = input(title="Start Date", defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)startYear  = input(title="Start Year", defval=2016, minval=1800, maxval=2100)endDate    = input(title="End Date", defval=31, minval=1, maxval=31)endMonth   = input(title="End Month", defval=12, minval=1, maxval=12)endYear    = input(title="End Year", defval=2022, minval=1800, maxval=2100)// VARSshort_sma        = sma(close, sma_short_val)long_sma         = sma(close, sma_long_val)stdDev           = stdev(close, sma_short_val)upperBand        = short_sma + (stdDev * ubOffset)lowerBand        = short_sma - (stdDev * lbOffset)stoploss_value   = strategy.position_avg_price * (1 - stoploss_input)takeprofit_value = strategy.position_avg_price * (1 + takeprofit_input)initial_dev_val  = strategy.position_avg_price * (1 - initial_deviation_input)inDateRange      = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))initial_deviation = close < initial_dev_val// Market ConditionsgoodBuy    = cross=="over"?crossover(close, lowerBand):crossunder(close, lowerBand) // Buy when close crossing lower bandsafety     = initial_deviation and (1-(close/strategy.position_avg_price))/.01 > strategy.opentrades-1 * safety_step and strategy.opentrades <= safety_max // SO when price deviates below SO threshold %stoploss   = close <= stoploss_value // Stoploss condition - true if closing price for current bar drops below stoploss %takeprofit = close >= takeprofit_value // Take profit condition - true if closing price for current bar is >= take profit percentage// goodSell is currently unused for any practical purpose. If you wish to try it, switch these two values. // Doing so will make sell suggestions at high crossover upper bollinger but it does not trigger the bot to sell as written but may affect backtest results//goodSell = crossover(high, upperBand)goodSell   = false// Plot some linesplot(short_sma, color=color.green)plot(upperBand)plot(lowerBand, color=color.yellow)plot(strategy.position_avg_price, color=color.red, linewidth=3)// Webhook message. Defaults to string. To signal 3c bot, fill in bot_id and email_token in user settingsvar enter_msg = "Enter Position"var exit_msg  = "Exit Position"var close_all = "Exit Position"if bot_id != "" and email_token != ""    if bot_type == "composite"        enter_msg := '{"message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "' + email_token + '", "delay_seconds": 0, "pair": "' + syminfo.currency + "_" + syminfo.basecurrency + '"}'    else        enter_msg := '{"message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "' + email_token + '", "delay_seconds": 0}'    exit_msg  := '{  "message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": ' + email_token + ',  "delay_seconds": 0,  "action": "close_at_market_price"}'    close_all := '{ "message_type": "bot", "bot_id": ' + bot_id + ', "email_token": ' + email_token + ', "delay_seconds": 0, "action": "close_at_market_price_all"}'actual_safety_size = float(safety_order_size) // Set safety order size to starting safetyif strategy.opentrades > 2 // If we have more than two open trades we need to start scaling the safety size by the volume_scale    actual_safety_size := (strategy.position_size - base_order_size) * volume_scale // Remove base order from total position size and scale it for next safety order// Strategy Actionsif inDateRange and goodBuy    strategy.entry("Good Buy", strategy.long, base_order_size, when = strategy.opentrades <= 0, alert_message=enter_msg)if inDateRange and safety    strategy.order("Good Buy", strategy.long, actual_safety_size, when = strategy.opentrades > 0, comment = "safety order")if inDateRange and goodSell    strategy.close_all(comment="Good sell point")if inDateRange and stoploss    strategy.close_all(comment="Stoploss")if inDateRange and takeprofit    strategy.close_all(comment="TP Target")