Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Swing Multi Moving Averages Crypto and Stocks Strategy

A Pine Script v5 strategy built on EMA (close, 17), WMA (src, len) and Change (close, 17). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.03% commission. 9 settings; defaults include Source close, Moving Averages 17 and MA Type ALMA.

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 Multi Moving Averages Crypto and Stocks Strategy repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Swing Multi Moving Averages Crypto and Stocks Strategy do on BTCUSDT 1D with default settings?
+60.17%
From 26 Jan 2024 to 21 Oct 2026, over 22 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Swing Multi Moving Averages Crypto and Stocks 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: 22 before, 22 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 Swing Multi Moving Averages Crypto and Stocks Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 146, 150.
Does Swing Multi Moving Averages Crypto and Stocks Strategy run in Zeal Terminal?
Yes
It compiles in 58 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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 (9)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$160$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. Lines are what the script plots.
Net profit
+60.17%
$60.17
Buy and hold
+102.5%
same period
Closed trades
22
14 won · 8 lost
Profitable
63.6%
of closed trades
Profit factor
2.77
gross profit ÷ gross loss
Max drawdown
13.15%
−$18.07

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

  • Likely bug

    The “SMMA” option calculates RMA line 131

    Choosing SMMA in “MA Type” runs ta.rma, not ta.smma. Anyone picking SMMA gets a different average from the one they asked for.

    out_ma_source == 'SMMA' ? ta.rma(out_ma_source == 'SMMA' ? ta.smma(
  • Likely bug

    The “LSMA” option calculates LINREG line 131

    Choosing LSMA in “MA Type” runs ta.linreg, not ta.lsma. Anyone picking LSMA gets a different average from the one they asked for.

    out_ma_source == 'LSMA' ? ta.linreg(out_ma_source == 'LSMA' ? ta.lsma(
  • Likely bug

    The “HULL” option calculates HMA line 131

    Choosing HULL in “MA Type” runs ta.hma, not ta.hull. Anyone picking HULL gets a different average from the one they asked for.

    out_ma_source == 'HULL' ? ta.hma(out_ma_source == 'HULL' ? ta.hull(
  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    2 settings have no label

    In the settings dialog longEntry (line 5), shortEntry (line 6) 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 145, 147, 149, 151. 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
Type of Entries
Long Entry (no label in the script)trueboolentry long exit LONG EXIT close long line 144
Short Entry (no label in the script)falseboolentry short exit SHORT EXIT close short line 148
Parameters
Sourceclosesourcedema hullma change volatility kama e zlemadata_1 Price mom vidya MA1 Det0 ema1 TRIMA out_ma
Moving Averages17int · min 1dema hullma change volatility e tema zlemalag_1 zlema N upSum downSum beta ema1 ema2 ema3 ema4 ema5 ema6 out_ma alpha
MA TypeALMAstring · options ['SMA', 'EMA', 'WMA', 'ALMA', 'SMMA', 'LSMA', 'VWMA', 'DEMA', 'HULL', 'KAMA', 'FRAMA', 'VIDYA', 'JMA', 'TEMA', 'ZLEMA', 'T3', 'TRIM']out_ma
Fixed Risk Management
LONG Stop Loss % 10.0floatlongStop
LONG Take Profit %30.0floatlongTake
SHORT Stop Loss % 5.0floatshortStop
SHORT Take Profit %10.0floatshortTake

What it calculates

  • EMASource (close), Moving Averages (17)dema · line 9
  • WMA2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len))hullma · line 13
  • ChangeSource (close), Moving Averages (17)change · line 17
  • ChangeSource (close)volatility · line 18
  • EMASource (close), Moving Averages (17)e · line 28
  • EMAe, Moving Averages (17)tema · line 29
  • EMAzlemadata_1, Moving Averages (17)zlema · line 35
  • Highest / LowestNN3 · line 52
  • HighestN / 2 - 1HH · line 53
  • LowestN / 2 - 1LL · line 54
  • ChangeSource (close)mom · line 83
  • EMASource (close), Moving Averages (17)ema1 · line 110
  • EMAema1, Moving Averages (17)ema2 · line 111
  • EMAema2, Moving Averages (17)ema3 · line 112
  • EMAema3, Moving Averages (17)ema4 · line 113
  • EMAema4, Moving Averages (17)ema5 · line 114
  • EMAema5, Moving Averages (17)ema6 · line 115
  • SMAta.sma(src, Nm), NmTRIMA · line 126
  • SMA / EMA / WMA / ALMA / RMA / Linreg / VWMA / HMASource (close), Moving Averages (17) · chosen by MA Typeout_ma · line 131

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.

The script has 63 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open long longlongclose> out_ma and close[1] < out_ma and dayofweek==dayofweek.mondayOn145
Exit LONG EXIT stop and limit(longEntry)On146
Close longdayofweek==dayofweek.sundayOn147
Open short shortshortclose< out_ma and close[1] > out_ma and dayofweek==dayofweek.mondayOn149
Exit SHORT EXIT stop and limit(shortEntry)On150
Close shortdayofweek==dayofweek.sundayOn151

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

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

8/8trades 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. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • 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+60.2%+102.5%2264%2.7713.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+21.7%+5.5%1267%2.5413.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−6.5%+9.8%2642%0.9144.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+15.1%+8.4%1656%1.5324.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+142.2%+16.7%1669%3.3326.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+14.2%+21.5%1450%1.3323.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+5.5%+148.3%1963%1.2318.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+38.3%+17.1%1759%2.978.5%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 market683%$27.12
Sideways market863%$16.48
Falling market850%$16.57

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

How bad could the drawdown be?

15.8%

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

0%18%
All 22 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.504 Mar 2024 63,114.006$15.79
long14 May 2024 62,940.1020 May 2024 66,274.006$6.06
long28 May 2024 69,436.403 Jun 2024 67,765.606−$3.00
long4 Jun 2024 68,809.9010 Jun 2024 69,648.106$1.38
long13 Aug 2024 59,346.6019 Aug 2024 58,427.306−$1.93
long20 Aug 2024 59,438.5026 Aug 2024 64,220.006$9.44
long10 Sep 2024 57,042.0016 Sep 2024 59,132.006$4.60
long11 Feb 2025 97,430.8017 Feb 2025 96,118.106−$1.86
long18 Mar 2025 84,010.0024 Mar 2025 86,082.506$3.14
long17 Jun 2025 106,795.0023 Jun 2025 100,964.006−$7.37
long24 Jun 2025 105,334.0030 Jun 2025 108,357.006$3.54
long21 Oct 2025 110,532.0027 Oct 2025 114,559.006$4.65
long25 Nov 2025 88,300.001 Dec 2025 90,360.006$3.05
long9 Dec 2025 90,634.4015 Dec 2025 88,172.206−$3.81
long13 Jan 2026 91,296.2019 Jan 2026 93,673.106$3.40
long3 Mar 2026 68,830.109 Mar 2026 65,971.206−$5.77
long24 Mar 2026 70,906.4030 Mar 2026 66,010.906−$9.14
long14 Apr 2026 74,418.0020 Apr 2026 73,801.806−$1.08
long21 Apr 2026 75,841.0027 Apr 2026 78,657.606$4.42
long18 Aug 2026 64,532.1024 Aug 2026 77,734.006$25.58
long1 Sep 2026 78,581.307 Sep 2026 80,341.806$3.29
long15 Sep 2026 78,189.2021 Sep 2026 81,178.006$5.80

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 Multi Moving Averages Crypto and Stocks Strategy this page—v5 strategy+60.2%2213.1%
Ultra Moving Average Rating Trend Strategy by exlux99ema wma highest lowest sma rma alma linreg vwma hmav5 strategy+2.8%52.4%
Multi Trend Cross Strategy Template by TradeAutomationalma ema hma linreg rma sma vwma wma highest lowestv5 strategy+33.0%37.3%
Multi MA Trend Following Strategy Template by TradeAutomationalma ema hma linreg rma sma vwma wma highest lowestv5 strategy+12.3%326.9%
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma alma rma linreg vwmav4 strategyNo trades on this market
VCP pivot buy by perrycc007sma ema rma vwma wma lowest highestv4 strategydoes not run in Zeal Terminal

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 145, 147, 149, 151). 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 22 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 145: when = long → if block
  • Line 147: when = dayofweek==dayofweek.sunday → if block
  • Line 149: when = short → if block
  • Line 151: when = dayofweek==dayofweek.sunday → if block
⋯if(longEntry)-    strategy.entry("long",strategy.long,when=long )+    if long+        strategy.entry("long",strategy.long )    strategy.exit('LONG EXIT', "long", limit=longTake, stop=longStop)-    strategy.close("long",when=dayofweek==dayofweek.sunday)+    if dayofweek==dayofweek.sunday+        strategy.close("long")if(shortEntry)-    strategy.entry("short",strategy.short,when=short )+    if short+        strategy.entry("short",strategy.short )    strategy.exit('SHORT EXIT', "short", limit=shortTake, stop=shortStop)-    strategy.close("short",when=dayofweek==dayofweek.sunday)+    if dayofweek==dayofweek.sunday+        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: 22 before, 22 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('Time MA strategy ', overlay=true, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick=true, commission_type=strategy.commission.percent, commission_value=0.03)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 58 msYes 1,000 bars in 32 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/// © exlux99//@version=5strategy('Time MA strategy ', overlay=true, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick=true, commission_type=strategy.commission.percent, commission_value=0.03)longEntry = input.bool(true, group="Type of Entries")shortEntry = input.bool(false, group="Type of Entries")//==========DEMAgetDEMA(src, len) =>    dema = 2 * ta.ema(src, len) - ta.ema(ta.ema(src, len), len)    dema//==========HMAgetHULLMA(src, len) =>    hullma = ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))    hullma//==========KAMAgetKAMA(src, len, k1, k2) =>    change = math.abs(ta.change(src, len))    volatility = math.sum(math.abs(ta.change(src)), len)    efficiency_ratio = volatility != 0 ? change / volatility : 0    kama = 0.0    fast = 2 / (k1 + 1)    slow = 2 / (k2 + 1)    smooth_const = math.pow(efficiency_ratio * (fast - slow) + slow, 2)    kama := nz(kama[1]) + smooth_const * (src - nz(kama[1]))    kama//==========TEMAgetTEMA(src, len) =>    e = ta.ema(src, len)    tema = 3 * (e - ta.ema(e, len)) + ta.ema(ta.ema(e, len), len)    tema//==========ZLEMAgetZLEMA(src, len) =>    zlemalag_1 = (len - 1) / 2    zlemadata_1 = src + src - src[zlemalag_1]    zlema = ta.ema(zlemadata_1, len)    zlema//==========FRAMAgetFRAMA(src, len) =>    Price = src    N = len    if N % 2 != 0        N := N + 1        N    N1 = 0.0    N2 = 0.0    N3 = 0.0    HH = 0.0    LL = 0.0    Dimen = 0.0    alpha = 0.0    Filt = 0.0    N3 := (ta.highest(N) - ta.lowest(N)) / N    HH := ta.highest(N / 2 - 1)    LL := ta.lowest(N / 2 - 1)    N1 := (HH - LL) / (N / 2)    HH := high[N / 2]    LL := low[N / 2]    for i = N / 2 to N - 1 by 1        if high[i] > HH            HH := high[i]            HH        if low[i] < LL            LL := low[i]            LL    N2 := (HH - LL) / (N / 2)    if N1 > 0 and N2 > 0 and N3 > 0        Dimen := (math.log(N1 + N2) - math.log(N3)) / math.log(2)        Dimen    alpha := math.exp(-4.6 * (Dimen - 1))    if alpha < .01        alpha := .01        alpha    if alpha > 1        alpha := 1        alpha    Filt := alpha * Price + (1 - alpha) * nz(Filt[1], 1)    if bar_index < N + 1        Filt := Price        Filt    Filt//==========VIDYAgetVIDYA(src, len) =>    mom = ta.change(src)    upSum = math.sum(math.max(mom, 0), len)    downSum = math.sum(-math.min(mom, 0), len)    out = (upSum - downSum) / (upSum + downSum)    cmo = math.abs(out)    alpha = 2 / (len + 1)    vidya = 0.0    vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)    vidya//==========JMAgetJMA(src, len, power, phase) =>    phase_ratio = phase < -100 ? 0.5 : phase > 100 ? 2.5 : phase / 100 + 1.5    beta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)    alpha = math.pow(beta, power)    MA1 = 0.0    Det0 = 0.0    MA2 = 0.0    Det1 = 0.0    JMA = 0.0    MA1 := (1 - alpha) * src + alpha * nz(MA1[1])    Det0 := (src - MA1) * (1 - beta) + beta * nz(Det0[1])    MA2 := MA1 + phase_ratio * Det0    Det1 := (MA2 - nz(JMA[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(Det1[1])    JMA := nz(JMA[1]) + Det1    JMA//==========T3getT3(src, len, vFactor) =>    ema1 = ta.ema(src, len)    ema2 = ta.ema(ema1, len)    ema3 = ta.ema(ema2, len)    ema4 = ta.ema(ema3, len)    ema5 = ta.ema(ema4, len)    ema6 = ta.ema(ema5, len)    c1 = -1 * math.pow(vFactor, 3)    c2 = 3 * math.pow(vFactor, 2) + 3 * math.pow(vFactor, 3)    c3 = -6 * math.pow(vFactor, 2) - 3 * vFactor - 3 * math.pow(vFactor, 3)    c4 = 1 + 3 * vFactor + math.pow(vFactor, 3) + 3 * math.pow(vFactor, 2)    T3 = c1 * ema6 + c2 * ema5 + c3 * ema4 + c4 * ema3    T3//==========TRIMAgetTRIMA(src, len) =>    N = len + 1    Nm = math.round(N / 2)    TRIMA = ta.sma(ta.sma(src, Nm), Nm)    TRIMAsrc = input.source(close, title='Source', group='Parameters')len = input.int(17, minval=1, title='Moving Averages', group='Parameters')out_ma_source = input.string(title='MA Type', defval='ALMA', options=['SMA', 'EMA', 'WMA', 'ALMA', 'SMMA', 'LSMA', 'VWMA', 'DEMA', 'HULL', 'KAMA', 'FRAMA', 'VIDYA', 'JMA', 'TEMA', 'ZLEMA', 'T3', 'TRIM'], group='Parameters')out_ma = out_ma_source == 'SMA' ? ta.sma(src, len) : out_ma_source == 'EMA' ? ta.ema(src, len) : out_ma_source == 'WMA' ? ta.wma(src, len) : out_ma_source == 'ALMA' ? ta.alma(src, len, 0.85, 6) : out_ma_source == 'SMMA' ? ta.rma(src, len) : out_ma_source == 'LSMA' ? ta.linreg(src, len, 0) : out_ma_source == 'VWMA' ? ta.vwma(src, len) : out_ma_source == 'DEMA' ? getDEMA(src, len) : out_ma_source == 'HULL' ? ta.hma(src, len) : out_ma_source == 'KAMA' ? getKAMA(src, len, 2, 30) : out_ma_source == 'FRAMA' ? getFRAMA(src, len) : out_ma_source == 'VIDYA' ? getVIDYA(src, len) : out_ma_source == 'JMA' ? getJMA(src, len, 2, 50) : out_ma_source == 'TEMA' ? getTEMA(src, len) : out_ma_source == 'ZLEMA' ? getZLEMA(src, len) : out_ma_source == 'T3' ? getT3(src, len, 0.7) : out_ma_source == 'TRIM' ? getTRIMA(src, len) : naplot(out_ma)long = close> out_ma and close[1] < out_ma and dayofweek==dayofweek.mondayshort = close< out_ma and close[1] > out_ma and dayofweek==dayofweek.mondaystopPer = input.float(10.0, title='LONG Stop Loss % ', group='Fixed Risk Management') / 100takePer = input.float(30.0, title='LONG Take Profit %', group='Fixed Risk Management') / 100stopPerShort = input.float(5.0, title='SHORT Stop Loss % ', group='Fixed Risk Management') / 100takePerShort = input.float(10.0, title='SHORT Take Profit %', group='Fixed Risk Management') / 100longStop = strategy.position_avg_price * (1 - stopPer)longTake = strategy.position_avg_price * (1 + takePer)shortStop = strategy.position_avg_price * (1 + stopPerShort)shortTake = strategy.position_avg_price * (1 - takePerShort)strategy.risk.max_intraday_filled_orders(2) // After 10 orders are filled, no more strategy orders will be placed (except for a market order to exit current open market position, if there is any).if(longEntry)    strategy.entry("long",strategy.long,when=long )    strategy.exit('LONG EXIT', "long", limit=longTake, stop=longStop)    strategy.close("long",when=dayofweek==dayofweek.sunday)if(shortEntry)    strategy.entry("short",strategy.short,when=short )    strategy.exit('SHORT EXIT', "short", limit=shortTake, stop=shortStop)    strategy.close("short",when=dayofweek==dayofweek.sunday)