Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$114,928$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
+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

Differs

Trades 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

Verified

Same 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.

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 42
Painting barstrueboolnColor
Show LinetrueboolnRes
Use AlertsfalseboolSignal Buy Signal Sell FLAT
Time Frame15stringentry Long entry Short close_all line 36 line 38 line 40
Time Range2300-0800stringentry Long entry Short close_all line 36 line 38 line 40
Trade Reversefalseboolpossig

What it calculates

  • SMA (sma, ta.sma in 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.

LengthLengthsetting · 14closecloseprice dataResolutionResolutionsetting · DtimeframeTime Framesetting · 15timerangeTime Rangesetting · 2300-0800lowlowprice datahighhighprice dataTakeProfitTake Profitsetting · 50StopLossStop Losssetting · 20xSMASMA→ xSMAxSeriesxSeriesvaluenResnResvaluepossigpossigconditionposposconditionnColorColournColorentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose_all:close_all strategy.close_allclose:LongClose Longstrategy.closeclose:ShortClose Shortstrategy.closealertcondition:30Signal Buyalertconditionalertcondition:31Signal Sellalertconditionalertcondition:32FLATalertconditionbarcolor:48barcolorbarcolorplot:49SMAplot

Order rules

OrderFires whenBy defaultLine
Open Long long(possig == 1 and timeinrange(timeframe, timerange))On37
Open Short short(possig == -1 and timeinrange(timeframe, timerange))On39
Close (timeinrange(timeframe, timerange) == 0)On41
Close Longhigh > strategy.position_avg_price + TakeProfitOn43
Close Longlow < strategy.position_avg_price - StopLossOn44
Close Shortlow < strategy.position_avg_price - TakeProfitOn45
Close Shorthigh > strategy.position_avg_price + StopLossOn46

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 BUY30
Signal SellalertconditionStrategy to change to SELL31
FLATalertconditionStrategy get out from position32

Does it repaint?

No

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

35/35trades 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+13.3%+102.5%11448%1.1320.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−2.0%+5.5%3057%0.683.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.5%+9.8%11937%0.792.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.1%+8.4%3743%0.840.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.2%+16.7%9757%1.870.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%3040%0.600.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.1%+148.3%11443%0.890.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%2737%0.490.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market4248%−$316.44
Sideways market4650%$10,232.70
Falling market2646%$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.

0%34%
All 114 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.7011 Feb 2024 47,751.102$2,462.42
short24 Feb 2024 50,744.2025 Feb 2024 51,568.201−$824.06
long26 Mar 2024 69,880.0031 Mar 2024 69,582.205−$297.83
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
short13 Apr 2024 67,116.5014 Apr 2024 63,924.501$3,192.00
long23 Apr 2024 66,819.3025 Apr 2024 64,289.602−$2,529.74
short25 Apr 2024 64,289.6028 Apr 2024 63,462.003$827.60
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.0012 May 2024 60,826.001−$26.00
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.5019 May 2024 66,915.203$708.69
short30 May 2024 67,652.402 Jun 2024 67,766.803−$114.43
long4 Jun 2024 68,809.909 Jun 2024 69,310.505$500.57
short12 Jun 2024 67,314.2016 Jun 2024 66,228.304$1,085.98
long2 Jul 2024 62,900.003 Jul 2024 62,135.501−$764.54
short3 Jul 2024 62,135.507 Jul 2024 58,230.104$3,905.33
short31 Jul 2024 66,188.004 Aug 2024 60,698.004$5,490.01
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.6018 Aug 2024 59,492.001$617.40
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.0025 Aug 2024 64,157.003$3,000.99
short28 Aug 2024 59,415.001 Sep 2024 58,974.004$441.00
long11 Sep 2024 57,636.0015 Sep 2024 59,993.004$2,357.03
short1 Oct 2024 63,327.606 Oct 2024 62,058.005$1,269.59
long12 Oct 2024 62,540.0013 Oct 2024 63,206.201$666.24
short26 Oct 2024 66,698.3027 Oct 2024 67,092.801−$394.44
long6 Nov 2024 69,372.0010 Nov 2024 76,677.504$7,305.45
short27 Nov 2024 91,965.2028 Nov 2024 95,863.101−$3,897.95
long28 Nov 2024 95,863.101 Dec 2024 96,408.003$544.88
short3 Dec 2024 95,840.605 Dec 2024 98,587.302−$2,746.71
long5 Dec 2024 98,587.308 Dec 2024 99,832.003$1,244.67
short11 Dec 2024 96,593.0012 Dec 2024 101,125.001−$4,532.00
long12 Dec 2024 101,125.0015 Dec 2024 101,420.003$295.00
short19 Dec 2024 100,204.0022 Dec 2024 97,292.003$2,912.01
long3 Jan 2025 96,984.805 Jan 2025 98,220.502$1,235.72
short9 Jan 2025 95,060.6012 Jan 2025 94,600.003$460.62
long15 Jan 2025 96,560.9019 Jan 2025 104,556.004$7,995.38
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.002 Feb 2025 100,636.001$1,793.90
long20 Feb 2025 96,644.4022 Feb 2025 96,182.002−$462.38
short22 Feb 2025 96,182.0023 Feb 2025 96,551.001−$369.02
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.709 Mar 2025 86,222.501$579.28
long20 Mar 2025 86,845.9023 Mar 2025 83,840.603−$3,005.34
short29 Mar 2025 84,424.4030 Mar 2025 82,648.501$1,775.85
long2 Apr 2025 85,158.403 Apr 2025 82,516.301−$2,642.07
short3 Apr 2025 82,516.306 Apr 2025 83,538.003−$1,021.71
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.8013 Apr 2025 85,276.901$1,853.08
short30 May 2025 105,590.001 Jun 2025 104,592.002$997.87
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
long17 Jun 2025 106,795.0018 Jun 2025 104,551.001−$2,243.36
short18 Jun 2025 104,551.0022 Jun 2025 102,120.004$2,431.15
long24 Jun 2025 105,334.0029 Jun 2025 107,297.005$1,962.85
short25 Jul 2025 118,341.0027 Jul 2025 117,920.002$420.99
short29 Jul 2025 118,062.003 Aug 2025 112,546.005$5,515.97
long8 Aug 2025 117,472.0010 Aug 2025 116,462.002−$1,009.77
long4 Sep 2025 111,706.005 Sep 2025 110,731.001−$974.85
short5 Sep 2025 110,731.007 Sep 2025 110,188.002$542.89
short23 Sep 2025 112,651.0028 Sep 2025 109,636.005$3,015.14
long30 Sep 2025 114,312.005 Oct 2025 122,391.005$8,079.02
short11 Oct 2025 112,774.0012 Oct 2025 110,644.001$2,130.09
long25 Oct 2025 111,005.0026 Oct 2025 111,646.001$641.37
short30 Oct 2025 110,021.002 Nov 2025 110,098.003−$76.80
long28 Nov 2025 91,333.9030 Nov 2025 90,802.402−$531.50
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.007 Dec 2025 89,236.801$93.24
short13 Dec 2025 90,268.4014 Dec 2025 90,240.001$28.43
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.104 Jan 2026 90,628.002$1,788.96
short20 Jan 2026 92,631.0025 Jan 2026 89,225.305$3,405.65
long26 Feb 2026 67,988.0027 Feb 2026 67,485.201−$502.85
short27 Feb 2026 67,485.201 Mar 2026 66,973.302$511.93
long3 Mar 2026 68,830.108 Mar 2026 67,262.905−$1,567.15
long10 Mar 2026 68,432.2015 Mar 2026 71,211.905$2,779.79
short20 Mar 2026 69,930.0022 Mar 2026 68,918.102$1,011.89
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,516.22
short27 Mar 2026 68,820.3029 Mar 2026 66,377.002$2,443.27
short29 Apr 2026 76,342.802 May 2026 78,231.103−$1,888.35
long2 May 2026 78,231.103 May 2026 78,686.801$455.71
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.2017 May 2026 78,148.101$965.15
short19 Jun 2026 62,958.0021 Jun 2026 64,298.002−$1,340.00
long23 Jun 2026 64,020.0024 Jun 2026 62,734.601−$1,285.44
short24 Jun 2026 62,734.6028 Jun 2026 60,029.004$2,705.56
long3 Jul 2026 61,560.005 Jul 2026 63,144.002$1,584.01
short14 Jul 2026 62,334.5015 Jul 2026 65,044.001−$2,709.47
long15 Jul 2026 65,044.0019 Jul 2026 64,834.204−$209.78
short25 Jul 2026 64,140.0026 Jul 2026 64,375.001−$235.01
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.902 Aug 2026 62,823.701$64.23
long6 Aug 2026 64,665.209 Aug 2026 64,962.603$297.36
short11 Aug 2026 63,970.0016 Aug 2026 63,086.005$884.00
long18 Aug 2026 64,532.1023 Aug 2026 77,074.905$12,542.80
short3 Sep 2026 77,340.004 Sep 2026 81,270.401−$3,930.36
long4 Sep 2026 81,270.406 Sep 2026 79,831.802−$1,438.62
short9 Sep 2026 78,455.8013 Sep 2026 77,278.704$1,177.07
long19 Sep 2026 80,883.9020 Sep 2026 81,250.001$366.13
short8 Oct 2026 83,321.8011 Oct 2026 82,988.403$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.

ScriptSharesTypeNetTradesMax drawdown
Simple SMA Strategy Backtest Part 5 this page—v4 strategy+13.3%11420.8%
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 19 msYes 1,000 bars in 59 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=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)