Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Binomial Moving Average Strategy

A Pine Script v4 strategy built on Crossover (close, fa_ma, close, sl_ma) and Crossunder (close, fa_ma, close, sl_ma). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include Fast MA 10 and Slow MA 30.

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 Moving Average Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 41 of 41 trades.
How did Binomial Moving Average Strategy do on BTCUSDT 1D with default settings?
+0.81%
From 26 Jan 2024 to 21 Oct 2026, over 132 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Binomial Moving Average 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 Moving Average Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Binomial Moving Average Strategy run in Zeal Terminal?
Yes
It compiles in 18 ms and runs 1,000 bars in 6,783 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$102,491$202,527Equity from $100,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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
+0.81%
$808.94
Buy and hold
+102.5%
same period
Closed trades
132
43 won · 89 lost
Profitable
32.6%
of closed trades
Profit factor
1.00
gross profit ÷ gross loss
Max drawdown
35.65%
−$42,857.50

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.

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 crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 30: crossover → ta.crossover
  • Line 33: crossunder → ta.crossunder
⋯// © HosseinDaftary-//@version=4+//@version=5strategy("Binomial Moving Average","BMA", overlay=true, margin_long=100, margin_short=100 ,max_bars_back=96)⋯fill(hn1,hn2,color=hn_ma(close,fa_ma)>hn_ma(close,sl_ma)?color.green:color.red)-longCondition = crossover(hn_ma(close, fa_ma), hn_ma(close, sl_ma))+longCondition = ta.crossover(hn_ma(close, fa_ma), hn_ma(close, sl_ma))if (longCondition)    strategy.entry("Long", strategy.long)-shortCondition = crossunder(hn_ma(close, fa_ma), hn_ma(close, sl_ma))+shortCondition = ta.crossunder(hn_ma(close, fa_ma), hn_ma(close, sl_ma))if (shortCondition)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
⋯//we use 126/256 for last bar,84/256,36/256,9/256 and finally use 1/256 for 5th bar. Seemingly this MA works better than EMA.-fa_ma=input(title='Fast MA',defval=10)+fa_ma=input.int(title='Fast MA',defval=10)-sl_ma=input(title='Slow MA',defval=30)+sl_ma=input.int(title='Slow MA',defval=30)fac(n)=>⋯

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: 132 before, 103 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.

⋯// © HosseinDaftary-//@version=5+//@version=6strategy("Binomial Moving Average","BMA", overlay=true, margin_long=100, margin_short=100 ,max_bars_back=96)⋯

Settings

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

SettingDefaultType and rangeFeeds
Fast MA10inthn2 longCondition shortCondition plot fill
Slow MA30intcof hn1 longCondition shortCondition plot fill

What it calculates

  • Crossover (crossover, ta.crossover in v5)hn_ma(close, fa_ma), hn_ma(close, sl_ma)longCondition · line 30
  • Crossunder (crossunder, ta.crossunder in v5)hn_ma(close, fa_ma), hn_ma(close, sl_ma)shortCondition · line 33

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 datasl_maSlow MAsetting · 30fa_maFast MAsetting · 10longConditionCrossover→ longConditionshortConditionCrossunder→ shortConditionfactfactvaluecofcofvaluesumsumvaluesum1sum1valueentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryplot:27plotplotplot:28plotplotfill:29Fillfill

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition)On32
Open Short short(shortCondition)On35

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.

41/41trades 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.8%+102.5%13233%1.0035.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.3%+5.5%13136%1.0217.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.3%+9.8%13832%0.903.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.6%+8.4%14330%1.270.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.3%+16.7%12042%1.510.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%12634%1.230.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%12135%0.890.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.2%+17.1%12337%1.370.1%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 market4628%−$5,043.68
Sideways market4743%$16,094.90
Falling market3926%−$10,242.30

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

How bad could the drawdown be?

55.4%

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

0%64%
All 132 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$10,824.20
short17 Mar 2024 65,300.6026 Mar 2024 69,880.009−$4,579.36
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$4,416.01
short3 Apr 2024 65,464.008 Apr 2024 69,360.405−$3,896.39
long8 Apr 2024 69,360.4013 Apr 2024 67,116.505−$2,243.86
short13 Apr 2024 67,116.5021 Apr 2024 64,940.608$2,175.94
long21 Apr 2024 64,940.6027 Apr 2024 63,770.006−$1,170.58
short27 Apr 2024 63,770.005 May 2024 63,892.008−$122.03
long5 May 2024 63,892.009 May 2024 61,193.004−$2,699.00
short9 May 2024 61,193.0015 May 2024 61,577.506−$384.46
long15 May 2024 61,577.5027 May 2024 68,507.7012$6,930.18
short27 May 2024 68,507.7028 May 2024 69,436.401−$928.76
long28 May 2024 69,436.4029 May 2024 68,398.401−$1,038.03
short29 May 2024 68,398.404 Jun 2024 68,809.906−$411.49
long4 Jun 2024 68,809.9010 Jun 2024 69,648.106$838.26
short10 Jun 2024 69,648.101 Jul 2024 62,772.0021$6,876.14
long1 Jul 2024 62,772.004 Jul 2024 60,208.603−$2,563.44
short4 Jul 2024 60,208.6012 Jul 2024 57,339.908$2,868.68
long12 Jul 2024 57,339.9025 Jul 2024 65,376.0013$8,036.12
short25 Jul 2024 65,376.0027 Jul 2024 67,908.002−$2,531.99
long27 Jul 2024 67,908.0031 Jul 2024 66,188.004−$1,720.00
short31 Jul 2024 66,188.0010 Aug 2024 60,838.0010$5,350.01
long10 Aug 2024 60,838.0015 Aug 2024 58,683.405−$2,154.60
short15 Aug 2024 58,683.4020 Aug 2024 59,438.505−$755.11
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$23.50
short28 Aug 2024 59,415.0011 Sep 2024 57,636.0014$1,779.01
long11 Sep 2024 57,636.002 Oct 2024 60,804.9021$3,168.93
short2 Oct 2024 60,804.907 Oct 2024 62,819.905−$2,014.99
long7 Oct 2024 62,819.9010 Oct 2024 60,636.003−$2,183.90
short10 Oct 2024 60,636.0013 Oct 2024 63,206.203−$2,570.22
long13 Oct 2024 63,206.2024 Oct 2024 66,668.6011$3,462.42
short24 Oct 2024 66,668.6029 Oct 2024 69,962.205−$3,293.56
long29 Oct 2024 69,962.203 Nov 2024 69,374.705−$587.47
short3 Nov 2024 69,374.707 Nov 2024 75,572.004−$6,197.25
long7 Nov 2024 75,572.0027 Nov 2024 91,965.2020$16,393.20
short27 Nov 2024 91,965.2030 Nov 2024 97,460.003−$5,494.84
long30 Nov 2024 97,460.0011 Dec 2024 96,593.0011−$867.00
short11 Dec 2024 96,593.0012 Dec 2024 101,125.001−$4,532.00
long12 Dec 2024 101,125.0020 Dec 2024 97,461.908−$3,663.14
short20 Dec 2024 97,461.9026 Dec 2024 99,429.606−$1,967.75
long26 Dec 2024 99,429.6027 Dec 2024 95,791.601−$3,638.01
short27 Dec 2024 95,791.603 Jan 2025 96,984.807−$1,193.19
long3 Jan 2025 96,984.809 Jan 2025 95,060.606−$1,924.18
short9 Jan 2025 95,060.6015 Jan 2025 96,560.906−$1,500.24
long15 Jan 2025 96,560.9027 Jan 2025 102,620.0012$6,059.16
short27 Jan 2025 102,620.0031 Jan 2025 104,723.004−$2,102.93
long31 Jan 2025 104,723.002 Feb 2025 100,636.002−$4,087.28
short2 Feb 2025 100,636.0013 Feb 2025 97,870.0011$2,765.66
long13 Feb 2025 97,870.0017 Feb 2025 96,118.104−$1,751.88
short17 Feb 2025 96,118.1021 Feb 2025 98,305.004−$2,186.89
long21 Feb 2025 98,305.0024 Feb 2025 96,258.003−$2,047.01
short24 Feb 2025 96,258.003 Mar 2025 94,270.007$1,988.01
long3 Mar 2025 94,270.009 Mar 2025 86,222.506−$8,047.53
short9 Mar 2025 86,222.5016 Mar 2025 84,338.407$1,884.02
long16 Mar 2025 84,338.4029 Mar 2025 84,424.4013$85.94
short29 Mar 2025 84,424.406 Apr 2025 83,538.008$886.39
long6 Apr 2025 83,538.007 Apr 2025 78,430.001−$5,107.99
short7 Apr 2025 78,430.0012 Apr 2025 83,423.805−$4,993.83
long12 Apr 2025 83,423.806 May 2025 94,733.7024$11,309.80
short6 May 2025 94,733.707 May 2025 96,834.001−$2,100.34
long7 May 2025 96,834.0018 May 2025 103,127.0011$6,292.63
short18 May 2025 103,127.0019 May 2025 106,454.001−$3,327.62
long19 May 2025 106,454.0029 May 2025 107,782.0010$1,327.51
short29 May 2025 107,782.009 Jun 2025 105,734.0011$2,047.77
long9 Jun 2025 105,734.0014 Jun 2025 106,067.005$332.58
short14 Jun 2025 106,067.0025 Jun 2025 106,083.0011−$16.41
long25 Jun 2025 106,083.002 Jul 2025 105,681.007−$401.87
short2 Jul 2025 105,681.003 Jul 2025 108,850.001−$3,168.46
long3 Jul 2025 108,850.0020 Jul 2025 117,840.0017$8,990.42
short20 Jul 2025 117,840.0023 Jul 2025 119,954.003−$2,114.42
long23 Jul 2025 119,954.0026 Jul 2025 117,614.003−$2,340.12
short26 Jul 2025 117,614.0028 Jul 2025 119,416.002−$1,801.25
long28 Jul 2025 119,416.0030 Jul 2025 117,951.002−$1,464.81
short30 Jul 2025 117,951.008 Aug 2025 117,472.009$478.73
long8 Aug 2025 117,472.0017 Aug 2025 117,381.009−$91.36
short17 Aug 2025 117,381.004 Sep 2025 111,706.0018$5,674.94
long4 Sep 2025 111,706.0021 Sep 2025 115,686.0017$3,979.91
short21 Sep 2025 115,686.0030 Sep 2025 114,312.009$1,373.66
long30 Sep 2025 114,312.0011 Oct 2025 112,774.0011−$1,537.48
short11 Oct 2025 112,774.0024 Oct 2025 110,078.0013$2,696.30
long24 Oct 2025 110,078.0031 Oct 2025 108,323.007−$1,755.32
short31 Oct 2025 108,323.0011 Nov 2025 106,011.0011$2,311.74
long11 Nov 2025 106,011.0013 Nov 2025 101,654.002−$4,356.76
short13 Nov 2025 101,654.0027 Nov 2025 90,484.0014$11,170.40
long27 Nov 2025 90,484.002 Dec 2025 86,286.005−$4,198.00
short2 Dec 2025 86,286.004 Dec 2025 93,429.902−$7,143.94
long4 Dec 2025 93,429.907 Dec 2025 89,236.803−$4,193.15
short7 Dec 2025 89,236.8010 Dec 2025 92,678.803−$3,442.01
long10 Dec 2025 92,678.8014 Dec 2025 90,240.004−$2,438.81
short14 Dec 2025 90,240.0022 Dec 2025 88,658.908$1,581.13
long22 Dec 2025 88,658.9026 Dec 2025 87,225.304−$1,433.60
short26 Dec 2025 87,225.3029 Dec 2025 87,952.703−$727.44
long29 Dec 2025 87,952.7030 Dec 2025 87,237.101−$715.58
short30 Dec 2025 87,237.1031 Dec 2025 88,485.501−$1,248.37
long31 Dec 2025 88,485.5010 Jan 2026 90,641.3010$2,155.77
short10 Jan 2026 90,641.3014 Jan 2026 95,414.004−$4,772.72
long14 Jan 2026 95,414.0020 Jan 2026 92,631.006−$2,783.00
short20 Jan 2026 92,631.0016 Feb 2026 68,832.6027$23,798.40
long16 Feb 2026 68,832.6018 Feb 2026 67,503.502−$1,329.07
short18 Feb 2026 67,503.5023 Feb 2026 67,643.405−$139.87
long23 Feb 2026 67,643.4024 Feb 2026 64,656.001−$2,987.38
short24 Feb 2026 64,656.0027 Feb 2026 67,485.203−$2,829.18
long27 Feb 2026 67,485.202 Mar 2026 65,776.503−$1,708.71
short2 Mar 2026 65,776.503 Mar 2026 68,830.101−$3,053.58
long3 Mar 2026 68,830.108 Mar 2026 67,262.905−$1,567.15
short8 Mar 2026 67,262.9012 Mar 2026 70,191.904−$2,928.95
long12 Mar 2026 70,191.9020 Mar 2026 69,930.008−$261.85
short20 Mar 2026 69,930.0026 Mar 2026 71,336.506−$1,406.52
long26 Mar 2026 71,336.5028 Mar 2026 66,407.302−$4,929.25
short28 Mar 2026 66,407.302 Apr 2026 68,113.905−$1,706.64
long2 Apr 2026 68,113.904 Apr 2026 66,964.302−$1,149.63
short4 Apr 2026 66,964.306 Apr 2026 69,034.202−$2,069.89
long6 Apr 2026 69,034.2029 Apr 2026 76,342.8023$7,308.60
short29 Apr 2026 76,342.803 May 2026 78,686.804−$2,344.06
long3 May 2026 78,686.8014 May 2026 79,313.6011$626.77
short14 May 2026 79,313.6013 Jun 2026 63,580.0030$15,733.60
long13 Jun 2026 63,580.0019 Jun 2026 62,958.006−$621.99
short19 Jun 2026 62,958.003 Jul 2026 61,560.0014$1,398.01
long3 Jul 2026 61,560.0014 Jul 2026 62,334.5011$774.52
short14 Jul 2026 62,334.5015 Jul 2026 65,044.001−$2,709.47
long15 Jul 2026 65,044.0025 Jul 2026 64,140.0010−$903.99
short25 Jul 2026 64,140.005 Aug 2026 64,106.6011$33.45
long5 Aug 2026 64,106.6012 Aug 2026 63,600.007−$506.54
short12 Aug 2026 63,600.0018 Aug 2026 64,532.106−$932.10
long18 Aug 2026 64,532.1031 Aug 2026 77,682.0013$13,149.90
short31 Aug 2026 77,682.004 Sep 2026 81,270.404−$3,588.37
long4 Sep 2026 81,270.409 Sep 2026 78,455.805−$2,814.57
short9 Sep 2026 78,455.8019 Sep 2026 80,883.9010−$2,428.06
long19 Sep 2026 80,883.9029 Sep 2026 83,500.0010$2,616.15
short29 Sep 2026 83,500.002 Oct 2026 84,880.103−$1,380.04
long2 Oct 2026 84,880.108 Oct 2026 83,321.806−$1,558.24
short8 Oct 2026 83,321.8021 Oct 2026 83,028.1013$293.67

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 18 msWith a workaround 1,000 bars in 6,783 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © HosseinDaftary//@version=4strategy("Binomial Moving Average","BMA", overlay=true, margin_long=100, margin_short=100 ,max_bars_back=96)//Binomial Moving Average:This type of moving average that is made by myself and i did not see anywhere before uses the half of binomial cofficients for//averaging the prices for example if the period be 5 then we use the 9 degree binomial cofficients(that yields 10 cofficients) and use half of them.//we use 126/256 for last bar,84/256,36/256,9/256 and finally use 1/256 for 5th bar. Seemingly this MA works better than EMA.fa_ma=input(title='Fast MA',defval=10)sl_ma=input(title='Slow MA',defval=30)fac(n)=>    fact=1    for i= 1 to n        fact:=fact*i    factcof= array.new_float(sl_ma) hn_ma(price,length)=>    sum=1.0    sum1=0.0    array.set(cof,length-1,1)    for i=2 to length        array.set(cof,length-i,fac(2*length-1)/(fac(i-1)*fac(2*length-i)))        sum:=sum+array.get(cof,length-i)    for i=0 to length-1        array.set(cof,i,array.get(cof,i)/sum)        sum1:=sum1+array.get(cof,i)*price[i]    sum1hn1=plot(hn_ma(close,sl_ma) , color=#00ff00)hn2=plot(hn_ma(close,fa_ma) ,color=#ff0000)fill(hn1,hn2,color=hn_ma(close,fa_ma)>hn_ma(close,sl_ma)?color.green:color.red)longCondition = crossover(hn_ma(close, fa_ma), hn_ma(close, sl_ma))if (longCondition)    strategy.entry("Long", strategy.long)shortCondition = crossunder(hn_ma(close, fa_ma), hn_ma(close, sl_ma))if (shortCondition)    strategy.entry("Short", strategy.short)