Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Advanced OutSide with HMA and Klinger Forex Swing strategy

A Pine Script v4 strategy built on Change (hlc3), EMA (sv, 34) and HMA (close, 27). It has 4 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 no commission. 6 settings; defaults include Length 27, Source close and Take profit % for long 0.006.

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 Advanced OutSide with HMA and Klinger Forex Swing strategy repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did Advanced OutSide with HMA and Klinger Forex Swing strategy do on BTCUSDT 1D with default settings?
−1.29%
From 26 Jan 2024 to 21 Oct 2026, over 49 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Advanced OutSide with HMA and Klinger Forex Swing strategy be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does Advanced OutSide with HMA and Klinger Forex Swing strategy use a stop loss?
Yes
strategy.exit sets a stop on line 21, 22.
Does Advanced OutSide with HMA and Klinger Forex Swing strategy run in Zeal Terminal?
Yes
It compiles in 20 ms and runs 1,000 bars in 30 ms, in the browser.

BTCUSDT · 1D · default settings

  • Change
  • EMA
  • EMA
  • HMA
  • 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)
-50,0000.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$98,710$202,527Equity from $100,000
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.
Net profit
−1.29%
−$1,289.77
Buy and hold
+102.5%
same period
Closed trades
49
32 won · 17 lost
Profitable
65.3%
of closed trades
Profit factor
0.94
gross profit ÷ gross loss
Max drawdown
5.26%
−$5,291.24

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

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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.

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 change → ta.change, ema → ta.ema, hma → ta.hma.

v4 → v5

Differs

Trades differ: 49 before, 49 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 5: change → ta.change
  • Line 6: ema → ta.ema
  • Line 6: ema → ta.ema
  • Line 7: ema → ta.ema
  • Line 8: input(type = input.integer) → input.int()
  • Line 10: hma → ta.hma
⋯// © exlux99-//@version=4+//@version=5strategy("Advanced OutSide Forex strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.0)-sv = change(hlc3) >= 0 ? volume : -volume+sv = ta.change(hlc3) >= 0 ? volume : -volume-kvo = ema(sv, 34) - ema(sv, 55)+kvo = ta.ema(sv, 34) - ta.ema(sv, 55)-sig = ema(kvo, 13)+sig = ta.ema(kvo, 13)-length = input(title="Length", type=input.integer, defval=27)+length = input.int(title="Length", defval=27)src = input(close, title="Source")-lsma = hma(src, length)+lsma = ta.hma(src, length)if (high > high[1] and low < low[1])⋯

Clean v5

Verified

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

  • Line 9: input() → input.source()
  • Line 17: input() → input.float()
  • Line 18: input() → input.float()
  • Line 19: input() → input.float()
  • Line 20: input() → input.float()
⋯length = input.int(title="Length", defval=27)-src = input(close, title="Source")+src = input.source(close, title="Source")lsma = ta.hma(src, length)⋯        strategy.entry("short", strategy.short, comment="short")-tplong=input(0.006, step=0.001, title="Take profit % for long")+tplong=input.float(0.006, step=0.001, title="Take profit % for long")-sllong=input(0.012, step=0.001, title="Stop loss % for long")+sllong=input.float(0.012, step=0.001, title="Stop loss % for long")-tpshort=input(0.0075, step=0.001, title="Take profit % for short")+tpshort=input.float(0.0075, step=0.001, title="Take profit % for short")-slshort=input(0.015, step=0.001, title="Stop loss % for short")+slshort=input.float(0.015, step=0.001, title="Stop loss % for short")strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')⋯

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: 49 before, 32 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("Advanced OutSide Forex strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.0)⋯

Settings

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

SettingDefaultType and rangeFeeds
Length27int (written input.integer)lsma
Sourceclosesourcelsma
Take profit % for long0.006float · step 0.001exit short_tp/sl
Stop loss % for long0.012float · step 0.001exit short_tp/sl
Take profit % for short0.0075float · step 0.001exit short_tp/sl
Stop loss % for short0.015float · step 0.001exit short_tp/sl

What it calculates

  • Change (change, ta.change in v5)hlc3sv · line 5
  • EMA (ema, ta.ema in v5)sv, 34kvo · line 6
  • EMA (ema, ta.ema in v5)kvo, 13sig · line 7
  • HMA (hma, ta.hma in v5)Source (close), Length (27)lsma · line 10

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.

volumevolumeprice datahlc3hlc3price dataclosecloseprice datalengthLengthsetting · 27openopenprice datasvChange→ svkvoEMA→ kvosigEMA→ siglsmaHMA→ lsmaentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:short_tp/slexit short_tp/slstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open long long(close > open and kvo>0 and lsma<close)On13
Open short short(close < open and kvo<0 and lsma>close)On16
Exit short_tp/sl stop and limitevery barOn21
Exit short_tp/sl stop and limitevery barOn22

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.

17/17trades 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 11 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−1.3%+102.5%4965%0.945.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.4%+5.5%5969%1.1111.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+9.7%+9.8%4279%1.683.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−6.6%+8.4%4661%0.7312.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−7.8%+16.7%4558%0.6911.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−11.0%+21.5%5056%0.6214.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.7%+148.3%5269%1.124.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−8.7%+17.1%4156%0.6314.9%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 market1567%$205.08
Sideways market1958%−$3,017.92
Falling market1573%$1,523.07

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

How bad could the drawdown be?

10.5%

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

0%12%
All 49 trades
SideEntryExitBarsP&L
short6 Apr 2024 67,820.606 Apr 2024 68,837.900−$1,500.00
short9 Jun 2024 69,310.5011 Jun 2024 68,788.902$741.20
short20 Jun 2024 64,974.4020 Jun 2024 65,949.000−$1,488.62
long22 Jul 2024 68,165.4022 Jul 2024 67,347.400−$1,173.04
short6 Sep 2024 56,180.006 Sep 2024 55,758.700$724.35
long23 Sep 2024 63,578.8023 Sep 2024 62,815.800−$1,167.65
long27 Sep 2024 65,174.0027 Sep 2024 65,565.000$576.83
short3 Nov 2024 69,374.703 Nov 2024 68,854.400$725.36
short11 Dec 2024 96,593.0011 Dec 2024 95,868.600$730.79
short12 Jan 2025 94,600.0012 Jan 2025 93,890.500$736.27
long21 Jan 2025 102,260.0021 Jan 2025 101,033.000−$1,186.88
long24 Jan 2025 103,910.0024 Jan 2025 104,534.000$586.32
short5 Feb 2025 97,763.105 Feb 2025 97,029.900$737.29
short6 Feb 2025 96,612.406 Feb 2025 95,887.800$742.82
short9 Feb 2025 96,444.809 Feb 2025 95,721.400$748.39
short4 Mar 2025 86,221.204 Mar 2025 87,514.500−$1,508.00
short9 Apr 2025 76,322.409 Apr 2025 75,750.000$742.69
long10 Apr 2025 82,615.2010 Apr 2025 81,623.800−$1,197.23
long29 Apr 2025 95,011.2029 Apr 2025 93,871.000−$1,182.86
short20 Jun 2025 104,659.0020 Jun 2025 106,228.000−$1,460.82
short24 Aug 2025 115,438.0024 Aug 2025 114,572.000$719.46
long16 Sep 2025 115,350.0016 Sep 2025 116,042.000$579.88
short28 Sep 2025 109,636.0028 Sep 2025 111,280.000−$1,458.40
short12 Oct 2025 110,644.0012 Oct 2025 109,815.000$718.27
short16 Oct 2025 110,763.0016 Oct 2025 109,933.000$723.65
short7 Nov 2025 101,346.007 Nov 2025 100,586.000$729.08
short9 Nov 2025 102,313.009 Nov 2025 101,546.000$734.55
short23 Nov 2025 84,739.8023 Nov 2025 86,010.900−$1,480.11
short7 Dec 2025 89,236.807 Dec 2025 88,567.500$728.96
long8 Dec 2025 90,395.308 Dec 2025 90,937.700$587.54
long10 Dec 2025 92,678.8010 Dec 2025 91,566.700−$1,182.13
long22 Dec 2025 88,658.9022 Dec 2025 89,190.800$583.98
long27 Dec 2025 87,369.6027 Dec 2025 87,893.800$587.48
short8 Feb 2026 69,289.408 Feb 2026 70,328.700−$1,477.50
long6 Apr 2026 69,034.206 Apr 2026 69,448.400$582.14
long8 Apr 2026 71,924.208 Apr 2026 72,355.800$585.63
long10 Apr 2026 71,788.0010 Apr 2026 72,218.700$589.14
long17 Apr 2026 75,154.3017 Apr 2026 75,605.200$592.68
short20 May 2026 76,834.4021 May 2026 77,997.601−$1,504.51
short7 Jun 2026 60,884.607 Jun 2026 61,797.900−$1,468.01
long7 Jul 2026 64,042.907 Jul 2026 63,274.400−$1,156.80
long21 Jul 2026 65,255.5021 Jul 2026 65,647.100$571.46
long8 Aug 2026 64,923.209 Aug 2026 65,313.001$575.24
short13 Aug 2026 63,480.0013 Aug 2026 63,003.900$722.92
long15 Sep 2026 78,189.2015 Sep 2026 77,250.900−$1,165.35
short7 Oct 2026 85,549.907 Oct 2026 84,908.300$719.61
short15 Oct 2026 81,682.0015 Oct 2026 81,069.400$725.00
short18 Oct 2026 81,491.0018 Oct 2026 80,879.900$730.44
long21 Oct 2026 83,028.1021 Oct 2026 83,526.300$588.73

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
Advanced OutSide with HMA and Klinger Forex Swing strategy this page—v4 strategy−1.3%495.3%
TriautoETF(TQQQ) Short Strategy B1 by BBcomhma emav5 strategyNo trades on this market
RMI + Triple HMRSI + Double EVWRSI + TERSI + CMO Strategy by burgercrisishma emav4 strategyNo trades on this market
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalaiema hmav5 strategy+1.3%1135.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 20 msYes 1,000 bars in 30 msNot measured
PineTSNo v5 and v6 only—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. 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("Advanced OutSide Forex strategy", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_every_tick = true, commission_type = strategy.commission.percent, commission_value = 0.0)sv = change(hlc3) >= 0 ? volume : -volumekvo = ema(sv, 34) - ema(sv, 55)sig = ema(kvo, 13)length = input(title="Length", type=input.integer, defval=27)src = input(close, title="Source")lsma = hma(src, length)if (high > high[1] and low < low[1])    if (close > open and kvo>0 and lsma<close)        strategy.entry("long", strategy.long, comment="long")if (high < high[1] and low > low[1])            if (close < open and kvo<0 and lsma>close)        strategy.entry("short", strategy.short, comment="short")tplong=input(0.006, step=0.001, title="Take profit % for long")sllong=input(0.012, step=0.001, title="Stop loss % for long")tpshort=input(0.0075, step=0.001, title="Take profit % for short")slshort=input(0.015, step=0.001, title="Stop loss % for short")strategy.exit("short_tp/sl", "long", profit=close * tplong / syminfo.mintick, loss=close * sllong / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')strategy.exit("short_tp/sl", "short", profit=close * tpshort / syminfo.mintick, loss=close * slshort / syminfo.mintick, comment='SHORT EXIT',  alert_message = 'closeshort')