Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Rudy's BB with Martingale

A Pine Script v5 strategy built on EMA (close, 200) and BB (close, 20). It has 2 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 is one contract and pays no commission. 1 setting; defaults include Base Contract Size 0.01.

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 Rudy's BB with Martingale repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Rudy's BB with Martingale do on BTCUSDT 1D with default settings?
+0.01%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Rudy's BB with Martingale run in Pine Script v6?
Yes
Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does Rudy's BB with Martingale use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Rudy's BB with Martingale run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • MA200
  • Middle BB
  • Upper BB
  • Lower BB
  • Current profit
  • Amount of last negative profits
  • 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 (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,000,120$2,025,273Equity from $1,000,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.01%
$115.72
Buy and hold
+102.5%
same period
Closed trades
12
7 won · 5 lost
Profitable
58.3%
of closed trades
Profit factor
1.28
gross profit ÷ gross loss
Max drawdown
0.05%
−$530.55

One run with the author's default settings, $1,000,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 stop loss

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

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

Settings

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

SettingDefaultType and rangeFeeds
Base Contract Size0.01floatamount_buy

What it calculates

  • EMAclose, 200ma200 · line 17
  • BBclose, 20, 2middle · line 18
  • BBclose, 20, 2upper · line 18
  • BBclose, 20, 2lower · line 18

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 database_contract_sizeBase Contract Sizesetting · 0.01ma200EMA→ ma200middleBB→ middleupperBB→ upperlowerBB→ loweriivalueamount_buyamount_buyvalueentry:bb buyOpen bb buystrategy.entryclose:bb buyClose bb buystrategy.closeplot:19MA200plotplot:20Middle BBplotplot:21Upper BBplotplot:22Lower BBplotplotchar:27plotcharplotcharplotchar:28plotcharplotchar

Order rules

OrderFires whenBy defaultLine
Open bb buy longclose < lowerOn24
Close bb buyclose>=upperOn25

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, and the live replay matched history.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 1D+0.0%+102.5%1258%1.280.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.0%+5.5%1242%1.610.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.0%+9.8%944%0.640.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%1377%1.150.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%1070%0.760.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1267%1.220.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%967%1.540.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%1275%1.660.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market475%$200.06
Sideways market650%−$113.44
Falling market250%$29.11

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

0.0%

The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.

0%1%
All 12 trades
SideEntryExitBarsP&L
long14 Apr 2024 63,924.5016 May 2024 66,206.5032$22.82
long15 Jun 2024 66,044.0016 Jul 2024 64,724.1031−$13.20
long3 Aug 2024 61,498.3024 Aug 2024 64,037.2021$25.39
long7 Sep 2024 53,963.0020 Sep 2024 62,948.0013$89.85
long5 Feb 2025 97,763.1023 Apr 2025 93,443.0077−$43.20
long6 Jun 2025 101,509.0011 Jul 2025 116,010.0035$145.01
long1 Aug 2025 115,764.0014 Aug 2025 123,306.0013$75.42
long26 Aug 2025 110,112.0012 Sep 2025 115,483.0017$53.71
long26 Sep 2025 108,994.003 Oct 2025 120,529.007$115.35
long5 Nov 2025 101,497.003 Jan 2026 89,995.1059−$115.02
long1 Feb 2026 78,741.105 Mar 2026 72,666.8032−$60.74
long23 May 2026 75,539.5022 Jul 2026 66,556.1060−$179.67

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
Rudy's BB with Martingale this page—v5 strategy+0.0%120.1%
BT-Bollinger Bands - Trend Following by Credsonbbb emav5 strategy+3.9%165.6%
Strategy Oil Z Score by jroche1973bb emav4 strategyNo trades on this market
Bollinger Bands Modified (Stormer) by AugustoErnibb emav5 strategy−7.8%298.0%
Strategy- Combo Z Score by jroche1973bb emav4 strategyNo trades on this market
Korea premium(KIMP) by roses27ema bbv4 strategydoes not run in Zeal Terminal

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.

  • 2 strategy calls use the when = argument (line 24, 25). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 24: when = close < lower → if block
  • Line 25: when = close>=upper → if block
⋯amount_buy = lastTradeProfit() < 0 ? base_contract_size * amountOfLastNegativeProfits() : 0.01-strategy.entry("bb buy", strategy.long, amount_buy, when=close < lower)+if close < lower+    strategy.entry("bb buy", strategy.long, amount_buy)-strategy.close("bb buy", when=close>=upper)+if close>=upper+    strategy.close("bb buy")    ⋯

Does it run in Pine Script v6?

Yes

Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © rudolfcicko2011-//@version=5+//@version=6strategy("Rudy BB with Martingala", overlay=true, margin_long=100, margin_short=100)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msYes 1,000 bars in 32 msNot measured
PineTSNot testedNot testedNot 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/// © rudolfcicko2011//@version=5strategy("Rudy BB with Martingala", overlay=true, margin_long=100, margin_short=100)base_contract_size= input.float(0.01, 'Base Contract Size')lastTradeProfit() =>    strategy.closedtrades.profit(strategy.closedtrades-1) + strategy.closedtrades.commission(strategy.closedtrades-1)    amountOfLastNegativeProfits() =>    result = 0    i = strategy.closedtrades - 1    while strategy.closedtrades.profit(i) < 0        result+=1        i-=1    result    ma200 = ta.ema(close, 200)[middle, upper, lower] = ta.bb(close, 20, 2)plot(ma200, "MA200", color=color.green)plot(middle, "Middle BB", color=color.purple)plot(upper, "Upper BB", color=color.purple)plot(lower, "Lower BB", color=color.purple)amount_buy = lastTradeProfit() < 0 ? base_contract_size * amountOfLastNegativeProfits() : 0.01strategy.entry("bb buy", strategy.long, amount_buy, when=close < lower)strategy.close("bb buy", when=close>=upper)    plotchar(strategy.openprofit, "Current profit", "", location = location.top)plotchar(amountOfLastNegativeProfits(), "Amount of last negative profits", "", location = location.top)