Pine Script v5 · Strategy
Swing Trading SPX Correlation
A Pine Script v5 strategy built on VWMA (P4, 100) and Rising or Falling (MA4, 2). It has 2 order rules, 1 entry among them, and trades long only 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 Length MA 100 and Reaction 2.
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 Swing Trading SPX Correlation repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Swing Trading SPX Correlation do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Swing Trading SPX Correlation run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Swing Trading SPX Correlation use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Swing Trading SPX Correlation run in Zeal Terminal?
- Yes
- It compiles in 7 ms and runs 1,000 bars in 19 ms, in the browser.
BTCUSDT · 1D · default settings
- VWMA
- Rising
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs INDEX:S5TH D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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
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
2 settings have no label
In the settings dialog lengthMA (line 7), reaction (line 8) show an empty name. The labels on this page come from the variable names.
-
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 19, 20. 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length MA (no label in the script) | 100 | int · min 1 | MA4 |
| Reaction (no label in the script) | 2 | int · min 1 · max 5 | direction4 |
What it calculates
- VWMAP4, Length MA (100)
MA4 · line 9 - Rising / FallingMA4, Reaction (2)
direction4 · line 11
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 | longdirection4 > 0 and direction4[1] < 0 | On | 19 |
| Close long | shortdirection4 < 0 and direction4[1] > 0 | On | 20 |
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.
- ClearHigher-timeframe data1 request.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
Not run on other markets: the script requests INDEX:S5TH D, and that data is not available here (not a Binance spot market). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| Swing Trading SPX Correlation this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Trading Day and Time Session by Dannnnnnny | vwma rising falling | v5 strategy | No trades on this market | ||
| Quarterly Returns in Strategies vs Buy & Hold by Dannnnnnny | vwma rising falling | v4 strategy | +80.2% | 4 | 10.7% |
| PMA Strategy Idea by QuantCT | rising falling | v4 strategy | +51.7% | 129 | 30.8% |
| Trendelicious Strategy by levieux | rising falling | v5 strategy | −12.8% | 9 | 41.4% |
| Linear On MACD by stocktechbot | rising falling vwma | v5 strategy | +1.5% | 16 | 5.6% |
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 19, 20). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 19: when = long → if block
- Line 20: when = short → if block
⋯short = direction4 < 0 and direction4[1] > 0-strategy.entry("long",strategy.long,when=long)+if long+ strategy.entry("long",strategy.long)-strategy.close("long",when=short)+if short+ strategy.close("long")//strategy.entry('short',strategy.short,when=short)Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © exlux99-//@version=5+//@version=6strategy("Swing Trading SPX Correlation")⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 7 ms | Yes 1,000 bars in 19 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © exlux99//@version=5strategy("Swing Trading SPX Correlation")S4 = 'INDEX:S5TH'//input.symbol(title='ABOVE 200', defval='INDEX:S5TH')P4 = request.security(S4, 'D', close)lengthMA = input.int(100, minval=1)reaction = input.int(2, minval=1, maxval=5)MA4 = ta.vwma(P4, lengthMA)direction4 = 0direction4 := ta.rising(MA4, reaction) ? 1 : ta.falling(MA4, reaction) ? -1 : nz(direction4[1])//change_direction= change(direction2,1)pcol4 = direction4 > 0 ? color.lime : direction4 < 0 ? color.red : napula_long = direction4 > direction4[1] and direction4 > 0pula_short= direction4 < direction4[1] and direction4 < 0plot(MA4, linewidth=4, color=pcol4)long = direction4 > 0 and direction4[1] < 0short = direction4 < 0 and direction4[1] > 0strategy.entry("long",strategy.long,when=long)strategy.close("long",when=short)//strategy.entry('short',strategy.short,when=short)