Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

SPX Scalping Strategy

A Pine Script v5 strategy built on SMA (close, len1), Crossover (close, out1) and Crossunder (close, out1). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include SMA Source #1 close.

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 SPX Scalping Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 32 of 32 trades.
How did SPX Scalping Strategy do on BTCUSDT 1D with default settings?
+1.52%
From 26 Jan 2024 to 21 Oct 2026, over 109 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does SPX Scalping Strategy 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: 109 before, 58 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does SPX Scalping Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does SPX Scalping Strategy run in Zeal Terminal?
Yes
It compiles in 27 ms and runs 1,000 bars in 46 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA #1
  • Shape
  • Shape
  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,015,180$2,025,273Equity from $1,000,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
+1.52%
$15,187.70
Buy and hold
+102.5%
same period
Closed trades
109
35 won · 74 lost
Profitable
32.1%
of closed trades
Profit factor
1.12
gross profit ÷ gross loss
Max drawdown
4.97%
−$50,398.40

One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. 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

    1 setting does nothing

    “RSI” is declared but never read.

  • 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 66, 67. The upgraded version below moves each call inside an if block.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
SMA Source #1closesourceout1
RSItrueboolunused

What it calculates

  • SMASMA Source #1 (close), len1out1 · line 9
  • Crossoverclose, out1data_over · line 11
  • Crossunderclose, out1data_under · line 13
  • EMAclose, smash · line 23
  • EMAclose, lmalon · line 24
  • Lowest / HighestMac, npMacNorm · line 31
  • WMAMacNorm2, tspTrigger · line 38
  • RMA / Changemath.max(ta.change(src), 0), lenup · line 48
  • RMA / Change-math.min(ta.change(src), 0), lendown · line 49
  • SMArsi, srsmr · line 51

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.

closecloseprice dataout1SMA→ out1data_overCrossover→ data_overdata_underCrossunder→ data_undershEMA→ shlonEMA→ lonMacNormLowest / Highest→ MacNormTriggerWMA→ TriggerupRMA / Change→ updownRMA / Change→ downmrSMA→ mrratioratiovalueMacMacvalueMacNorm2MacNorm2valuesrcsrcvaluersirsivaluebuySignalbuySignalconditionshortSignalshortSignalconditionsellSignalsellSignalconditiondataO, dataUdataO · dataU2 conditionstrigger_above, trigger_undertrigger_above · trigger…2 conditionsrsi_above, rsi_underrsi_above · rsi_under2 conditionsentry:LONGOpen LONGstrategy.entryentry:SHORTOpen SHORTstrategy.entryclose:LONGClose LONGstrategy.closeclose:SHORTClose SHORTstrategy.closeplot:10SMA #1plotbgcolor:15bgcolorbgcolorbgcolor:16bgcolorbgcolorplotshape:41plotshapeplotshapeplotshape:42plotshapeplotshapebgcolor:57bgcolorbgcolorbgcolor:58bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open LONG long(buySignal)On62
Open SHORT short(shortSignal)On64
Close LONGsellSignalta.cross(close, out1) or ta.cross(Trigger, MacNorm2) or ta.cross(rsi, mr)On66
Close SHORTsellSignalta.cross(close, out1) or ta.cross(Trigger, MacNorm2) or ta.cross(rsi, mr)On67

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

Does it repaint?

No

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

32/32trades 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 dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.5%+102.5%10932%1.125.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.5%+5.5%10333%1.470.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.0%+9.8%11832%0.960.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%12425%1.040.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%11430%1.070.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%12027%0.960.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%11935%0.940.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%11632%1.260.0%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 market3537%−$8,990.73
Sideways market4538%$25,820.70
Falling market2917%−$1,642.23

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

5.2%

The 95th percentile of the worst drawdown when the same 109 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.2% to 5.2%; the tick is what actually happened, 4.9%. Order luck alone moves it this much.

0%6%
All 109 trades
SideEntryExitBarsP&L
short3 Apr 2024 65,464.007 Apr 2024 68,896.004−$3,432.01
short13 Apr 2024 67,116.5021 Apr 2024 64,940.608$2,175.94
short28 Apr 2024 63,462.004 May 2024 62,882.006$579.97
long6 May 2024 64,012.007 May 2024 63,165.201−$846.82
long14 May 2024 62,940.1015 May 2024 61,577.501−$1,362.60
long16 May 2024 66,206.5027 May 2024 68,507.7011$2,301.16
long28 May 2024 69,436.4029 May 2024 68,398.401−$1,038.03
long6 Jun 2024 71,108.009 Jun 2024 69,310.503−$1,797.54
short12 Jun 2024 67,314.201 Jul 2024 62,772.0019$4,542.22
short5 Jul 2024 57,050.0010 Jul 2024 58,050.005−$999.98
long14 Jul 2024 59,204.0025 Jul 2024 65,376.0011$6,172.00
long27 Jul 2024 67,908.0030 Jul 2024 66,784.703−$1,123.32
short3 Aug 2024 61,498.309 Aug 2024 61,686.006−$187.66
short12 Aug 2024 58,712.6013 Aug 2024 59,346.601−$634.05
long14 Aug 2024 60,587.2015 Aug 2024 58,683.401−$1,903.77
long22 Aug 2024 61,156.0028 Aug 2024 59,415.006−$1,741.03
short29 Aug 2024 59,034.9010 Sep 2024 57,042.0012$1,992.89
long13 Sep 2024 58,132.301 Oct 2024 63,327.6018$5,195.29
short2 Oct 2024 60,804.907 Oct 2024 62,819.905−$2,014.99
short8 Oct 2024 62,224.0012 Oct 2024 62,540.004−$315.98
long14 Oct 2024 62,870.0024 Oct 2024 66,668.6010$3,798.63
short26 Oct 2024 66,698.3027 Oct 2024 67,092.801−$394.44
long30 Oct 2024 72,736.402 Nov 2024 69,496.003−$3,240.41
short3 Nov 2024 69,374.707 Nov 2024 75,572.004−$6,197.25
long7 Nov 2024 75,572.0018 Nov 2024 89,856.0011$14,284.00
long22 Nov 2024 98,317.1024 Nov 2024 97,672.402−$644.72
short26 Nov 2024 93,010.0028 Nov 2024 95,863.102−$2,853.10
short3 Dec 2024 95,840.604 Dec 2024 95,849.701−$9.08
short10 Dec 2024 97,276.5012 Dec 2024 101,125.002−$3,848.52
long17 Dec 2024 106,059.0019 Dec 2024 100,204.002−$5,854.64
short19 Dec 2024 100,204.0026 Dec 2024 99,429.607$774.40
short27 Dec 2024 95,791.603 Jan 2025 96,984.807−$1,193.19
long7 Jan 2025 102,236.008 Jan 2025 96,954.601−$5,281.00
short10 Jan 2025 92,552.5015 Jan 2025 96,560.905−$4,008.36
long16 Jan 2025 100,497.0027 Jan 2025 102,620.0011$2,122.66
short29 Jan 2025 101,336.0030 Jan 2025 103,733.001−$2,397.73
short1 Feb 2025 102,430.0013 Feb 2025 97,870.0012$4,559.56
short14 Feb 2025 96,608.1015 Feb 2025 97,500.501−$892.34
short19 Feb 2025 95,671.7020 Feb 2025 96,644.401−$972.63
long21 Feb 2025 98,305.0022 Feb 2025 96,182.001−$2,123.02
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$2,717.11
long3 Mar 2025 94,270.004 Mar 2025 86,221.201−$8,048.83
short10 Mar 2025 80,734.5016 Mar 2025 84,338.406−$3,603.96
long16 Mar 2025 84,338.4017 Mar 2025 82,574.501−$1,763.92
long18 Mar 2025 84,010.0019 Mar 2025 82,715.001−$1,294.99
long20 Mar 2025 86,845.9029 Mar 2025 84,424.409−$2,421.55
short31 Mar 2025 82,390.002 Apr 2025 85,158.402−$2,768.35
short7 Apr 2025 78,430.0010 Apr 2025 82,615.203−$4,185.22
long12 Apr 2025 83,423.8030 Apr 2025 94,256.8018$10,833.00
long2 May 2025 96,489.904 May 2025 95,856.402−$633.48
long9 May 2025 103,262.0015 May 2025 103,508.006$246.22
long22 May 2025 109,644.0025 May 2025 107,762.003−$1,882.09
short29 May 2025 107,782.008 Jun 2025 105,552.0010$2,229.63
short14 Jun 2025 106,067.0024 Jun 2025 105,334.0010$732.65
long30 Jun 2025 108,357.001 Jul 2025 107,147.001−$1,210.42
long3 Jul 2025 108,850.005 Jul 2025 107,984.002−$865.34
long7 Jul 2025 109,204.008 Jul 2025 108,263.001−$940.91
long9 Jul 2025 108,923.0020 Jul 2025 117,840.0011$8,917.02
short29 Jul 2025 118,062.008 Aug 2025 117,472.0010$590.30
long11 Aug 2025 119,294.0012 Aug 2025 118,686.001−$608.27
long13 Aug 2025 120,134.0015 Aug 2025 118,295.002−$1,839.00
short16 Aug 2025 117,342.0023 Aug 2025 116,936.007$406.04
short24 Aug 2025 115,438.003 Sep 2025 111,240.0010$4,198.05
long11 Sep 2025 113,960.0020 Sep 2025 115,632.009$1,672.39
short23 Sep 2025 112,651.0030 Sep 2025 114,312.007−$1,660.98
long1 Oct 2025 114,049.0011 Oct 2025 112,774.0010−$1,274.45
short11 Oct 2025 112,774.0024 Oct 2025 110,078.0013$2,696.30
long27 Oct 2025 114,559.0029 Oct 2025 112,898.002−$1,660.97
short4 Nov 2025 106,583.0011 Nov 2025 106,011.007$571.92
short14 Nov 2025 99,692.0027 Nov 2025 90,484.0013$9,208.02
long28 Nov 2025 91,333.902 Dec 2025 86,286.004−$5,047.93
long3 Dec 2025 91,277.906 Dec 2025 89,330.003−$1,947.84
long9 Dec 2025 90,634.4013 Dec 2025 90,268.404−$365.92
short16 Dec 2025 86,432.1017 Dec 2025 87,863.401−$1,431.35
short18 Dec 2025 86,243.2020 Dec 2025 88,136.902−$1,893.72
long22 Dec 2025 88,658.9024 Dec 2025 87,486.002−$1,172.87
long25 Dec 2025 87,669.4026 Dec 2025 87,225.301−$444.17
long28 Dec 2025 87,877.0030 Dec 2025 87,237.102−$639.87
long31 Dec 2025 88,485.501 Jan 2026 87,648.201−$837.29
long2 Jan 2026 88,839.109 Jan 2026 91,100.007$2,260.95
long14 Jan 2026 95,414.0019 Jan 2026 93,673.105−$1,740.85
short21 Jan 2026 88,427.7029 Jan 2026 89,300.008−$872.34
short30 Jan 2026 84,650.2010 Feb 2026 70,138.0011$14,512.20
short11 Feb 2026 68,841.3014 Feb 2026 68,854.003−$12.69
long26 Feb 2026 67,988.0028 Feb 2026 65,872.102−$2,115.95
long1 Mar 2026 66,973.302 Mar 2026 65,776.501−$1,196.78
long3 Mar 2026 68,830.107 Mar 2026 68,114.004−$716.04
long10 Mar 2026 68,432.2019 Mar 2026 71,246.609$2,814.39
short28 Mar 2026 66,407.301 Apr 2026 68,284.504−$1,877.21
short3 Apr 2026 66,902.005 Apr 2026 67,300.402−$398.43
long7 Apr 2026 68,853.7020 Apr 2026 73,801.8013$4,948.14
long23 Apr 2026 78,178.2026 Apr 2026 77,625.003−$553.22
long27 Apr 2026 78,657.6028 Apr 2026 77,371.301−$1,286.23
short30 Apr 2026 75,780.001 May 2026 76,346.601−$566.58
long6 May 2026 80,905.5013 May 2026 80,504.507−$401.06
short14 May 2026 79,313.6015 May 2026 81,090.001−$1,776.39
short16 May 2026 79,113.2026 May 2026 77,322.0010$1,791.19
short27 May 2026 75,930.0012 Jun 2026 63,626.0016$12,304.00
short26 Jun 2026 59,794.602 Jul 2026 60,024.006−$229.36
long3 Jul 2026 61,560.0014 Jul 2026 62,334.5011$774.52
long15 Jul 2026 65,044.0024 Jul 2026 65,099.009$54.99
short1 Aug 2026 62,887.903 Aug 2026 63,570.002−$682.13
long8 Aug 2026 64,923.2011 Aug 2026 63,970.003−$953.19
short12 Aug 2026 63,600.0018 Aug 2026 64,532.106−$932.10
long19 Aug 2026 64,725.4029 Aug 2026 77,845.9010$13,120.50
short10 Sep 2026 78,306.4019 Sep 2026 80,883.909−$2,577.43
long20 Sep 2026 81,250.0029 Sep 2026 83,500.009$2,250.02
short29 Sep 2026 83,500.002 Oct 2026 84,880.103−$1,380.04
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
SPX Scalping Strategy this page—v5 strategy+1.5%1095.0%
MACD Willy Strategy by PtGamblerrma sma ema highest lowest wmav5 strategyNo trades on this market
VuManChu Cipher B + Divergences Strategy by nattichai001ema cross lowest highest sma rma wmav4 strategy+76.6%17518.4%
Bagheri IG Ether by Bagheri_IGema highest lowest rma smav4 strategy+0.0%30.0%
Bagheri IG Ether v2 by Bagheri_IGema highest lowest rma smav4 strategy−0.0%20.0%
Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99ema wma highest lowest smav5 strategy+60.2%2213.1%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 66, 67). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 2 settings use the untyped input() (line 8, 44). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.source()
  • Line 44: input() → input.bool()
  • Line 66: when = sellSignal → if block
  • Line 67: when = sellSignal → if block
⋯len1 = 10-src1 = input(close, title="SMA Source #1")+src1 = input.source(close, title="SMA Source #1")out1 = ta.sma(src1, len1)⋯//RSI / SMA RSI-swr=input(true,title="RSI")+swr=input.bool(true,title="RSI")src = close⋯// Submit exit orders-strategy.close("LONG", when=sellSignal)+if sellSignal+    strategy.close("LONG")-strategy.close("SHORT", when=sellSignal)+if sellSignal+    strategy.close("SHORT")

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: 109 before, 58 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.

⋯// © connor2279-//@version=5+//@version=6strategy(title="SPX Strategy", shorttitle="SPXS", overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 27 msYes 1,000 bars in 46 msNot measured
PineTSNot testedNot testedNot 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.

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/// USE HEIEN ASHI, 1 min, SPX 500 USD OANDA// © connor2279//@version=5strategy(title="SPX Strategy", shorttitle="SPXS", overlay=true)//SMAlen1 = 10src1 = input(close, title="SMA Source #1")out1 = ta.sma(src1, len1)plot(out1, title="SMA #1", color=close >= out1 ? color.lime : color.red, linewidth=2)data_over = ta.crossover(close, out1)dataO = close >= out1data_under = ta.crossunder(close, out1)dataU = close < out1bgcolor(color=ta.crossover(close, out1) ? color.new(color.lime, 90) : na)bgcolor(color=ta.crossunder(close, out1) ? color.new(color.red, 90) : na)     //Norm MacDsma = 12lma = 21tsp = 10np = 50    sh = ta.ema(close,sma)  lon= ta.ema(close,lma) ratio = math.min(sh,lon)/math.max(sh,lon)Mac = ratio - 1if(sh>lon)    Mac := 2-ratio - 1else    Mac := ratio - 1MacNorm = ((Mac-ta.lowest(Mac, np)) /(ta.highest(Mac, np)-ta.lowest(Mac, np)+.000001)*2)- 1MacNorm2 = MacNormif(np<2)    MacNorm2 := Macelse    MacNorm2 := MacNorm    Trigger = ta.wma(MacNorm2, tsp)trigger_above = Trigger >= MacNormtrigger_under = Trigger < MacNormplotshape(ta.crossover(Trigger, MacNorm2), style=shape.triangledown, color=color.red)plotshape(ta.crossunder(Trigger, MacNorm2), style=shape.triangledown, color=color.lime)//RSI / SMA RSIswr=input(true,title="RSI")src = closelen = 14srs = 50up = ta.rma(math.max(ta.change(src), 0), len)down = ta.rma(-math.min(ta.change(src), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))mr = ta.sma(rsi,srs)rsi_above = rsi >= mrrsi_under = rsi < mr//AllbuySignal = rsi_above and trigger_under and dataOshortSignal = rsi_under and trigger_above and dataUbgcolor(color=buySignal ? color.new(color.lime,97) : na)     bgcolor(color=shortSignal ? color.new(color.red, 97) : na)          sellSignal = ta.cross(close, out1) or ta.cross(Trigger, MacNorm2) or ta.cross(rsi, mr)if (buySignal)    strategy.entry("LONG", strategy.long, 1)if (shortSignal)    strategy.entry("SHORT", strategy.short, 1)// Submit exit ordersstrategy.close("LONG", when=sellSignal)strategy.close("SHORT", when=sellSignal)