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
- 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
VerifiedSame 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)⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Fast MA | 10 | int | hn2 longCondition shortCondition plot fill |
| Slow MA | 30 | int | cof hn1 longCondition shortCondition plot fill |
What it calculates
- Crossover (
crossover,ta.crossoverin v5)hn_ma(close, fa_ma), hn_ma(close, sl_ma)longCondition · line 30 - Crossunder (
crossunder,ta.crossunderin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCondition) | On | 32 |
| Open Short short | (shortCondition) | On | 35 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.8% | +102.5% | 132 | 33% | 1.00 | 35.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.3% | +5.5% | 131 | 36% | 1.02 | 17.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.3% | +9.8% | 138 | 32% | 0.90 | 3.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.6% | +8.4% | 143 | 30% | 1.27 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.3% | +16.7% | 120 | 42% | 1.51 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 126 | 34% | 1.23 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.2% | +148.3% | 121 | 35% | 0.89 | 0.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.2% | +17.1% | 123 | 37% | 1.37 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 46 | 28% | −$5,043.68 |
| Sideways market | 47 | 43% | $16,094.90 |
| Falling market | 39 | 26% | −$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.
All 132 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Feb 2024 54,476.50 | 17 Mar 2024 65,300.60 | 19 | $10,824.20 |
| short | 17 Mar 2024 65,300.60 | 26 Mar 2024 69,880.00 | 9 | −$4,579.36 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$4,416.01 |
| short | 3 Apr 2024 65,464.00 | 8 Apr 2024 69,360.40 | 5 | −$3,896.39 |
| long | 8 Apr 2024 69,360.40 | 13 Apr 2024 67,116.50 | 5 | −$2,243.86 |
| short | 13 Apr 2024 67,116.50 | 21 Apr 2024 64,940.60 | 8 | $2,175.94 |
| long | 21 Apr 2024 64,940.60 | 27 Apr 2024 63,770.00 | 6 | −$1,170.58 |
| short | 27 Apr 2024 63,770.00 | 5 May 2024 63,892.00 | 8 | −$122.03 |
| long | 5 May 2024 63,892.00 | 9 May 2024 61,193.00 | 4 | −$2,699.00 |
| short | 9 May 2024 61,193.00 | 15 May 2024 61,577.50 | 6 | −$384.46 |
| long | 15 May 2024 61,577.50 | 27 May 2024 68,507.70 | 12 | $6,930.18 |
| short | 27 May 2024 68,507.70 | 28 May 2024 69,436.40 | 1 | −$928.76 |
| long | 28 May 2024 69,436.40 | 29 May 2024 68,398.40 | 1 | −$1,038.03 |
| short | 29 May 2024 68,398.40 | 4 Jun 2024 68,809.90 | 6 | −$411.49 |
| long | 4 Jun 2024 68,809.90 | 10 Jun 2024 69,648.10 | 6 | $838.26 |
| short | 10 Jun 2024 69,648.10 | 1 Jul 2024 62,772.00 | 21 | $6,876.14 |
| long | 1 Jul 2024 62,772.00 | 4 Jul 2024 60,208.60 | 3 | −$2,563.44 |
| short | 4 Jul 2024 60,208.60 | 12 Jul 2024 57,339.90 | 8 | $2,868.68 |
| long | 12 Jul 2024 57,339.90 | 25 Jul 2024 65,376.00 | 13 | $8,036.12 |
| short | 25 Jul 2024 65,376.00 | 27 Jul 2024 67,908.00 | 2 | −$2,531.99 |
| long | 27 Jul 2024 67,908.00 | 31 Jul 2024 66,188.00 | 4 | −$1,720.00 |
| short | 31 Jul 2024 66,188.00 | 10 Aug 2024 60,838.00 | 10 | $5,350.01 |
| long | 10 Aug 2024 60,838.00 | 15 Aug 2024 58,683.40 | 5 | −$2,154.60 |
| short | 15 Aug 2024 58,683.40 | 20 Aug 2024 59,438.50 | 5 | −$755.11 |
| long | 20 Aug 2024 59,438.50 | 28 Aug 2024 59,415.00 | 8 | −$23.50 |
| short | 28 Aug 2024 59,415.00 | 11 Sep 2024 57,636.00 | 14 | $1,779.01 |
| long | 11 Sep 2024 57,636.00 | 2 Oct 2024 60,804.90 | 21 | $3,168.93 |
| short | 2 Oct 2024 60,804.90 | 7 Oct 2024 62,819.90 | 5 | −$2,014.99 |
| long | 7 Oct 2024 62,819.90 | 10 Oct 2024 60,636.00 | 3 | −$2,183.90 |
| short | 10 Oct 2024 60,636.00 | 13 Oct 2024 63,206.20 | 3 | −$2,570.22 |
| long | 13 Oct 2024 63,206.20 | 24 Oct 2024 66,668.60 | 11 | $3,462.42 |
| short | 24 Oct 2024 66,668.60 | 29 Oct 2024 69,962.20 | 5 | −$3,293.56 |
| long | 29 Oct 2024 69,962.20 | 3 Nov 2024 69,374.70 | 5 | −$587.47 |
| short | 3 Nov 2024 69,374.70 | 7 Nov 2024 75,572.00 | 4 | −$6,197.25 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $16,393.20 |
| short | 27 Nov 2024 91,965.20 | 30 Nov 2024 97,460.00 | 3 | −$5,494.84 |
| long | 30 Nov 2024 97,460.00 | 11 Dec 2024 96,593.00 | 11 | −$867.00 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$4,532.00 |
| long | 12 Dec 2024 101,125.00 | 20 Dec 2024 97,461.90 | 8 | −$3,663.14 |
| short | 20 Dec 2024 97,461.90 | 26 Dec 2024 99,429.60 | 6 | −$1,967.75 |
| long | 26 Dec 2024 99,429.60 | 27 Dec 2024 95,791.60 | 1 | −$3,638.01 |
| short | 27 Dec 2024 95,791.60 | 3 Jan 2025 96,984.80 | 7 | −$1,193.19 |
| long | 3 Jan 2025 96,984.80 | 9 Jan 2025 95,060.60 | 6 | −$1,924.18 |
| short | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | −$1,500.24 |
| long | 15 Jan 2025 96,560.90 | 27 Jan 2025 102,620.00 | 12 | $6,059.16 |
| short | 27 Jan 2025 102,620.00 | 31 Jan 2025 104,723.00 | 4 | −$2,102.93 |
| long | 31 Jan 2025 104,723.00 | 2 Feb 2025 100,636.00 | 2 | −$4,087.28 |
| short | 2 Feb 2025 100,636.00 | 13 Feb 2025 97,870.00 | 11 | $2,765.66 |
| long | 13 Feb 2025 97,870.00 | 17 Feb 2025 96,118.10 | 4 | −$1,751.88 |
| short | 17 Feb 2025 96,118.10 | 21 Feb 2025 98,305.00 | 4 | −$2,186.89 |
| long | 21 Feb 2025 98,305.00 | 24 Feb 2025 96,258.00 | 3 | −$2,047.01 |
| short | 24 Feb 2025 96,258.00 | 3 Mar 2025 94,270.00 | 7 | $1,988.01 |
| long | 3 Mar 2025 94,270.00 | 9 Mar 2025 86,222.50 | 6 | −$8,047.53 |
| short | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | $1,884.02 |
| long | 16 Mar 2025 84,338.40 | 29 Mar 2025 84,424.40 | 13 | $85.94 |
| short | 29 Mar 2025 84,424.40 | 6 Apr 2025 83,538.00 | 8 | $886.39 |
| long | 6 Apr 2025 83,538.00 | 7 Apr 2025 78,430.00 | 1 | −$5,107.99 |
| short | 7 Apr 2025 78,430.00 | 12 Apr 2025 83,423.80 | 5 | −$4,993.83 |
| long | 12 Apr 2025 83,423.80 | 6 May 2025 94,733.70 | 24 | $11,309.80 |
| short | 6 May 2025 94,733.70 | 7 May 2025 96,834.00 | 1 | −$2,100.34 |
| long | 7 May 2025 96,834.00 | 18 May 2025 103,127.00 | 11 | $6,292.63 |
| short | 18 May 2025 103,127.00 | 19 May 2025 106,454.00 | 1 | −$3,327.62 |
| long | 19 May 2025 106,454.00 | 29 May 2025 107,782.00 | 10 | $1,327.51 |
| short | 29 May 2025 107,782.00 | 9 Jun 2025 105,734.00 | 11 | $2,047.77 |
| long | 9 Jun 2025 105,734.00 | 14 Jun 2025 106,067.00 | 5 | $332.58 |
| short | 14 Jun 2025 106,067.00 | 25 Jun 2025 106,083.00 | 11 | −$16.41 |
| long | 25 Jun 2025 106,083.00 | 2 Jul 2025 105,681.00 | 7 | −$401.87 |
| short | 2 Jul 2025 105,681.00 | 3 Jul 2025 108,850.00 | 1 | −$3,168.46 |
| long | 3 Jul 2025 108,850.00 | 20 Jul 2025 117,840.00 | 17 | $8,990.42 |
| short | 20 Jul 2025 117,840.00 | 23 Jul 2025 119,954.00 | 3 | −$2,114.42 |
| long | 23 Jul 2025 119,954.00 | 26 Jul 2025 117,614.00 | 3 | −$2,340.12 |
| short | 26 Jul 2025 117,614.00 | 28 Jul 2025 119,416.00 | 2 | −$1,801.25 |
| long | 28 Jul 2025 119,416.00 | 30 Jul 2025 117,951.00 | 2 | −$1,464.81 |
| short | 30 Jul 2025 117,951.00 | 8 Aug 2025 117,472.00 | 9 | $478.73 |
| long | 8 Aug 2025 117,472.00 | 17 Aug 2025 117,381.00 | 9 | −$91.36 |
| short | 17 Aug 2025 117,381.00 | 4 Sep 2025 111,706.00 | 18 | $5,674.94 |
| long | 4 Sep 2025 111,706.00 | 21 Sep 2025 115,686.00 | 17 | $3,979.91 |
| short | 21 Sep 2025 115,686.00 | 30 Sep 2025 114,312.00 | 9 | $1,373.66 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$1,537.48 |
| short | 11 Oct 2025 112,774.00 | 24 Oct 2025 110,078.00 | 13 | $2,696.30 |
| long | 24 Oct 2025 110,078.00 | 31 Oct 2025 108,323.00 | 7 | −$1,755.32 |
| short | 31 Oct 2025 108,323.00 | 11 Nov 2025 106,011.00 | 11 | $2,311.74 |
| long | 11 Nov 2025 106,011.00 | 13 Nov 2025 101,654.00 | 2 | −$4,356.76 |
| short | 13 Nov 2025 101,654.00 | 27 Nov 2025 90,484.00 | 14 | $11,170.40 |
| long | 27 Nov 2025 90,484.00 | 2 Dec 2025 86,286.00 | 5 | −$4,198.00 |
| short | 2 Dec 2025 86,286.00 | 4 Dec 2025 93,429.90 | 2 | −$7,143.94 |
| long | 4 Dec 2025 93,429.90 | 7 Dec 2025 89,236.80 | 3 | −$4,193.15 |
| short | 7 Dec 2025 89,236.80 | 10 Dec 2025 92,678.80 | 3 | −$3,442.01 |
| long | 10 Dec 2025 92,678.80 | 14 Dec 2025 90,240.00 | 4 | −$2,438.81 |
| short | 14 Dec 2025 90,240.00 | 22 Dec 2025 88,658.90 | 8 | $1,581.13 |
| long | 22 Dec 2025 88,658.90 | 26 Dec 2025 87,225.30 | 4 | −$1,433.60 |
| short | 26 Dec 2025 87,225.30 | 29 Dec 2025 87,952.70 | 3 | −$727.44 |
| long | 29 Dec 2025 87,952.70 | 30 Dec 2025 87,237.10 | 1 | −$715.58 |
| short | 30 Dec 2025 87,237.10 | 31 Dec 2025 88,485.50 | 1 | −$1,248.37 |
| long | 31 Dec 2025 88,485.50 | 10 Jan 2026 90,641.30 | 10 | $2,155.77 |
| short | 10 Jan 2026 90,641.30 | 14 Jan 2026 95,414.00 | 4 | −$4,772.72 |
| long | 14 Jan 2026 95,414.00 | 20 Jan 2026 92,631.00 | 6 | −$2,783.00 |
| short | 20 Jan 2026 92,631.00 | 16 Feb 2026 68,832.60 | 27 | $23,798.40 |
| long | 16 Feb 2026 68,832.60 | 18 Feb 2026 67,503.50 | 2 | −$1,329.07 |
| short | 18 Feb 2026 67,503.50 | 23 Feb 2026 67,643.40 | 5 | −$139.87 |
| long | 23 Feb 2026 67,643.40 | 24 Feb 2026 64,656.00 | 1 | −$2,987.38 |
| short | 24 Feb 2026 64,656.00 | 27 Feb 2026 67,485.20 | 3 | −$2,829.18 |
| long | 27 Feb 2026 67,485.20 | 2 Mar 2026 65,776.50 | 3 | −$1,708.71 |
| short | 2 Mar 2026 65,776.50 | 3 Mar 2026 68,830.10 | 1 | −$3,053.58 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$1,567.15 |
| short | 8 Mar 2026 67,262.90 | 12 Mar 2026 70,191.90 | 4 | −$2,928.95 |
| long | 12 Mar 2026 70,191.90 | 20 Mar 2026 69,930.00 | 8 | −$261.85 |
| short | 20 Mar 2026 69,930.00 | 26 Mar 2026 71,336.50 | 6 | −$1,406.52 |
| long | 26 Mar 2026 71,336.50 | 28 Mar 2026 66,407.30 | 2 | −$4,929.25 |
| short | 28 Mar 2026 66,407.30 | 2 Apr 2026 68,113.90 | 5 | −$1,706.64 |
| long | 2 Apr 2026 68,113.90 | 4 Apr 2026 66,964.30 | 2 | −$1,149.63 |
| short | 4 Apr 2026 66,964.30 | 6 Apr 2026 69,034.20 | 2 | −$2,069.89 |
| long | 6 Apr 2026 69,034.20 | 29 Apr 2026 76,342.80 | 23 | $7,308.60 |
| short | 29 Apr 2026 76,342.80 | 3 May 2026 78,686.80 | 4 | −$2,344.06 |
| long | 3 May 2026 78,686.80 | 14 May 2026 79,313.60 | 11 | $626.77 |
| short | 14 May 2026 79,313.60 | 13 Jun 2026 63,580.00 | 30 | $15,733.60 |
| long | 13 Jun 2026 63,580.00 | 19 Jun 2026 62,958.00 | 6 | −$621.99 |
| short | 19 Jun 2026 62,958.00 | 3 Jul 2026 61,560.00 | 14 | $1,398.01 |
| long | 3 Jul 2026 61,560.00 | 14 Jul 2026 62,334.50 | 11 | $774.52 |
| short | 14 Jul 2026 62,334.50 | 15 Jul 2026 65,044.00 | 1 | −$2,709.47 |
| long | 15 Jul 2026 65,044.00 | 25 Jul 2026 64,140.00 | 10 | −$903.99 |
| short | 25 Jul 2026 64,140.00 | 5 Aug 2026 64,106.60 | 11 | $33.45 |
| long | 5 Aug 2026 64,106.60 | 12 Aug 2026 63,600.00 | 7 | −$506.54 |
| short | 12 Aug 2026 63,600.00 | 18 Aug 2026 64,532.10 | 6 | −$932.10 |
| long | 18 Aug 2026 64,532.10 | 31 Aug 2026 77,682.00 | 13 | $13,149.90 |
| short | 31 Aug 2026 77,682.00 | 4 Sep 2026 81,270.40 | 4 | −$3,588.37 |
| long | 4 Sep 2026 81,270.40 | 9 Sep 2026 78,455.80 | 5 | −$2,814.57 |
| short | 9 Sep 2026 78,455.80 | 19 Sep 2026 80,883.90 | 10 | −$2,428.06 |
| long | 19 Sep 2026 80,883.90 | 29 Sep 2026 83,500.00 | 10 | $2,616.15 |
| short | 29 Sep 2026 83,500.00 | 2 Oct 2026 84,880.10 | 3 | −$1,380.04 |
| long | 2 Oct 2026 84,880.10 | 8 Oct 2026 83,321.80 | 6 | −$1,558.24 |
| short | 8 Oct 2026 83,321.80 | 21 Oct 2026 83,028.10 | 13 | $293.67 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 18 ms | With a workaround 1,000 bars in 6,783 ms | Not measured |
| PineTS | No 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)