Pine Script v4 · Strategy
Binomial Strategy
A Pine Script v4 strategy built on EMA (cdf, 10). 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 commits 100% of equity and pays no commission. It has no settings.
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 Binomial Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Binomial Strategy do on BTCUSDT 1D with default settings?
- +5.32%
- From 26 Jan 2024 to 21 Oct 2026, over 27 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Binomial Strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does Binomial Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Binomial Strategy run in Zeal Terminal?
- Yes
- It compiles in 10 ms and runs 1,000 bars in 370 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +5.32%
- $531.53
- Buy and hold
- +102.5%
- same period
- Closed trades
- 27
- 11 won · 16 lost
- Profitable
- 40.7%
- of closed trades
- Profit factor
- 1.08
- gross profit ÷ gross loss
- Max drawdown
- 30.73%
- −$3,208.57
One run with the author's default settings, $10,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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
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 pow → math.pow, sum → math.sum, ema → ta.ema.
Same 27 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 14: pow → math.pow
- Line 14: pow → math.pow
- Line 26: sum → math.sum
- Line 30: sum → math.sum
- Line 33: ema → ta.ema
- Line 34: ema → ta.ema
⋯// © pieroliviermarquis-//@version=4+//@version=5strategy("Binomial Strategy", overlay=false, default_qty_type= strategy.percent_of_equity, default_qty_value= 100, slippage=1, initial_capital= 10000, calc_on_every_tick=true)⋯ coef = factorial(trials) / (factorial(trials-success) * factorial(success))- pdf = coef * pow(p, success) * pow(q, trials-success)+ pdf = coef * math.pow(p, success) * math.pow(q, trials-success) ⋯lt_lookback = 100-lt_up_bars = sum(up, lt_lookback)+lt_up_bars = math.sum(up, lt_lookback)prob = lt_up_bars/lt_lookback⋯lookback = 20-up_bars = sum(up, lookback)+up_bars = math.sum(up, lookback)cdf = binomial_cdf(up_bars, lookback, prob)//ema on cdf-ema1 = ema(cdf, 10)+ema1 = ta.ema(cdf, 10)-ema2 = ema(cdf, 20)+ema2 = ta.ema(cdf, 20)plot(cdf*100)⋯Clean v5
VerifiedNothing to change.
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: 27 before, 20 after on BTCUSDT 1D, 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.
⋯// © pieroliviermarquis-//@version=5+//@version=6strategy("Binomial Strategy", overlay=false, default_qty_type= strategy.percent_of_equity, default_qty_value= 100, slippage=1, initial_capital= 10000, calc_on_every_tick=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
The script declares no settings.
What it calculates
- EMA (
ema,ta.emain v5)cdf, 10ema1 · line 33 - EMA (
ema,ta.emain v5)cdf, 20ema2 · line 34
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 Long long | buy | On | 50 |
| Close Long | sell | On | 52 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- 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 | +5.3% | +102.5% | 27 | 41% | 1.08 | 30.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +22.9% | +5.5% | 27 | 37% | 1.93 | 8.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −56.8% | +9.8% | 27 | 22% | 0.45 | 70.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +31.3% | +8.4% | 23 | 48% | 2.23 | 9.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −29.8% | +16.7% | 22 | 41% | 0.73 | 56.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −2.1% | +21.5% | 20 | 35% | 0.95 | 18.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −7.9% | +148.3% | 26 | 38% | 0.89 | 45.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.4% | +17.1% | 26 | 42% | 1.06 | 15.9% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 8 | 38% | $365.96 |
| Sideways market | 11 | 36% | −$698.28 |
| Falling market | 8 | 50% | $863.85 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
41.5%
The 95th percentile of the worst drawdown when the same 27 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 20.2% to 41.5%; the tick is what actually happened, 28.2%. Order luck alone moves it this much.
All 27 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 May 2024 67,969.70 | 2 Jun 2024 67,766.80 | 9 | −$29.84 |
| long | 12 Jun 2024 67,314.20 | 22 Jun 2024 64,143.60 | 10 | −$469.62 |
| long | 5 Jul 2024 57,050.00 | 6 Jul 2024 56,628.80 | 1 | −$70.15 |
| long | 10 Jul 2024 58,050.00 | 5 Aug 2024 58,161.00 | 26 | $18.03 |
| long | 23 Aug 2024 60,375.80 | 7 Sep 2024 53,963.00 | 15 | −$1,003.57 |
| long | 11 Sep 2024 57,636.00 | 16 Sep 2024 59,132.00 | 5 | $219.19 |
| long | 19 Sep 2024 61,760.00 | 10 Oct 2024 60,636.00 | 21 | −$157.68 |
| long | 29 Oct 2024 69,962.20 | 6 Nov 2024 69,372.00 | 8 | −$71.76 |
| long | 11 Nov 2024 80,370.00 | 18 Nov 2024 89,856.00 | 7 | $995.52 |
| long | 22 Nov 2024 98,317.10 | 2 Dec 2024 97,185.20 | 10 | −$108.57 |
| long | 9 Dec 2024 101,110.00 | 11 Dec 2024 96,593.00 | 2 | −$416.40 |
| long | 7 Jan 2025 102,236.00 | 26 Jan 2025 104,747.00 | 19 | $218.74 |
| long | 27 Feb 2025 84,250.10 | 9 Apr 2025 76,322.40 | 41 | −$858.53 |
| long | 12 Apr 2025 83,423.80 | 14 May 2025 104,104.00 | 32 | $2,048.89 |
| long | 10 Jun 2025 110,263.00 | 14 Jun 2025 106,067.00 | 4 | −$392.55 |
| long | 11 Jul 2025 116,010.00 | 26 Jul 2025 117,614.00 | 15 | $137.21 |
| long | 21 Aug 2025 114,271.00 | 2 Oct 2025 118,595.00 | 42 | $380.60 |
| long | 4 Oct 2025 122,232.00 | 24 Oct 2025 110,078.00 | 20 | −$1,038.04 |
| long | 8 Nov 2025 103,339.00 | 9 Nov 2025 102,313.00 | 1 | −$93.36 |
| long | 11 Dec 2025 92,015.40 | 19 Dec 2025 85,516.40 | 8 | −$657.43 |
| long | 21 Dec 2025 88,360.90 | 21 Jan 2026 88,427.60 | 31 | $6.53 |
| long | 5 Mar 2026 72,666.80 | 9 Mar 2026 65,971.20 | 4 | −$797.68 |
| long | 12 Mar 2026 70,191.90 | 3 Apr 2026 66,902.00 | 22 | −$368.38 |
| long | 12 Apr 2026 73,043.20 | 14 May 2026 79,313.60 | 32 | $643.08 |
| long | 24 Jun 2026 62,734.60 | 27 Jul 2026 65,400.00 | 33 | $345.60 |
| long | 2 Aug 2026 62,823.70 | 10 Sep 2026 78,306.40 | 39 | $2,089.84 |
| long | 1 Oct 2026 83,623.60 | 8 Oct 2026 83,321.80 | 7 | −$38.15 |
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 |
|---|---|---|---|---|---|
| Binomial Strategy this page | — | v4 strategy | +5.3% | 27 | 30.7% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 10 ms | Yes 1,000 bars in 370 ms | Not measured |
| PineTS | No 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © pieroliviermarquis//@version=4strategy("Binomial Strategy", overlay=false, default_qty_type= strategy.percent_of_equity, default_qty_value= 100, slippage=1, initial_capital= 10000, calc_on_every_tick=true)factorial(length) => n = 1 if length != 0 for i = 1 to length n := n * i nbinomial_pdf(success, trials, p) => q = 1-p coef = factorial(trials) / (factorial(trials-success) * factorial(success)) pdf = coef * pow(p, success) * pow(q, trials-success) binomial_cdf(success, trials, p) => q = 1-p cdf = 0.0 for i = 0 to success cdf := cdf + binomial_pdf(i, trials, p) up = close[0] > close[1] ? 1 : 0//long-term probabilitieslt_lookback = 100lt_up_bars = sum(up, lt_lookback)prob = lt_up_bars/lt_lookback//lookback for cdflookback = 20up_bars = sum(up, lookback)cdf = binomial_cdf(up_bars, lookback, prob)//ema on cdfema1 = ema(cdf, 10)ema2 = ema(cdf, 20)plot(cdf*100)plot(ema1*100, color=color.red)plot(ema2*100, color=color.orange)buy = ema1 > ema2sell = ema1 < ema2//////////////////////Bar Colors//////////////////var color buy_or_sell = naif buy == true buy_or_sell := #3BB3E4else if sell == true buy_or_sell := #FF006E barcolor(buy_or_sell)///////////////////////////Orders////////////////if buy strategy.entry("Long", strategy.long, comment="")if sell strategy.close("Long", comment="Sell")