Pine Script v4 · Strategy
Simple SMA Strategy Backtest Part 5
A Pine Script v4 strategy built on SMA (xSeries, 14). It has 7 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. 13 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 Part 5 repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 35 of 35 trades.
- How did Simple SMA Strategy Backtest Part 5 do on BTCUSDT 1D with default settings?
- +13.25%
- From 26 Jan 2024 to 21 Oct 2026, over 114 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Simple SMA Strategy Backtest Part 5 be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- What alerts does Simple SMA Strategy Backtest Part 5 have?
- 3
- Signal Buy; Signal Sell; FLAT.
- Does Simple SMA Strategy Backtest Part 5 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
- +13.25%
- $13,253.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 114
- 55 won · 59 lost
- Profitable
- 48.2%
- of closed trades
- Profit factor
- 1.13
- gross profit ÷ gross loss
- Max drawdown
- 20.83%
- −$23,731.80
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 an argument v6 removed
when = on line 43, 44, 45, 46. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 27
iff() on line 27, 28, 33, 34, 35. 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.
- 4 strategy calls use the when = argument (line 43, 44, 45, 46). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 114 before, 138 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: //@version=4 → //@version=5
- Line 11: input(type = input.resolution) → input.timeframe()
- Line 12: input(type = input.source) → input.source()
- Line 13: security → request.security
- Line 14: input(type = input.integer) → input.int()
- Line 15: input(type = input.source) → input.source()
11 more edits
- Line 18: input(type = input.bool) → input.bool()
- Line 19: input(type = input.bool) → input.bool()
- Line 20: input(type = input.bool) → input.bool()
- Line 21: input(type = input.bool) → input.bool()
- Line 24: input(type = input.bool) → input.bool()
- Line 26: sma → ta.sma
- Line 27: iff(c, a, b) → (c ? a : b)
- Line 28: iff(c, a, b) → (c ? a : b)
- Line 33: iff(c, a, b) → (c ? a : b)
- Line 34: iff(c, a, b) → (c ? a : b)
- Line 35: iff(c, a, b) → (c ? a : b)
⋯// - This script to change bars colors-//@version=4+//@version=5timeinrange(res, sess) => not na(time(res, sess)) ? 1 : 0strategy(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)TakeProfit = input(50, title="Take Profit", step=0.01)StopLoss = input(20, title="Stop Loss", step=0.01)-UseTPSL = input(title="Use Take\Stop", type=input.bool, defval=false)+UseTPSL = input.bool(title="Use Take\Stop", defval=false)-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)timeframe = input(title="Time Frame", defval="15")timerange = input(title="Time Range", defval="2300-0800")-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(pos[1] != pos,- iff(reverse and pos == 1, -1,- iff(reverse and pos == -1, 1, pos)), 0)+possig =(pos[1] != pos ? (reverse and pos == 1 ? -1 : (reverse and pos == -1 ? 1 : pos)) : 0)if (possig == 1 and timeinrange(timeframe, timerange))⋯Clean v5
VerifiedSame 138 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 16: input() → input.int()
- Line 17: input() → input.int()
- Line 22: input() → input.string()
- Line 23: input() → input.string()
- Line 40: when = high > strategy.position_avg_price + TakeProfit → if block
- Line 41: when = low < strategy.position_avg_price - StopLoss → if block
- Line 42: when = low < strategy.position_avg_price - TakeProfit → if block
- Line 43: when = high > strategy.position_avg_price + StopLoss → if block
⋯TriggerPrice = input.source(title="Trigger Price", defval=close)-TakeProfit = input(50, title="Take Profit", step=0.01)+TakeProfit = input.int(50, title="Take Profit", step=0.01)-StopLoss = input(20, title="Stop Loss", step=0.01)+StopLoss = input.int(20, title="Stop Loss", step=0.01)UseTPSL = input.bool(title="Use Take\Stop", defval=false)⋯UseAlerts = input.bool(title="Use Alerts", defval=false)-timeframe = input(title="Time Frame", defval="15")+timeframe = input.string(title="Time Frame", defval="15")-timerange = input(title="Time Range", defval="2300-0800")+timerange = input.string(title="Time Range", defval="2300-0800")reverse = input.bool(title="Trade Reverse", defval=false)⋯if (UseTPSL) - strategy.close("Long", when = high > strategy.position_avg_price + TakeProfit, comment = "close buy take profit")+ if high > strategy.position_avg_price + TakeProfit+ strategy.close("Long", comment = "close buy take profit")- strategy.close("Long", when = low < strategy.position_avg_price - StopLoss, comment = "close buy stop loss")+ if low < strategy.position_avg_price - StopLoss+ strategy.close("Long", comment = "close buy stop loss")- strategy.close("Short", when = low < strategy.position_avg_price - TakeProfit, comment = "close buy take profit")+ if low < strategy.position_avg_price - TakeProfit+ strategy.close("Short", comment = "close buy take profit")- strategy.close("Short", when = high > strategy.position_avg_price + StopLoss, comment = "close buy stop loss")+ if high > strategy.position_avg_price + StopLoss+ strategy.close("Short", comment = "close buy stop loss")nColor = BarColors ? strategy.position_avg_price != 0 and pos == 1 ? color.green :strategy.position_avg_price != 0 and pos == -1 ? color.red : color.blue : na⋯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, 107 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=6timeinrange(res, sess) => not na(time(res, sess)) ? 1 : 0⋯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 |
| Take Profit | 50 | int · step 0.01 | close Long close Short |
| Stop Loss | 20 | int · step 0.01 | close Long close Short |
| Use Take\Stop | false | bool | close Long close Long close Short close Short line 42 |
| Painting bars | true | bool | nColor |
| Show Line | true | bool | nRes |
| Use Alerts | false | bool | Signal Buy Signal Sell FLAT |
| Time Frame | 15 | string | entry Long entry Short close_all line 36 line 38 line 40 |
| Time Range | 2300-0800 | string | entry Long entry Short close_all line 36 line 38 line 40 |
| Trade Reverse | false | bool | possig |
What it calculates
- SMA (
sma,ta.smain v5)xSeries, Length (14)xSMA · line 26
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 and timeinrange(timeframe, timerange)) | On | 37 |
| Open Short short | (possig == -1 and timeinrange(timeframe, timerange)) | On | 39 |
| Close | (timeinrange(timeframe, timerange) == 0) | On | 41 |
| Close Long | high > strategy.position_avg_price + TakeProfit | On | 43 |
| Close Long | low < strategy.position_avg_price - StopLoss | On | 44 |
| Close Short | low < strategy.position_avg_price - TakeProfit | On | 45 |
| Close Short | high > strategy.position_avg_price + StopLoss | On | 46 |
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 | 30 |
| Signal Sell | alertcondition | Strategy to change to SELL | 31 |
| FLAT | alertcondition | Strategy get out from position | 32 |
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 | +13.3% | +102.5% | 114 | 48% | 1.13 | 20.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.0% | +5.5% | 30 | 57% | 0.68 | 3.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.5% | +9.8% | 119 | 37% | 0.79 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.1% | +8.4% | 37 | 43% | 0.84 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.2% | +16.7% | 97 | 57% | 1.87 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 30 | 40% | 0.60 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 114 | 43% | 0.89 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 27 | 37% | 0.49 | 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 | 42 | 48% | −$316.44 |
| Sideways market | 46 | 50% | $10,232.70 |
| Falling market | 26 | 46% | $3,336.69 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
29.8%
The 95th percentile of the worst drawdown when the same 114 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 13.7% to 29.8%; the tick is what actually happened, 19.1%. Order luck alone moves it this much.
All 114 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 9 Feb 2024 45,288.70 | 11 Feb 2024 47,751.10 | 2 | $2,462.42 |
| short | 24 Feb 2024 50,744.20 | 25 Feb 2024 51,568.20 | 1 | −$824.06 |
| long | 26 Mar 2024 69,880.00 | 31 Mar 2024 69,582.20 | 5 | −$297.83 |
| 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 |
| short | 13 Apr 2024 67,116.50 | 14 Apr 2024 63,924.50 | 1 | $3,192.00 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$2,529.74 |
| short | 25 Apr 2024 64,289.60 | 28 Apr 2024 63,462.00 | 3 | $827.60 |
| 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 | 12 May 2024 60,826.00 | 1 | −$26.00 |
| 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 | 19 May 2024 66,915.20 | 3 | $708.69 |
| short | 30 May 2024 67,652.40 | 2 Jun 2024 67,766.80 | 3 | −$114.43 |
| long | 4 Jun 2024 68,809.90 | 9 Jun 2024 69,310.50 | 5 | $500.57 |
| short | 12 Jun 2024 67,314.20 | 16 Jun 2024 66,228.30 | 4 | $1,085.98 |
| long | 2 Jul 2024 62,900.00 | 3 Jul 2024 62,135.50 | 1 | −$764.54 |
| short | 3 Jul 2024 62,135.50 | 7 Jul 2024 58,230.10 | 4 | $3,905.33 |
| short | 31 Jul 2024 66,188.00 | 4 Aug 2024 60,698.00 | 4 | $5,490.01 |
| 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 | 18 Aug 2024 59,492.00 | 1 | $617.40 |
| 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 | 25 Aug 2024 64,157.00 | 3 | $3,000.99 |
| short | 28 Aug 2024 59,415.00 | 1 Sep 2024 58,974.00 | 4 | $441.00 |
| long | 11 Sep 2024 57,636.00 | 15 Sep 2024 59,993.00 | 4 | $2,357.03 |
| short | 1 Oct 2024 63,327.60 | 6 Oct 2024 62,058.00 | 5 | $1,269.59 |
| long | 12 Oct 2024 62,540.00 | 13 Oct 2024 63,206.20 | 1 | $666.24 |
| short | 26 Oct 2024 66,698.30 | 27 Oct 2024 67,092.80 | 1 | −$394.44 |
| long | 6 Nov 2024 69,372.00 | 10 Nov 2024 76,677.50 | 4 | $7,305.45 |
| short | 27 Nov 2024 91,965.20 | 28 Nov 2024 95,863.10 | 1 | −$3,897.95 |
| long | 28 Nov 2024 95,863.10 | 1 Dec 2024 96,408.00 | 3 | $544.88 |
| short | 3 Dec 2024 95,840.60 | 5 Dec 2024 98,587.30 | 2 | −$2,746.71 |
| long | 5 Dec 2024 98,587.30 | 8 Dec 2024 99,832.00 | 3 | $1,244.67 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$4,532.00 |
| long | 12 Dec 2024 101,125.00 | 15 Dec 2024 101,420.00 | 3 | $295.00 |
| short | 19 Dec 2024 100,204.00 | 22 Dec 2024 97,292.00 | 3 | $2,912.01 |
| long | 3 Jan 2025 96,984.80 | 5 Jan 2025 98,220.50 | 2 | $1,235.72 |
| short | 9 Jan 2025 95,060.60 | 12 Jan 2025 94,600.00 | 3 | $460.62 |
| long | 15 Jan 2025 96,560.90 | 19 Jan 2025 104,556.00 | 4 | $7,995.38 |
| 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 | 2 Feb 2025 100,636.00 | 1 | $1,793.90 |
| long | 20 Feb 2025 96,644.40 | 22 Feb 2025 96,182.00 | 2 | −$462.38 |
| short | 22 Feb 2025 96,182.00 | 23 Feb 2025 96,551.00 | 1 | −$369.02 |
| 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 | 9 Mar 2025 86,222.50 | 1 | $579.28 |
| long | 20 Mar 2025 86,845.90 | 23 Mar 2025 83,840.60 | 3 | −$3,005.34 |
| short | 29 Mar 2025 84,424.40 | 30 Mar 2025 82,648.50 | 1 | $1,775.85 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$2,642.07 |
| short | 3 Apr 2025 82,516.30 | 6 Apr 2025 83,538.00 | 3 | −$1,021.71 |
| 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 | 13 Apr 2025 85,276.90 | 1 | $1,853.08 |
| short | 30 May 2025 105,590.00 | 1 Jun 2025 104,592.00 | 2 | $997.87 |
| 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 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$2,243.36 |
| short | 18 Jun 2025 104,551.00 | 22 Jun 2025 102,120.00 | 4 | $2,431.15 |
| long | 24 Jun 2025 105,334.00 | 29 Jun 2025 107,297.00 | 5 | $1,962.85 |
| short | 25 Jul 2025 118,341.00 | 27 Jul 2025 117,920.00 | 2 | $420.99 |
| short | 29 Jul 2025 118,062.00 | 3 Aug 2025 112,546.00 | 5 | $5,515.97 |
| long | 8 Aug 2025 117,472.00 | 10 Aug 2025 116,462.00 | 2 | −$1,009.77 |
| long | 4 Sep 2025 111,706.00 | 5 Sep 2025 110,731.00 | 1 | −$974.85 |
| short | 5 Sep 2025 110,731.00 | 7 Sep 2025 110,188.00 | 2 | $542.89 |
| short | 23 Sep 2025 112,651.00 | 28 Sep 2025 109,636.00 | 5 | $3,015.14 |
| long | 30 Sep 2025 114,312.00 | 5 Oct 2025 122,391.00 | 5 | $8,079.02 |
| short | 11 Oct 2025 112,774.00 | 12 Oct 2025 110,644.00 | 1 | $2,130.09 |
| long | 25 Oct 2025 111,005.00 | 26 Oct 2025 111,646.00 | 1 | $641.37 |
| short | 30 Oct 2025 110,021.00 | 2 Nov 2025 110,098.00 | 3 | −$76.80 |
| long | 28 Nov 2025 91,333.90 | 30 Nov 2025 90,802.40 | 2 | −$531.50 |
| 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 | 7 Dec 2025 89,236.80 | 1 | $93.24 |
| short | 13 Dec 2025 90,268.40 | 14 Dec 2025 90,240.00 | 1 | $28.43 |
| 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 | 4 Jan 2026 90,628.00 | 2 | $1,788.96 |
| short | 20 Jan 2026 92,631.00 | 25 Jan 2026 89,225.30 | 5 | $3,405.65 |
| long | 26 Feb 2026 67,988.00 | 27 Feb 2026 67,485.20 | 1 | −$502.85 |
| short | 27 Feb 2026 67,485.20 | 1 Mar 2026 66,973.30 | 2 | $511.93 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$1,567.15 |
| long | 10 Mar 2026 68,432.20 | 15 Mar 2026 71,211.90 | 5 | $2,779.79 |
| short | 20 Mar 2026 69,930.00 | 22 Mar 2026 68,918.10 | 2 | $1,011.89 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$2,516.22 |
| short | 27 Mar 2026 68,820.30 | 29 Mar 2026 66,377.00 | 2 | $2,443.27 |
| short | 29 Apr 2026 76,342.80 | 2 May 2026 78,231.10 | 3 | −$1,888.35 |
| long | 2 May 2026 78,231.10 | 3 May 2026 78,686.80 | 1 | $455.71 |
| 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 | 17 May 2026 78,148.10 | 1 | $965.15 |
| short | 19 Jun 2026 62,958.00 | 21 Jun 2026 64,298.00 | 2 | −$1,340.00 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$1,285.44 |
| short | 24 Jun 2026 62,734.60 | 28 Jun 2026 60,029.00 | 4 | $2,705.56 |
| long | 3 Jul 2026 61,560.00 | 5 Jul 2026 63,144.00 | 2 | $1,584.01 |
| short | 14 Jul 2026 62,334.50 | 15 Jul 2026 65,044.00 | 1 | −$2,709.47 |
| long | 15 Jul 2026 65,044.00 | 19 Jul 2026 64,834.20 | 4 | −$209.78 |
| short | 25 Jul 2026 64,140.00 | 26 Jul 2026 64,375.00 | 1 | −$235.01 |
| 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 | 2 Aug 2026 62,823.70 | 1 | $64.23 |
| long | 6 Aug 2026 64,665.20 | 9 Aug 2026 64,962.60 | 3 | $297.36 |
| short | 11 Aug 2026 63,970.00 | 16 Aug 2026 63,086.00 | 5 | $884.00 |
| long | 18 Aug 2026 64,532.10 | 23 Aug 2026 77,074.90 | 5 | $12,542.80 |
| short | 3 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 1 | −$3,930.36 |
| long | 4 Sep 2026 81,270.40 | 6 Sep 2026 79,831.80 | 2 | −$1,438.62 |
| short | 9 Sep 2026 78,455.80 | 13 Sep 2026 77,278.70 | 4 | $1,177.07 |
| long | 19 Sep 2026 80,883.90 | 20 Sep 2026 81,250.00 | 1 | $366.13 |
| short | 8 Oct 2026 83,321.80 | 11 Oct 2026 82,988.40 | 3 | $333.46 |
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 Part 5 this page | — | v4 strategy | +13.3% | 114 | 20.8% |
| 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 19 ms | Yes 1,000 bars in 59 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=4timeinrange(res, sess) => not na(time(res, sess)) ? 1 : 0strategy(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)TakeProfit = input(50, title="Take Profit", step=0.01)StopLoss = input(20, title="Stop Loss", step=0.01)UseTPSL = input(title="Use Take\Stop", type=input.bool, defval=false)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)timeframe = input(title="Time Frame", defval="15")timerange = input(title="Time Range", defval="2300-0800")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(pos[1] != pos, iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos)), 0)if (possig == 1 and timeinrange(timeframe, timerange)) strategy.entry("Long", strategy.long)if (possig == -1 and timeinrange(timeframe, timerange)) strategy.entry("Short", strategy.short)if (timeinrange(timeframe, timerange) == 0) strategy.close_all()if (UseTPSL) strategy.close("Long", when = high > strategy.position_avg_price + TakeProfit, comment = "close buy take profit") strategy.close("Long", when = low < strategy.position_avg_price - StopLoss, comment = "close buy stop loss") strategy.close("Short", when = low < strategy.position_avg_price - TakeProfit, comment = "close buy take profit") strategy.close("Short", when = high > strategy.position_avg_price + StopLoss, comment = "close buy stop loss")nColor = BarColors ? strategy.position_avg_price != 0 and pos == 1 ? color.green :strategy.position_avg_price != 0 and pos == -1 ? color.red : color.blue : nabarcolor(nColor)plot(nRes, title='SMA', color=#00ffaa, linewidth=2, style=plot.style_line)