Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Swing VWAP Weekly Stock and Crypto Strategy

A Pine Script v4 strategy with no technical-analysis calculation. 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 commits 100% of equity and pays 0.03% commission. It has no settings.

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 VWAP Weekly Stock and Crypto Strategy repaint?
Yes
In a live replay, it did not match history on 47 of 60 trades, and it produced 99 trades that history does not have.
How did Swing VWAP Weekly Stock and Crypto Strategy do on BTCUSDT 1D with default settings?
−10.66%
From 26 Jan 2024 to 21 Oct 2026, over 189 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Swing VWAP Weekly Stock and Crypto Strategy 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.
Does Swing VWAP Weekly Stock and Crypto Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Swing VWAP Weekly Stock and Crypto Strategy run in Zeal Terminal?
Yes
It compiles in 6 ms and runs 1,000 bars in 22 ms, in the browser.

BTCUSDT · 1D · default settings

  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$91$203Equity from $100
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, which this page cannot load in your browser.
Net profit
−10.66%
−$10.66
Buy and hold
+102.5%
same period
Closed trades
189
59 won · 130 lost
Profitable
31.2%
of closed trades
Profit factor
0.97
gross profit ÷ gross loss
Max drawdown
46.32%
−$76.47

One run with the author's default settings, $100 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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses an argument v6 removed

    when = on line 8, 9, 10, 11. The upgraded version below moves each call inside an if block.

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.
  • 4 strategy calls use the when = argument (line 8, 9, 10, 11). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 5: security → request.security
  • Line 5: vwap → ta.vwap
⋯// © exlux99-//@version=4+//@version=5strategy(title = "Swing VWAP Weekly Strategy", overlay = true,  pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)-vwapweekly= security(syminfo.tickerid, "W", vwap)+vwapweekly= request.security(syminfo.tickerid, "W", ta.vwap)long=( close > vwapweekly)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: when = long → if block
  • Line 9: when = close < vwapweekly or vwapweekly[1] > vwapweekly → if block
  • Line 10: when = short → if block
  • Line 11: when = close > vwapweekly or vwapweekly > vwapweekly[1] → if block
⋯short=( close < vwapweekly)-strategy.entry("long", strategy.long,when=long,  comment = "long")+if long+    strategy.entry("long", strategy.long,  comment = "long")-strategy.close("long",when=close < vwapweekly or vwapweekly[1] > vwapweekly)+if close < vwapweekly or vwapweekly[1] > vwapweekly+    strategy.close("long")-strategy.entry("short", strategy.short,when=short, comment = "short")+if short+    strategy.entry("short", strategy.short, comment = "short")-strategy.close("short",when=close > vwapweekly or vwapweekly > vwapweekly[1])+if close > vwapweekly or vwapweekly > vwapweekly[1]+    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: 189 before, 585 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.

⋯// © exlux99-//@version=5+//@version=6strategy(title = "Swing VWAP Weekly Strategy", overlay = true,  pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)⋯

Settings

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

The script declares no settings.

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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 datavwapweeklyvwapweeklyvaluelonglongconditionshortshortconditionentry:longOpen longstrategy.entryclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.close

Order rules

OrderFires whenBy defaultLine
Open long longlong( close > vwapweekly)On8
Close longclose < vwapweekly or vwapweekly[1] > vwapweeklyOn9
Open short shortshort( close < vwapweekly)On10
Close shortclose > vwapweekly or vwapweekly > vwapweekly[1]On11

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

Does it repaint?

Yes

The live replay did not match history.

13/60trades 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−10.7%+102.5%18931%0.9746.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+8.3%+5.5%6624%1.1413.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+69.1%+9.8%17635%1.1050.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+12.7%+8.4%7419%1.1526.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−10.4%+16.7%18733%0.9862.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.0%+21.5%8716%1.0823.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+95.1%+148.3%16836%1.2034.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.3%+17.1%6721%1.0217.2%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market6730%−$42.39
Sideways market7539%$61.48
Falling market4721%−$29.73

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

How bad could the drawdown be?

64.9%

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

0%75%
The first 150 of 189 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.5029 Jan 2024 42,031.102$0.44
long30 Jan 2024 43,302.705 Feb 2024 42,582.906−$1.73
short5 Feb 2024 42,582.907 Feb 2024 43,099.002−$1.26
long7 Feb 2024 43,099.0024 Feb 2024 50,744.2017$17.22
short24 Feb 2024 50,744.2025 Feb 2024 51,568.201−$1.93
long25 Feb 2024 51,568.2026 Feb 2024 51,728.801$0.28
short26 Feb 2024 51,728.8027 Feb 2024 54,476.501−$6.07
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$21.18
short17 Mar 2024 65,300.6018 Mar 2024 68,393.501−$6.15
short19 Mar 2024 67,610.0025 Mar 2024 67,210.006$0.65
long25 Mar 2024 67,210.002 Apr 2024 69,649.808$4.38
short2 Apr 2024 69,649.808 Apr 2024 69,360.406$0.45
long8 Apr 2024 69,360.4013 Apr 2024 67,116.505−$4.20
short13 Apr 2024 67,116.5022 Apr 2024 64,941.209$3.92
long22 Apr 2024 64,941.2027 Apr 2024 63,770.005−$2.37
short27 Apr 2024 63,770.0029 Apr 2024 63,118.602$1.20
short30 Apr 2024 63,866.006 May 2024 64,012.006−$0.36
long6 May 2024 64,012.009 May 2024 61,193.003−$5.61
short9 May 2024 61,193.0010 May 2024 63,074.001−$3.76
long10 May 2024 63,074.0011 May 2024 60,800.001−$4.26
short11 May 2024 60,800.0013 May 2024 61,484.002−$1.33
long14 May 2024 62,940.1015 May 2024 61,577.501−$2.46
short15 May 2024 61,577.5016 May 2024 66,206.501−$8.20
long16 May 2024 66,206.5027 May 2024 68,507.7011$3.42
short27 May 2024 68,507.7028 May 2024 69,436.401−$1.46
long28 May 2024 69,436.4029 May 2024 68,398.401−$1.59
short29 May 2024 68,398.404 Jun 2024 68,809.906−$0.66
long4 Jun 2024 68,809.9010 Jun 2024 69,648.106$1.15
short10 Jun 2024 69,648.101 Jul 2024 62,772.0021$9.90
long1 Jul 2024 62,772.004 Jul 2024 60,208.603−$4.59
short4 Jul 2024 60,208.6010 Jul 2024 58,050.006$3.74
long10 Jul 2024 58,050.0011 Jul 2024 57,725.801−$0.68
short11 Jul 2024 57,725.8013 Jul 2024 57,889.102−$0.37
long13 Jul 2024 57,889.1025 Jul 2024 65,376.0012$14.01
short25 Jul 2024 65,376.0026 Jul 2024 65,799.901−$0.87
long26 Jul 2024 65,799.9030 Jul 2024 66,784.704$1.75
short30 Jul 2024 66,784.7012 Aug 2024 58,712.6013$14.89
long12 Aug 2024 58,712.6019 Aug 2024 58,427.307−$0.76
short19 Aug 2024 58,427.3020 Aug 2024 59,438.501−$2.47
long20 Aug 2024 59,438.5028 Aug 2024 59,415.008−$0.13
short28 Aug 2024 59,415.0010 Sep 2024 57,042.0013$5.32
long10 Sep 2024 57,042.001 Oct 2024 63,327.6021$15.41
short1 Oct 2024 63,327.607 Oct 2024 62,819.906$1.16
long7 Oct 2024 62,819.908 Oct 2024 62,224.001−$1.59
short8 Oct 2024 62,224.0013 Oct 2024 63,206.205−$2.55
long13 Oct 2024 63,206.2014 Oct 2024 62,870.001−$0.91
long15 Oct 2024 66,084.0024 Oct 2024 66,668.609$1.25
short24 Oct 2024 66,668.6025 Oct 2024 68,198.301−$3.61
long25 Oct 2024 68,198.3026 Oct 2024 66,698.301−$3.38
short26 Oct 2024 66,698.3027 Oct 2024 67,092.801−$0.95
long27 Oct 2024 67,092.804 Nov 2024 68,776.008$3.56
short4 Nov 2024 68,776.007 Nov 2024 75,572.003−$14.82
long7 Nov 2024 75,572.0026 Nov 2024 93,010.0019$30.88
short26 Nov 2024 93,010.0028 Nov 2024 95,863.102−$5.16
long28 Nov 2024 95,863.102 Dec 2024 97,185.204$2.11
long3 Dec 2024 95,840.6010 Dec 2024 97,276.507$2.33
short10 Dec 2024 97,276.5012 Dec 2024 101,125.002−$6.60
long12 Dec 2024 101,125.0019 Dec 2024 100,204.007−$1.53
short19 Dec 2024 100,204.0025 Dec 2024 98,663.606$2.31
long25 Dec 2024 98,663.6027 Dec 2024 95,791.602−$4.71
short27 Dec 2024 95,791.603 Jan 2025 96,984.807−$2.01
long3 Jan 2025 96,984.809 Jan 2025 95,060.606−$3.10
short9 Jan 2025 95,060.6015 Jan 2025 96,560.906−$2.44
long15 Jan 2025 96,560.9027 Jan 2025 102,620.0012$9.09
short27 Jan 2025 102,620.0031 Jan 2025 104,723.004−$3.28
long31 Jan 2025 104,723.001 Feb 2025 102,430.001−$3.42
short1 Feb 2025 102,430.004 Feb 2025 101,329.003$1.51
long4 Feb 2025 101,329.005 Feb 2025 97,763.101−$5.37
short5 Feb 2025 97,763.1011 Feb 2025 97,430.806$0.41
long11 Feb 2025 97,430.8012 Feb 2025 95,778.201−$2.55
short12 Feb 2025 95,778.2013 Feb 2025 97,870.001−$3.20
long13 Feb 2025 97,870.0014 Feb 2025 96,608.101−$1.88
short14 Feb 2025 96,608.1015 Feb 2025 97,500.501−$1.35
long15 Feb 2025 97,500.5017 Feb 2025 96,118.102−$2.01
short17 Feb 2025 96,118.1020 Feb 2025 96,644.403−$0.82
long20 Feb 2025 96,644.4022 Feb 2025 96,182.002−$0.72
short22 Feb 2025 96,182.0023 Feb 2025 96,551.001−$0.59
long23 Feb 2025 96,551.0024 Feb 2025 96,258.001−$0.48
short24 Feb 2025 96,258.003 Mar 2025 94,270.007$2.64
long3 Mar 2025 94,270.004 Mar 2025 86,221.201−$11.54
short4 Mar 2025 86,221.206 Mar 2025 90,606.002−$6.32
long6 Mar 2025 90,606.008 Mar 2025 86,801.702−$4.96
short8 Mar 2025 86,801.7017 Mar 2025 82,574.509$5.36
long17 Mar 2025 82,574.5029 Mar 2025 84,424.4012$2.55
short29 Mar 2025 84,424.402 Apr 2025 85,158.404−$1.11
long2 Apr 2025 85,158.403 Apr 2025 82,516.301−$3.74
short3 Apr 2025 82,516.3010 Apr 2025 82,615.207−$0.21
long10 Apr 2025 82,615.2011 Apr 2025 79,607.301−$4.23
short11 Apr 2025 79,607.3012 Apr 2025 83,423.801−$5.34
long12 Apr 2025 83,423.805 May 2025 94,277.6023$13.56
short5 May 2025 94,277.607 May 2025 96,834.002−$3.28
long7 May 2025 96,834.0030 May 2025 105,590.0023$10.33
short30 May 2025 105,590.009 Jun 2025 105,734.0010−$0.25
long9 Jun 2025 105,734.0016 Jun 2025 105,594.007−$0.24
short16 Jun 2025 105,594.0017 Jun 2025 106,795.001−$1.49
long17 Jun 2025 106,795.0018 Jun 2025 104,551.001−$2.66
short18 Jun 2025 104,551.0024 Jun 2025 105,334.006−$0.98
long24 Jun 2025 105,334.008 Jul 2025 108,263.0014$3.26
short8 Jul 2025 108,263.009 Jul 2025 108,923.001−$0.82
long9 Jul 2025 108,923.0021 Jul 2025 117,265.0012$9.28
short21 Jul 2025 117,265.0023 Jul 2025 119,954.002−$3.09
long23 Jul 2025 119,954.0025 Jul 2025 118,341.002−$1.80
short25 Jul 2025 118,341.0028 Jul 2025 119,416.003−$1.23
long28 Jul 2025 119,416.0029 Jul 2025 118,062.001−$1.49
short29 Jul 2025 118,062.008 Aug 2025 117,472.0010$0.54
long8 Aug 2025 117,472.0018 Aug 2025 117,405.0010−$0.15
short18 Aug 2025 117,405.003 Sep 2025 111,240.0016$6.45
long3 Sep 2025 111,240.0022 Sep 2025 115,232.0019$4.61
short22 Sep 2025 115,232.0029 Sep 2025 112,164.007$3.52
long29 Sep 2025 112,164.0011 Oct 2025 112,774.0012$0.67
short11 Oct 2025 112,774.0013 Oct 2025 114,959.002−$2.79
long13 Oct 2025 114,959.0015 Oct 2025 113,028.002−$2.38
short15 Oct 2025 113,028.0021 Oct 2025 110,532.006$2.89
long21 Oct 2025 110,532.0022 Oct 2025 108,298.001−$2.85
short22 Oct 2025 108,298.0024 Oct 2025 110,078.002−$2.29
long24 Oct 2025 110,078.0030 Oct 2025 110,021.006−$0.15
short30 Oct 2025 110,021.0011 Nov 2025 106,011.0012$4.73
long11 Nov 2025 106,011.0012 Nov 2025 103,059.001−$3.88
short12 Nov 2025 103,059.0025 Nov 2025 88,300.0013$18.93
long25 Nov 2025 88,300.0026 Nov 2025 87,370.001−$1.69
short26 Nov 2025 87,370.0027 Nov 2025 90,484.001−$5.44
long27 Nov 2025 90,484.002 Dec 2025 86,286.005−$6.79
short2 Dec 2025 86,286.003 Dec 2025 91,277.901−$8.05
long3 Dec 2025 91,277.906 Dec 2025 89,330.003−$2.84
short6 Dec 2025 89,330.008 Dec 2025 90,395.302−$1.59
long8 Dec 2025 90,395.3015 Dec 2025 88,172.207−$3.15
short15 Dec 2025 88,172.2022 Dec 2025 88,658.907−$0.75
long22 Dec 2025 88,658.9024 Dec 2025 87,486.002−$1.68
short24 Dec 2025 87,486.0028 Dec 2025 87,877.004−$0.61
long28 Dec 2025 87,877.0029 Dec 2025 87,952.701$0.03
short29 Dec 2025 87,952.7031 Dec 2025 88,485.502−$0.79
long31 Dec 2025 88,485.501 Jan 2026 87,648.201−$1.19
short1 Jan 2026 87,648.202 Jan 2026 88,839.101−$1.66
long2 Jan 2026 88,839.1012 Jan 2026 91,013.7010$2.76
short12 Jan 2026 91,013.7014 Jan 2026 95,414.002−$5.79
long14 Jan 2026 95,414.0019 Jan 2026 93,673.105−$2.12
short19 Jan 2026 93,673.1028 Jan 2026 89,250.009$5.14
long28 Jan 2026 89,250.0030 Jan 2026 84,650.202−$6.02
short30 Jan 2026 84,650.209 Feb 2026 70,330.4010$18.45
long9 Feb 2026 70,330.4011 Feb 2026 68,841.302−$2.78
short11 Feb 2026 68,841.3016 Feb 2026 68,832.605−$0.06
long16 Feb 2026 68,832.6018 Feb 2026 67,503.502−$2.49
short18 Feb 2026 67,503.5026 Feb 2026 67,988.008−$0.95
long26 Feb 2026 67,988.0027 Feb 2026 67,485.201−$0.97
short27 Feb 2026 67,485.203 Mar 2026 68,830.104−$2.48
long3 Mar 2026 68,830.109 Mar 2026 65,971.206−$4.98
short9 Mar 2026 65,971.2010 Mar 2026 68,432.201−$4.29
long10 Mar 2026 68,432.2020 Mar 2026 69,930.0010$2.32
short20 Mar 2026 69,930.0024 Mar 2026 70,906.404−$1.62
long24 Mar 2026 70,906.4027 Mar 2026 68,820.303−$3.29

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 6 msWith a workaround 1,000 bars in 22 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © exlux99//@version=4strategy(title = "Swing VWAP Weekly Strategy", overlay = true,  pyramiding=1,initial_capital = 100, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)vwapweekly= security(syminfo.tickerid, "W", vwap)long=( close > vwapweekly)short=( close < vwapweekly)strategy.entry("long", strategy.long,when=long,  comment = "long")strategy.close("long",when=close < vwapweekly or vwapweekly[1] > vwapweekly)strategy.entry("short", strategy.short,when=short, comment = "short")strategy.close("short",when=close > vwapweekly or vwapweekly > vwapweekly[1])