Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Swing Trend Strategy

A Pine Script v5 strategy built on SMA or EMA or RMA or WMA or VWMA (close, 200) and ATR (10). 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.1 commission. 6 settings; defaults include Source close, Trend Length 200 and Moving Average Type ema.

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 Trend Strategy 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 Trend Strategy do on BTCUSDT 1D with default settings?
+11.23%
From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Swing Trend Strategy run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L55:C65: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
Does Swing Trend Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Swing Trend Strategy run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 36 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • 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 (6)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,203$2,025Equity from $1,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
+11.23%
$112.30
Buy and hold
+102.5%
same period
Closed trades
5
2 won · 3 lost
Profitable
40.0%
of closed trades
Profit factor
1.39
gross profit ÷ gross loss
Max drawdown
16.24%
−$197.27

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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 41, 42, 43, 44. 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
Open Short Positions?falseboolopen_short
Exit trade on Moving Average Cross?trueboolclose_long close_short
Sourceclosesourcema open_long close_long open_short close_short tcolor
Trend Length200intma
Moving Average TypeSelect the type of Moving Average to use to calculate the Trendemastring · options ['sma', 'ema', 'rma', 'wma', 'vwma']line 21 line 23 line 25 line 27 line 29
ATR ThresholdFilter the ranging market using the Average True Range1.float · step 0.5uptrend downtrend

What it calculates

  • SMA / EMA / RMA / WMA / VWMASource (close), Trend Length (200)ma · line 20
  • ATR10atr · line 33

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 datalenTrend Lengthsetting · 200high · low · closehigh · low · closeprice dataatr_multiplierATR Thresholdsetting · 1.maSMA / EMA / RMA / WMA /…→ maatrATR→ atruptrend, downtrenduptrend · downtrend2 valuesclose_longclose_longvalueclose_shortclose_shortvalueopen_longopen_longconditionopen_shortopen_shortconditiontcolorColourtcolorentry:longOpen longstrategy.entryclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryclose:shortClose shortstrategy.closeplot:47plotplotplot:48plotplotplot:49plotplotplot:50plotplotfill:51Fillfill × 2fill:52Fillfill × 2

Order rules

OrderFires whenBy defaultLine
Open long longopen_longstrategy.position_size == 0 and src > uptrendOn41
Close longclose_longOn42
Open short shortopen_shortuse_short and strategy.position_size == 0 and src < downtrendOn43
Close shortclose_shortOn44

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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+11.2%+102.5%540%1.3916.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+12.5%+5.5%714%2.147.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+4.1%+9.8%540%1.1429.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+28.5%+8.4%540%4.907.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−29.3%+16.7%825%0.3835.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+29.6%+21.5%617%4.3110.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+12.9%+148.3%633%1.4916.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+21.7%+17.1%250%9.863.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 market0—$0.00
Sideways market540%$113.42
Falling market0—$0.00

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

How bad could the drawdown be?

23.0%

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

0%26%
All 5 trades
SideEntryExitBarsP&L
long23 Sep 2024 63,578.802 Oct 2024 60,804.909−$45.54
long15 Oct 2024 66,084.0027 Feb 2025 84,250.10135$259.94
long3 Mar 2025 94,270.0010 Mar 2025 80,734.507−$176.44
long23 Apr 2025 93,443.0018 Oct 2025 106,432.00178$141.92
long27 Oct 2025 114,559.0031 Oct 2025 108,323.004−$66.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
Swing Trend Strategy this page—v5 strategy+11.2%516.2%
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma rma vwmav4 strategyNo trades on this market
Open Close Cross Strategy plus Explorer by roses27sma ema wma vwma atrv4 strategydoes not run in Zeal Terminal
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalaisma ema vwma rmav5 strategy+1.3%1135.6%
Strategy Myth-Busting #2 - Braid Filter+ADX+EMA-Trend - [MYN] by myncryptosma ema wma atrv5 strategy−47.2%448.6%
Nifty & BN 2 Candle Theory Back Testing and Alert Notification by abdullabashaaema rma atr vwmav5 strategy−1.9%31.9%

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.

  • 4 strategy calls use the when = argument (line 41, 42, 43, 44). 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

VerifiedDownload the v5 script

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

  • Line 41: when = open_long → if block
  • Line 42: when = close_long → if block
  • Line 43: when = open_short → if block
  • Line 44: when = close_short → if block
⋯close_short = exit_type ? strategy.position_size < 0 and src > trend : strategy.position_size < 0 and src > uptrend-strategy.entry('long', strategy.long, when=open_long)+if open_long+    strategy.entry('long', strategy.long)-strategy.close('long', when=close_long)+if close_long+    strategy.close('long')-strategy.entry('short', strategy.short, when=open_short)+if open_short+    strategy.entry('short', strategy.short)-strategy.close('short', when=close_short)+if close_short+    strategy.close('short')// ------------------ PLOTTING AND COLORING ------------------⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L55:C65: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Inkedlau-//@version=5+//@version=6strategy('Swing Trend Strategy', overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, commission_value=0.1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msYes 1,000 bars in 36 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/// © Inkedlau//@version=5strategy('Swing Trend Strategy', overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=1000, commission_value=0.1)use_short = input.bool(false, 'Open Short Positions?')exit_type = input.bool(true, 'Exit trade on Moving Average Cross?')src = input.source(close, 'Source')len = input.int(200, 'Trend Length')ma_type = input.string('ema', 'Moving Average Type', options=['sma', 'ema', 'rma', 'wma', 'vwma'], tooltip='Select the type of Moving Average to use to calculate the Trend')atr_multiplier = input.float(1., 'ATR Threshold', step=0.5, tooltip='Filter the ranging market using the Average True Range')// ----------------------- DESCRIPTION -----------------------// THIS SCRIPT IS A TREND FOLLOWING SYSTEM THAT USES A COMBINATION OF MOVING AVERAGE AND AVERAGE TRUE RANGE// TO SPOT THE TRENDS AND ENTER THE MARKET ACCODINGLY.// THE MARKET IS CONSIDERED IN AN UPTREND WHEN THE PRICE CLOSES ABOVE THE MOVING AVERAGE + THE AVERAGE TRUE RANGE OF THE LAST 10 PERIODS// THE MARKET IS CONSIDERED IN AN DOWNTREND WHEN THE PRICE CLOSES BLOW THE MOVING AVERAGE - THE AVERAGE TRUE RANGE OF THE LAST 10 PERIODS// BY DEFAULT, THE STRATEGY WILL ENTER LONG WHEN AN UPTREND IS SPOTTED, THEN CLOSES WHEN THE PRICE CLOSES BELOW THE MOVING AVERAGE// THE STRATEGY WILL ENTER SHORT WHEN A DOWNTREND IS SPOTTED, THEN CLOSES WHEN THE PRICE CLOSES ABOVE THE MOVING AVERAGE// ------------------ INDICATORS CALCULATION------------------my_ma()=>    ma = close    if ma_type == 'sma'        ma := ta.sma(src, len)    if ma_type == 'ema'        ma := ta.ema(src, len)    if ma_type == 'rma'        ma := ta.rma(src, len)    if ma_type == 'wma'        ma := ta.wma(src, len)    if ma_type == 'vwma'        ma := ta.vwma(src, len)    matrend = my_ma()atr = ta.atr(10)uptrend = trend + atr * atr_multiplierdowntrend = trend - atr * atr_multiplier// ---------------- ENTRY AND EXIT CONDITIONS ----------------open_long = strategy.position_size == 0 and src > uptrendclose_long = exit_type ? strategy.position_size > 0 and src < trend : strategy.position_size > 0 and src < downtrendopen_short = use_short and strategy.position_size == 0 and src < downtrendclose_short = exit_type ? strategy.position_size < 0 and src > trend : strategy.position_size < 0 and src > uptrendstrategy.entry('long', strategy.long, when=open_long)strategy.close('long', when=close_long)strategy.entry('short', strategy.short, when=open_short)strategy.close('short', when=close_short)// ------------------ PLOTTING AND COLORING ------------------tcolor = src > uptrend ? color.green : src < downtrend ? color.red : naptrend = plot(trend, color=color.blue, linewidth=1)puptrend = plot(uptrend, color=color.green, linewidth=1)pdowntrend = plot(downtrend, color=color.red, linewidth=1)pclose = plot(close, color=na)fill(puptrend, pclose, color=close > uptrend ? color.green : na, transp = 90)fill(pdowntrend, pclose, color=close < downtrend ? color.red : na, transp = 90)