Pine Script v4 · Strategy
Simple SMA Strategy Backtest
A Pine Script v4 strategy built on SMA (xSeries, 14). It has 3 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. 8 settings; defaults include Resolution D, Source close and Length 14.
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 Simple SMA Strategy Backtest repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 42 of 42 trades.
- How did Simple SMA Strategy Backtest do on BTCUSDT 1D with default settings?
- +56.79%
- From 26 Jan 2024 to 21 Oct 2026, over 138 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Simple SMA Strategy Backtest 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.
- What alerts does Simple SMA Strategy Backtest have?
- 3
- Signal Buy; Signal Sell; FLAT.
- Does Simple SMA Strategy Backtest use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +56.79%
- $56,788.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 138
- 38 won · 100 lost
- Profitable
- 27.5%
- of closed trades
- Profit factor
- 1.33
- gross profit ÷ gross loss
- Max drawdown
- 28.74%
- −$37,299.40
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.
-
Note
Uses iff(), which v5 removed line 21
iff() on line 21, 22, 27, 28. v5 writes it as the ternary c ? a : b.
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 security → request.security, sma → ta.sma.
Same 138 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: //@version=4 → //@version=5
- Line 10: input(type = input.resolution) → input.timeframe()
- Line 11: input(type = input.source) → input.source()
- Line 12: security → request.security
- Line 13: input(type = input.integer) → input.int()
- Line 14: input(type = input.source) → input.source()
9 more edits
- Line 15: input(type = input.bool) → input.bool()
- Line 16: input(type = input.bool) → input.bool()
- Line 17: input(type = input.bool) → input.bool()
- Line 18: input(type = input.bool) → input.bool()
- Line 20: sma → ta.sma
- Line 21: iff(c, a, b) → (c ? a : b)
- Line 22: iff(c, a, b) → (c ? a : b)
- Line 27: iff(c, a, b) → (c ? a : b)
- Line 28: iff(c, a, b) → (c ? a : b)
⋯// - This script to change bars colors-//@version=4+//@version=5strategy(title="Simple SMA Strategy Backtest", shorttitle="SMA Backtest", precision=6, overlay=true)-Resolution = input(title="Resolution", type=input.resolution, defval="D")+Resolution = input.timeframe(title="Resolution", defval="D")-Source = input(title="Source", type=input.source, defval=close)+Source = input.source(title="Source", defval=close)-xSeries = security(syminfo.tickerid, Resolution, Source)+xSeries = request.security(syminfo.tickerid, Resolution, Source)-Length = input(title="Length", type=input.integer, defval=14, minval=2)+Length = input.int(title="Length", defval=14, minval=2)-TriggerPrice = input(title="Trigger Price", type=input.source, defval=close)+TriggerPrice = input.source(title="Trigger Price", defval=close)-BarColors = input(title="Painting bars", type=input.bool, defval=true)+BarColors = input.bool(title="Painting bars", defval=true)-ShowLine = input(title="Show Line", type=input.bool, defval=true)+ShowLine = input.bool(title="Show Line", defval=true)-UseAlerts = input(title="Use Alerts", type=input.bool, defval=false)+UseAlerts = input.bool(title="Use Alerts", defval=false)-reverse = input(title="Trade Reverse", type=input.bool, defval=false)+reverse = input.bool(title="Trade Reverse", defval=false)pos = 0-xSMA = sma(xSeries, Length)+xSMA = ta.sma(xSeries, Length)-pos := iff(TriggerPrice > xSMA, 1,- iff(TriggerPrice < xSMA, -1, nz(pos[1], 0)))+pos := (TriggerPrice > xSMA ? 1 : (TriggerPrice < xSMA ? -1 : nz(pos[1], 0)))nRes = ShowLine ? xSMA : na⋯alertcondition(UseAlerts == true and pos != pos[1] and pos == 0, title='FLAT', message='Strategy get out from position')-possig = iff(reverse and pos == 1, -1,- iff(reverse and pos == -1, 1, pos))+possig = (reverse and pos == 1 ? -1 : (reverse and pos == -1 ? 1 : pos))if (possig == 1)⋯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: 138 before, 165 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.
⋯// - This script to change bars colors-//@version=5+//@version=6strategy(title="Simple SMA Strategy Backtest", shorttitle="SMA Backtest", precision=6, overlay=true)⋯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 |
|---|---|---|---|
| Resolution | D | timeframe (written input.resolution) | xSeries |
| Source | close | source | xSeries |
| Length | 14 | int (written input.integer) · min 2 | xSMA |
| Trigger Price | close | source | pos |
| Painting bars | true | bool | nColor |
| Show Line | true | bool | nRes |
| Use Alerts | false | bool | Signal Buy Signal Sell FLAT |
| Trade Reverse | false | bool | possig |
What it calculates
- SMA (
sma,ta.smain v5)xSeries, Length (14)xSMA · line 20
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 | (possig == 1) | On | 30 |
| Open Short short | (possig == -1) | On | 32 |
| Close | (possig == 0) | On | 34 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Signal Buy | alertcondition | Strategy to change to BUY | 24 |
| Signal Sell | alertcondition | Strategy to change to SELL | 25 |
| FLAT | alertcondition | Strategy get out from position | 26 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe data1 security call(s), none with lookahead on.
- 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 | +56.8% | +102.5% | 138 | 28% | 1.33 | 28.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −9.9% | +5.5% | 126 | 23% | 0.85 | 16.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.5% | +9.8% | 145 | 24% | 0.96 | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.4% | +8.4% | 148 | 21% | 0.85 | 1.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 125 | 34% | 1.23 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 114 | 29% | 1.02 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.2% | +148.3% | 146 | 30% | 0.92 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 136 | 24% | 0.86 | 0.2% | 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 | 50 | 24% | −$3,371.93 |
| Sideways market | 56 | 36% | $46,509.70 |
| Falling market | 32 | 19% | $13,650.60 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
38.6%
The 95th percentile of the worst drawdown when the same 138 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 18.2% to 38.6%; the tick is what actually happened, 27.6%. Order luck alone moves it this much.
All 138 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 9 Feb 2024 45,288.70 | 24 Feb 2024 50,744.20 | 15 | $5,455.49 |
| short | 24 Feb 2024 50,744.20 | 25 Feb 2024 51,568.20 | 1 | −$824.06 |
| long | 25 Feb 2024 51,568.20 | 17 Mar 2024 65,300.60 | 21 | $13,732.40 |
| 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 | 5 Apr 2024 68,487.80 | 2 | −$3,023.81 |
| long | 5 Apr 2024 68,487.80 | 6 Apr 2024 67,820.60 | 1 | −$667.17 |
| short | 6 Apr 2024 67,820.60 | 7 Apr 2024 68,896.00 | 1 | −$1,075.37 |
| long | 7 Apr 2024 68,896.00 | 13 Apr 2024 67,116.50 | 6 | −$1,779.48 |
| short | 13 Apr 2024 67,116.50 | 23 Apr 2024 66,819.30 | 10 | $297.20 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$2,529.74 |
| short | 25 Apr 2024 64,289.60 | 5 May 2024 63,892.00 | 10 | $397.55 |
| long | 5 May 2024 63,892.00 | 8 May 2024 62,312.10 | 3 | −$1,579.96 |
| short | 8 May 2024 62,312.10 | 10 May 2024 63,074.00 | 2 | −$761.93 |
| long | 10 May 2024 63,074.00 | 11 May 2024 60,800.00 | 1 | −$2,274.01 |
| short | 11 May 2024 60,800.00 | 14 May 2024 62,940.10 | 3 | −$2,140.10 |
| long | 14 May 2024 62,940.10 | 15 May 2024 61,577.50 | 1 | −$1,362.60 |
| short | 15 May 2024 61,577.50 | 16 May 2024 66,206.50 | 1 | −$4,629.02 |
| long | 16 May 2024 66,206.50 | 30 May 2024 67,652.40 | 14 | $1,445.90 |
| short | 30 May 2024 67,652.40 | 4 Jun 2024 68,809.90 | 5 | −$1,157.48 |
| long | 4 Jun 2024 68,809.90 | 12 Jun 2024 67,314.20 | 8 | −$1,495.66 |
| short | 12 Jun 2024 67,314.20 | 2 Jul 2024 62,900.00 | 20 | $4,414.23 |
| long | 2 Jul 2024 62,900.00 | 3 Jul 2024 62,135.50 | 1 | −$764.54 |
| short | 3 Jul 2024 62,135.50 | 14 Jul 2024 59,204.00 | 11 | $2,931.45 |
| long | 14 Jul 2024 59,204.00 | 31 Jul 2024 66,188.00 | 17 | $6,983.99 |
| short | 31 Jul 2024 66,188.00 | 14 Aug 2024 60,587.20 | 14 | $5,600.84 |
| long | 14 Aug 2024 60,587.20 | 15 Aug 2024 58,683.40 | 1 | −$1,903.77 |
| short | 15 Aug 2024 58,683.40 | 17 Aug 2024 58,874.60 | 2 | −$191.20 |
| long | 17 Aug 2024 58,874.60 | 19 Aug 2024 58,427.30 | 2 | −$447.24 |
| short | 19 Aug 2024 58,427.30 | 20 Aug 2024 59,438.50 | 1 | −$1,011.15 |
| long | 20 Aug 2024 59,438.50 | 21 Aug 2024 59,013.80 | 1 | −$424.70 |
| short | 21 Aug 2024 59,013.80 | 22 Aug 2024 61,156.00 | 1 | −$2,142.23 |
| long | 22 Aug 2024 61,156.00 | 28 Aug 2024 59,415.00 | 6 | −$1,741.03 |
| short | 28 Aug 2024 59,415.00 | 11 Sep 2024 57,636.00 | 14 | $1,779.01 |
| long | 11 Sep 2024 57,636.00 | 1 Oct 2024 63,327.60 | 20 | $5,691.61 |
| short | 1 Oct 2024 63,327.60 | 12 Oct 2024 62,540.00 | 11 | $787.61 |
| long | 12 Oct 2024 62,540.00 | 26 Oct 2024 66,698.30 | 14 | $4,158.33 |
| short | 26 Oct 2024 66,698.30 | 28 Oct 2024 68,021.70 | 2 | −$1,323.37 |
| long | 28 Oct 2024 68,021.70 | 4 Nov 2024 68,776.00 | 7 | $754.30 |
| short | 4 Nov 2024 68,776.00 | 6 Nov 2024 69,372.00 | 2 | −$596.02 |
| long | 6 Nov 2024 69,372.00 | 27 Nov 2024 91,965.20 | 21 | $22,593.20 |
| short | 27 Nov 2024 91,965.20 | 28 Nov 2024 95,863.10 | 1 | −$3,897.95 |
| long | 28 Nov 2024 95,863.10 | 3 Dec 2024 95,840.60 | 5 | −$22.50 |
| short | 3 Dec 2024 95,840.60 | 5 Dec 2024 98,587.30 | 2 | −$2,746.71 |
| long | 5 Dec 2024 98,587.30 | 11 Dec 2024 96,593.00 | 6 | −$1,994.32 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$4,532.00 |
| long | 12 Dec 2024 101,125.00 | 19 Dec 2024 100,204.00 | 7 | −$920.99 |
| short | 19 Dec 2024 100,204.00 | 3 Jan 2025 96,984.80 | 15 | $3,219.22 |
| 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 | 28 Jan 2025 102,083.00 | 13 | $5,521.98 |
| short | 28 Jan 2025 102,083.00 | 30 Jan 2025 103,733.00 | 2 | −$1,650.42 |
| long | 30 Jan 2025 103,733.00 | 1 Feb 2025 102,430.00 | 2 | −$1,303.69 |
| short | 1 Feb 2025 102,430.00 | 16 Feb 2025 97,569.70 | 15 | $4,859.89 |
| long | 16 Feb 2025 97,569.70 | 17 Feb 2025 96,118.10 | 1 | −$1,451.55 |
| short | 17 Feb 2025 96,118.10 | 20 Feb 2025 96,644.40 | 3 | −$526.25 |
| long | 20 Feb 2025 96,644.40 | 22 Feb 2025 96,182.00 | 2 | −$462.38 |
| short | 22 Feb 2025 96,182.00 | 3 Mar 2025 94,270.00 | 9 | $1,912.00 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$8,048.83 |
| short | 4 Mar 2025 86,221.20 | 6 Mar 2025 90,606.00 | 2 | −$4,384.84 |
| long | 6 Mar 2025 90,606.00 | 8 Mar 2025 86,801.70 | 2 | −$3,804.26 |
| short | 8 Mar 2025 86,801.70 | 20 Mar 2025 86,845.90 | 12 | −$44.19 |
| long | 20 Mar 2025 86,845.90 | 29 Mar 2025 84,424.40 | 9 | −$2,421.55 |
| short | 29 Mar 2025 84,424.40 | 2 Apr 2025 85,158.40 | 4 | −$733.97 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$2,642.07 |
| short | 3 Apr 2025 82,516.30 | 10 Apr 2025 82,615.20 | 7 | −$98.94 |
| long | 10 Apr 2025 82,615.20 | 11 Apr 2025 79,607.30 | 1 | −$3,007.92 |
| short | 11 Apr 2025 79,607.30 | 12 Apr 2025 83,423.80 | 1 | −$3,816.53 |
| long | 12 Apr 2025 83,423.80 | 30 May 2025 105,590.00 | 48 | $22,165.90 |
| short | 30 May 2025 105,590.00 | 9 Jun 2025 105,734.00 | 10 | −$144.26 |
| long | 9 Jun 2025 105,734.00 | 13 Jun 2025 105,672.00 | 4 | −$62.27 |
| short | 13 Jun 2025 105,672.00 | 14 Jun 2025 106,067.00 | 1 | −$394.85 |
| long | 14 Jun 2025 106,067.00 | 15 Jun 2025 105,415.00 | 1 | −$651.96 |
| short | 15 Jun 2025 105,415.00 | 17 Jun 2025 106,795.00 | 2 | −$1,379.90 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$2,243.36 |
| short | 18 Jun 2025 104,551.00 | 24 Jun 2025 105,334.00 | 6 | −$782.77 |
| long | 24 Jun 2025 105,334.00 | 25 Jul 2025 118,341.00 | 31 | $13,007.00 |
| short | 25 Jul 2025 118,341.00 | 28 Jul 2025 119,416.00 | 3 | −$1,074.58 |
| long | 28 Jul 2025 119,416.00 | 29 Jul 2025 118,062.00 | 1 | −$1,353.24 |
| short | 29 Jul 2025 118,062.00 | 8 Aug 2025 117,472.00 | 10 | $590.30 |
| 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 | 5 Sep 2025 110,731.00 | 1 | −$974.85 |
| short | 5 Sep 2025 110,731.00 | 8 Sep 2025 111,137.00 | 3 | −$406.48 |
| long | 8 Sep 2025 111,137.00 | 23 Sep 2025 112,651.00 | 15 | $1,513.64 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$1,660.98 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$1,537.48 |
| short | 11 Oct 2025 112,774.00 | 25 Oct 2025 111,005.00 | 14 | $1,769.59 |
| long | 25 Oct 2025 111,005.00 | 30 Oct 2025 110,021.00 | 5 | −$983.60 |
| short | 30 Oct 2025 110,021.00 | 28 Nov 2025 91,333.90 | 29 | $18,687.40 |
| long | 28 Nov 2025 91,333.90 | 2 Dec 2025 86,286.00 | 4 | −$5,047.93 |
| short | 2 Dec 2025 86,286.00 | 3 Dec 2025 91,277.90 | 1 | −$4,991.87 |
| long | 3 Dec 2025 91,277.90 | 6 Dec 2025 89,330.00 | 3 | −$1,947.84 |
| short | 6 Dec 2025 89,330.00 | 8 Dec 2025 90,395.30 | 2 | −$1,065.28 |
| long | 8 Dec 2025 90,395.30 | 13 Dec 2025 90,268.40 | 5 | −$126.89 |
| short | 13 Dec 2025 90,268.40 | 28 Dec 2025 87,877.00 | 15 | $2,391.43 |
| long | 28 Dec 2025 87,877.00 | 30 Dec 2025 87,237.10 | 2 | −$639.87 |
| short | 30 Dec 2025 87,237.10 | 31 Dec 2025 88,485.50 | 1 | −$1,248.37 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | −$837.29 |
| short | 1 Jan 2026 87,648.20 | 2 Jan 2026 88,839.10 | 1 | −$1,190.84 |
| long | 2 Jan 2026 88,839.10 | 20 Jan 2026 92,631.00 | 18 | $3,791.94 |
| short | 20 Jan 2026 92,631.00 | 26 Feb 2026 67,988.00 | 37 | $24,643.00 |
| long | 26 Feb 2026 67,988.00 | 27 Feb 2026 67,485.20 | 1 | −$502.85 |
| short | 27 Feb 2026 67,485.20 | 3 Mar 2026 68,830.10 | 4 | −$1,344.87 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$1,567.15 |
| short | 8 Mar 2026 67,262.90 | 10 Mar 2026 68,432.20 | 2 | −$1,169.25 |
| long | 10 Mar 2026 68,432.20 | 20 Mar 2026 69,930.00 | 10 | $1,497.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 | 27 Mar 2026 68,820.30 | 1 | −$2,516.22 |
| short | 27 Mar 2026 68,820.30 | 6 Apr 2026 69,034.20 | 10 | −$213.87 |
| long | 6 Apr 2026 69,034.20 | 29 Apr 2026 76,342.80 | 23 | $7,308.60 |
| short | 29 Apr 2026 76,342.80 | 2 May 2026 78,231.10 | 3 | −$1,888.35 |
| long | 2 May 2026 78,231.10 | 14 May 2026 79,313.60 | 12 | $1,082.48 |
| short | 14 May 2026 79,313.60 | 15 May 2026 81,090.00 | 1 | −$1,776.39 |
| long | 15 May 2026 81,090.00 | 16 May 2026 79,113.20 | 1 | −$1,976.80 |
| short | 16 May 2026 79,113.20 | 15 Jun 2026 65,746.40 | 30 | $13,366.80 |
| long | 15 Jun 2026 65,746.40 | 19 Jun 2026 62,958.00 | 4 | −$2,788.44 |
| short | 19 Jun 2026 62,958.00 | 21 Jun 2026 64,298.00 | 2 | −$1,340.00 |
| long | 21 Jun 2026 64,298.00 | 22 Jun 2026 63,312.00 | 1 | −$986.01 |
| short | 22 Jun 2026 63,312.00 | 23 Jun 2026 64,020.00 | 1 | −$708.01 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$1,285.44 |
| short | 24 Jun 2026 62,734.60 | 3 Jul 2026 61,560.00 | 9 | $1,174.57 |
| 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 | 27 Jul 2026 65,400.00 | 2 | −$1,260.00 |
| long | 27 Jul 2026 65,400.00 | 28 Jul 2026 63,755.90 | 1 | −$1,644.14 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$1,024.17 |
| long | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | −$1,892.15 |
| short | 1 Aug 2026 62,887.90 | 6 Aug 2026 64,665.20 | 5 | −$1,777.36 |
| long | 6 Aug 2026 64,665.20 | 11 Aug 2026 63,970.00 | 5 | −$695.23 |
| short | 11 Aug 2026 63,970.00 | 18 Aug 2026 64,532.10 | 7 | −$562.10 |
| long | 18 Aug 2026 64,532.10 | 3 Sep 2026 77,340.00 | 16 | $12,807.90 |
| short | 3 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 1 | −$3,930.36 |
| 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 | 8 Oct 2026 83,321.80 | 19 | $2,437.95 |
| short | 8 Oct 2026 83,321.80 | 21 Oct 2026 83,028.10 | 13 | $293.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Simple SMA Strategy Backtest this page | — | v4 strategy | +56.8% | 138 | 28.7% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | Yes 1,000 bars in 41 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/// © HPotter// Simple SMA strategy//// WARNING:// - For purpose educate only// - This script to change bars colors//@version=4strategy(title="Simple SMA Strategy Backtest", shorttitle="SMA Backtest", precision=6, overlay=true)Resolution = input(title="Resolution", type=input.resolution, defval="D")Source = input(title="Source", type=input.source, defval=close)xSeries = security(syminfo.tickerid, Resolution, Source)Length = input(title="Length", type=input.integer, defval=14, minval=2)TriggerPrice = input(title="Trigger Price", type=input.source, defval=close)BarColors = input(title="Painting bars", type=input.bool, defval=true)ShowLine = input(title="Show Line", type=input.bool, defval=true)UseAlerts = input(title="Use Alerts", type=input.bool, defval=false)reverse = input(title="Trade Reverse", type=input.bool, defval=false)pos = 0xSMA = sma(xSeries, Length)pos := iff(TriggerPrice > xSMA, 1, iff(TriggerPrice < xSMA, -1, nz(pos[1], 0)))nRes = ShowLine ? xSMA : naalertcondition(UseAlerts == true and pos != pos[1] and pos == 1, title='Signal Buy', message='Strategy to change to BUY')alertcondition(UseAlerts == true and pos != pos[1] and pos == -1, title='Signal Sell', message='Strategy to change to SELL')alertcondition(UseAlerts == true and pos != pos[1] and pos == 0, title='FLAT', message='Strategy get out from position')possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos))if (possig == 1) strategy.entry("Long", strategy.long)if (possig == -1) strategy.entry("Short", strategy.short)if (possig == 0) strategy.close_all()nColor = BarColors ? possig == -1 ? color.red : possig == 1 ? color.green : color.blue : na barcolor(nColor)plot(nRes, title='SMA', color=#00ffaa, linewidth=2, style=plot.style_line)