Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (0)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$10,531$20,253Equity from $10,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
+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.

v4 → v5

VerifiedDownload the v5 script

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

Verified

Nothing 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.ema in v5)cdf, 10ema1 · line 33
  • EMA (ema, ta.ema in 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.

closecloseprice dataema1EMA→ ema1ema2EMA→ ema2nnvalueq, coefq · coef2 valuespdfpdfvaluecdfcdfvalueupupvaluelt_up_bars, up_barslt_up_bars · up_bars2 valuesprobprobvaluebuybuyconditionsellsellconditionbuy_or_sellColourbuy_or_sellentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:35plotplotplot:36plotplotplot:37plotplotbarcolor:47barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open Long longbuyOn50
Close LongsellOn52

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.

6/6trades 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. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+5.3%+102.5%2741%1.0830.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+22.9%+5.5%2737%1.938.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−56.8%+9.8%2722%0.4570.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+31.3%+8.4%2348%2.239.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−29.8%+16.7%2241%0.7356.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−2.1%+21.5%2035%0.9518.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−7.9%+148.3%2638%0.8945.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.4%+17.1%2642%1.0615.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 barsTradesWonP&L
Rising market838%$365.96
Sideways market1136%−$698.28
Falling market850%$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.

0%48%
All 27 trades
SideEntryExitBarsP&L
long24 May 2024 67,969.702 Jun 2024 67,766.809−$29.84
long12 Jun 2024 67,314.2022 Jun 2024 64,143.6010−$469.62
long5 Jul 2024 57,050.006 Jul 2024 56,628.801−$70.15
long10 Jul 2024 58,050.005 Aug 2024 58,161.0026$18.03
long23 Aug 2024 60,375.807 Sep 2024 53,963.0015−$1,003.57
long11 Sep 2024 57,636.0016 Sep 2024 59,132.005$219.19
long19 Sep 2024 61,760.0010 Oct 2024 60,636.0021−$157.68
long29 Oct 2024 69,962.206 Nov 2024 69,372.008−$71.76
long11 Nov 2024 80,370.0018 Nov 2024 89,856.007$995.52
long22 Nov 2024 98,317.102 Dec 2024 97,185.2010−$108.57
long9 Dec 2024 101,110.0011 Dec 2024 96,593.002−$416.40
long7 Jan 2025 102,236.0026 Jan 2025 104,747.0019$218.74
long27 Feb 2025 84,250.109 Apr 2025 76,322.4041−$858.53
long12 Apr 2025 83,423.8014 May 2025 104,104.0032$2,048.89
long10 Jun 2025 110,263.0014 Jun 2025 106,067.004−$392.55
long11 Jul 2025 116,010.0026 Jul 2025 117,614.0015$137.21
long21 Aug 2025 114,271.002 Oct 2025 118,595.0042$380.60
long4 Oct 2025 122,232.0024 Oct 2025 110,078.0020−$1,038.04
long8 Nov 2025 103,339.009 Nov 2025 102,313.001−$93.36
long11 Dec 2025 92,015.4019 Dec 2025 85,516.408−$657.43
long21 Dec 2025 88,360.9021 Jan 2026 88,427.6031$6.53
long5 Mar 2026 72,666.809 Mar 2026 65,971.204−$797.68
long12 Mar 2026 70,191.903 Apr 2026 66,902.0022−$368.38
long12 Apr 2026 73,043.2014 May 2026 79,313.6032$643.08
long24 Jun 2026 62,734.6027 Jul 2026 65,400.0033$345.60
long2 Aug 2026 62,823.7010 Sep 2026 78,306.4039$2,089.84
long1 Oct 2026 83,623.608 Oct 2026 83,321.807−$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.

ScriptSharesTypeNetTradesMax drawdown
Binomial Strategy this page—v4 strategy+5.3%2730.7%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 10 msYes 1,000 bars in 370 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.

// 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")