Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Simple SMA Strategy Backtest Part 4

A Pine Script v4 strategy built on SMA (xSeries, 14). It has 6 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. 11 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 4 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 Part 4 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 Part 4 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 Part 4 have?
3
Signal Buy; Signal Sell; FLAT.
Does Simple SMA Strategy Backtest Part 4 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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (11)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$158,474$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.
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 an argument v6 removed

    when = on line 39, 40, 41, 42. The upgraded version below moves each call inside an if block.

  • Note

    Uses iff(), which v5 removed line 24

    iff() on line 24, 25, 30, 31, 32. 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 39, 40, 41, 42). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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()
11 more edits
  • Line 17: input(type = input.bool) → input.bool()
  • 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 23: sma → ta.sma
  • Line 24: iff(c, a, b) → (c ? a : b)
  • Line 25: iff(c, a, b) → (c ? a : b)
  • Line 30: iff(c, a, b) → (c ? a : b)
  • Line 31: iff(c, a, b) → (c ? a : b)
  • Line 32: 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)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)-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)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 15: input() → input.int()
  • Line 16: input() → input.int()
  • Line 36: when = high > strategy.position_avg_price + TakeProfit → if block
  • Line 37: when = low < strategy.position_avg_price - StopLoss → if block
  • Line 38: when = low < strategy.position_avg_price - TakeProfit → if block
  • Line 39: 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)⋯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=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.

SettingDefaultType and rangeFeeds
ResolutionDtimeframe (written input.resolution)xSeries
SourceclosesourcexSeries
Length14int (written input.integer) · min 2xSMA
Trigger Priceclosesourcepos
Take Profit50int · step 0.01close Long close Short
Stop Loss20int · step 0.01close Long close Short
Use Take\Stopfalseboolclose Long close Long close Short close Short line 38
Painting barstrueboolnColor
Show LinetrueboolnRes
Use AlertsfalseboolSignal Buy Signal Sell FLAT
Trade Reversefalseboolpossig

What it calculates

  • SMA (sma, ta.sma in v5)xSeries, Length (14)xSMA · line 23

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.

LengthLengthsetting · 14closecloseprice dataResolutionResolutionsetting · Dlowlowprice datahighhighprice dataTakeProfitTake Profitsetting · 50StopLossStop Losssetting · 20xSMASMA→ xSMAxSeriesxSeriesvaluenResnResvaluepossigpossigconditionposposconditionnColorColournColorentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:LongClose Longstrategy.closeclose:ShortClose Shortstrategy.closealertcondition:27Signal Buyalertconditionalertcondition:28Signal Sellalertconditionalertcondition:29FLATalertconditionbarcolor:44barcolorbarcolorplot:45SMAplot

Order rules

OrderFires whenBy defaultLine
Open Long long(possig == 1)On34
Open Short short(possig == -1)On36
Close Longhigh > strategy.position_avg_price + TakeProfitOn39
Close Longlow < strategy.position_avg_price - StopLossOn40
Close Shortlow < strategy.position_avg_price - TakeProfitOn41
Close Shorthigh > strategy.position_avg_price + StopLossOn42

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Signal BuyalertconditionStrategy to change to BUY27
Signal SellalertconditionStrategy to change to SELL28
FLATalertconditionStrategy get out from position29

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

42/42trades 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 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+56.8%+102.5%13828%1.3328.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−9.9%+5.5%12623%0.8516.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.5%+9.8%14524%0.963.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.4%+8.4%14821%0.851.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%12534%1.230.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%11429%1.020.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%14630%0.920.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%13624%0.860.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 barsTradesWonP&L
Rising market5024%−$3,371.93
Sideways market5636%$46,509.70
Falling market3219%$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.

0%44%
All 138 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.7024 Feb 2024 50,744.2015$5,455.49
short24 Feb 2024 50,744.2025 Feb 2024 51,568.201−$824.06
long25 Feb 2024 51,568.2017 Mar 2024 65,300.6021$13,732.40
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.005 Apr 2024 68,487.802−$3,023.81
long5 Apr 2024 68,487.806 Apr 2024 67,820.601−$667.17
short6 Apr 2024 67,820.607 Apr 2024 68,896.001−$1,075.37
long7 Apr 2024 68,896.0013 Apr 2024 67,116.506−$1,779.48
short13 Apr 2024 67,116.5023 Apr 2024 66,819.3010$297.20
long23 Apr 2024 66,819.3025 Apr 2024 64,289.602−$2,529.74
short25 Apr 2024 64,289.605 May 2024 63,892.0010$397.55
long5 May 2024 63,892.008 May 2024 62,312.103−$1,579.96
short8 May 2024 62,312.1010 May 2024 63,074.002−$761.93
long10 May 2024 63,074.0011 May 2024 60,800.001−$2,274.01
short11 May 2024 60,800.0014 May 2024 62,940.103−$2,140.10
long14 May 2024 62,940.1015 May 2024 61,577.501−$1,362.60
short15 May 2024 61,577.5016 May 2024 66,206.501−$4,629.02
long16 May 2024 66,206.5030 May 2024 67,652.4014$1,445.90
short30 May 2024 67,652.404 Jun 2024 68,809.905−$1,157.48
long4 Jun 2024 68,809.9012 Jun 2024 67,314.208−$1,495.66
short12 Jun 2024 67,314.202 Jul 2024 62,900.0020$4,414.23
long2 Jul 2024 62,900.003 Jul 2024 62,135.501−$764.54
short3 Jul 2024 62,135.5014 Jul 2024 59,204.0011$2,931.45
long14 Jul 2024 59,204.0031 Jul 2024 66,188.0017$6,983.99
short31 Jul 2024 66,188.0014 Aug 2024 60,587.2014$5,600.84
long14 Aug 2024 60,587.2015 Aug 2024 58,683.401−$1,903.77
short15 Aug 2024 58,683.4017 Aug 2024 58,874.602−$191.20
long17 Aug 2024 58,874.6019 Aug 2024 58,427.302−$447.24
short19 Aug 2024 58,427.3020 Aug 2024 59,438.501−$1,011.15
long20 Aug 2024 59,438.5021 Aug 2024 59,013.801−$424.70
short21 Aug 2024 59,013.8022 Aug 2024 61,156.001−$2,142.23
long22 Aug 2024 61,156.0028 Aug 2024 59,415.006−$1,741.03
short28 Aug 2024 59,415.0011 Sep 2024 57,636.0014$1,779.01
long11 Sep 2024 57,636.001 Oct 2024 63,327.6020$5,691.61
short1 Oct 2024 63,327.6012 Oct 2024 62,540.0011$787.61
long12 Oct 2024 62,540.0026 Oct 2024 66,698.3014$4,158.33
short26 Oct 2024 66,698.3028 Oct 2024 68,021.702−$1,323.37
long28 Oct 2024 68,021.704 Nov 2024 68,776.007$754.30
short4 Nov 2024 68,776.006 Nov 2024 69,372.002−$596.02
long6 Nov 2024 69,372.0027 Nov 2024 91,965.2021$22,593.20
short27 Nov 2024 91,965.2028 Nov 2024 95,863.101−$3,897.95
long28 Nov 2024 95,863.103 Dec 2024 95,840.605−$22.50
short3 Dec 2024 95,840.605 Dec 2024 98,587.302−$2,746.71
long5 Dec 2024 98,587.3011 Dec 2024 96,593.006−$1,994.32
short11 Dec 2024 96,593.0012 Dec 2024 101,125.001−$4,532.00
long12 Dec 2024 101,125.0019 Dec 2024 100,204.007−$920.99
short19 Dec 2024 100,204.003 Jan 2025 96,984.8015$3,219.22
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.9028 Jan 2025 102,083.0013$5,521.98
short28 Jan 2025 102,083.0030 Jan 2025 103,733.002−$1,650.42
long30 Jan 2025 103,733.001 Feb 2025 102,430.002−$1,303.69
short1 Feb 2025 102,430.0016 Feb 2025 97,569.7015$4,859.89
long16 Feb 2025 97,569.7017 Feb 2025 96,118.101−$1,451.55
short17 Feb 2025 96,118.1020 Feb 2025 96,644.403−$526.25
long20 Feb 2025 96,644.4022 Feb 2025 96,182.002−$462.38
short22 Feb 2025 96,182.003 Mar 2025 94,270.009$1,912.00
long3 Mar 2025 94,270.004 Mar 2025 86,221.201−$8,048.83
short4 Mar 2025 86,221.206 Mar 2025 90,606.002−$4,384.84
long6 Mar 2025 90,606.008 Mar 2025 86,801.702−$3,804.26
short8 Mar 2025 86,801.7020 Mar 2025 86,845.9012−$44.19
long20 Mar 2025 86,845.9029 Mar 2025 84,424.409−$2,421.55
short29 Mar 2025 84,424.402 Apr 2025 85,158.404−$733.97
long2 Apr 2025 85,158.403 Apr 2025 82,516.301−$2,642.07
short3 Apr 2025 82,516.3010 Apr 2025 82,615.207−$98.94
long10 Apr 2025 82,615.2011 Apr 2025 79,607.301−$3,007.92
short11 Apr 2025 79,607.3012 Apr 2025 83,423.801−$3,816.53
long12 Apr 2025 83,423.8030 May 2025 105,590.0048$22,165.90
short30 May 2025 105,590.009 Jun 2025 105,734.0010−$144.26
long9 Jun 2025 105,734.0013 Jun 2025 105,672.004−$62.27
short13 Jun 2025 105,672.0014 Jun 2025 106,067.001−$394.85
long14 Jun 2025 106,067.0015 Jun 2025 105,415.001−$651.96
short15 Jun 2025 105,415.0017 Jun 2025 106,795.002−$1,379.90
long17 Jun 2025 106,795.0018 Jun 2025 104,551.001−$2,243.36
short18 Jun 2025 104,551.0024 Jun 2025 105,334.006−$782.77
long24 Jun 2025 105,334.0025 Jul 2025 118,341.0031$13,007.00
short25 Jul 2025 118,341.0028 Jul 2025 119,416.003−$1,074.58
long28 Jul 2025 119,416.0029 Jul 2025 118,062.001−$1,353.24
short29 Jul 2025 118,062.008 Aug 2025 117,472.0010$590.30
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.005 Sep 2025 110,731.001−$974.85
short5 Sep 2025 110,731.008 Sep 2025 111,137.003−$406.48
long8 Sep 2025 111,137.0023 Sep 2025 112,651.0015$1,513.64
short23 Sep 2025 112,651.0030 Sep 2025 114,312.007−$1,660.98
long30 Sep 2025 114,312.0011 Oct 2025 112,774.0011−$1,537.48
short11 Oct 2025 112,774.0025 Oct 2025 111,005.0014$1,769.59
long25 Oct 2025 111,005.0030 Oct 2025 110,021.005−$983.60
short30 Oct 2025 110,021.0028 Nov 2025 91,333.9029$18,687.40
long28 Nov 2025 91,333.902 Dec 2025 86,286.004−$5,047.93
short2 Dec 2025 86,286.003 Dec 2025 91,277.901−$4,991.87
long3 Dec 2025 91,277.906 Dec 2025 89,330.003−$1,947.84
short6 Dec 2025 89,330.008 Dec 2025 90,395.302−$1,065.28
long8 Dec 2025 90,395.3013 Dec 2025 90,268.405−$126.89
short13 Dec 2025 90,268.4028 Dec 2025 87,877.0015$2,391.43
long28 Dec 2025 87,877.0030 Dec 2025 87,237.102−$639.87
short30 Dec 2025 87,237.1031 Dec 2025 88,485.501−$1,248.37
long31 Dec 2025 88,485.501 Jan 2026 87,648.201−$837.29
short1 Jan 2026 87,648.202 Jan 2026 88,839.101−$1,190.84
long2 Jan 2026 88,839.1020 Jan 2026 92,631.0018$3,791.94
short20 Jan 2026 92,631.0026 Feb 2026 67,988.0037$24,643.00
long26 Feb 2026 67,988.0027 Feb 2026 67,485.201−$502.85
short27 Feb 2026 67,485.203 Mar 2026 68,830.104−$1,344.87
long3 Mar 2026 68,830.108 Mar 2026 67,262.905−$1,567.15
short8 Mar 2026 67,262.9010 Mar 2026 68,432.202−$1,169.25
long10 Mar 2026 68,432.2020 Mar 2026 69,930.0010$1,497.85
short20 Mar 2026 69,930.0026 Mar 2026 71,336.506−$1,406.52
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,516.22
short27 Mar 2026 68,820.306 Apr 2026 69,034.2010−$213.87
long6 Apr 2026 69,034.2029 Apr 2026 76,342.8023$7,308.60
short29 Apr 2026 76,342.802 May 2026 78,231.103−$1,888.35
long2 May 2026 78,231.1014 May 2026 79,313.6012$1,082.48
short14 May 2026 79,313.6015 May 2026 81,090.001−$1,776.39
long15 May 2026 81,090.0016 May 2026 79,113.201−$1,976.80
short16 May 2026 79,113.2015 Jun 2026 65,746.4030$13,366.80
long15 Jun 2026 65,746.4019 Jun 2026 62,958.004−$2,788.44
short19 Jun 2026 62,958.0021 Jun 2026 64,298.002−$1,340.00
long21 Jun 2026 64,298.0022 Jun 2026 63,312.001−$986.01
short22 Jun 2026 63,312.0023 Jun 2026 64,020.001−$708.01
long23 Jun 2026 64,020.0024 Jun 2026 62,734.601−$1,285.44
short24 Jun 2026 62,734.603 Jul 2026 61,560.009$1,174.57
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.0027 Jul 2026 65,400.002−$1,260.00
long27 Jul 2026 65,400.0028 Jul 2026 63,755.901−$1,644.14
short28 Jul 2026 63,755.9031 Jul 2026 64,780.003−$1,024.17
long31 Jul 2026 64,780.001 Aug 2026 62,887.901−$1,892.15
short1 Aug 2026 62,887.906 Aug 2026 64,665.205−$1,777.36
long6 Aug 2026 64,665.2011 Aug 2026 63,970.005−$695.23
short11 Aug 2026 63,970.0018 Aug 2026 64,532.107−$562.10
long18 Aug 2026 64,532.103 Sep 2026 77,340.0016$12,807.90
short3 Sep 2026 77,340.004 Sep 2026 81,270.401−$3,930.36
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.908 Oct 2026 83,321.8019$2,437.95
short8 Oct 2026 83,321.8021 Oct 2026 83,028.1013$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.

ScriptSharesTypeNetTradesMax drawdown
Simple SMA Strategy Backtest Part 4 this page—v4 strategy+56.8%13828.7%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 13 msYes 1,000 bars in 41 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/// © 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)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)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)    strategy.entry("Long", strategy.long)if (possig == -1)    strategy.entry("Short", strategy.short)    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)