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
- 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
DiffersTrades 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
VerifiedSame 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length | 27 | int (written input.integer) | lsma |
| Source | close | source | lsma |
| Take profit % for long | 0.006 | float · step 0.001 | exit short_tp/sl |
| Stop loss % for long | 0.012 | float · step 0.001 | exit short_tp/sl |
| Take profit % for short | 0.0075 | float · step 0.001 | exit short_tp/sl |
| Stop loss % for short | 0.015 | float · step 0.001 | exit short_tp/sl |
What it calculates
- Change (
change,ta.changein v5)hlc3sv · line 5 - EMA (
ema,ta.emain v5)sv, 34kvo · line 6 - EMA (
ema,ta.emain v5)kvo, 13sig · line 7 - HMA (
hma,ta.hmain 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | (close > open and kvo>0 and lsma<close) | On | 13 |
| Open short short | (close < open and kvo<0 and lsma>close) | On | 16 |
| Exit short_tp/sl stop and limit | every bar | On | 21 |
| Exit short_tp/sl stop and limit | every bar | On | 22 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −1.3% | +102.5% | 49 | 65% | 0.94 | 5.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.4% | +5.5% | 59 | 69% | 1.11 | 11.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +9.7% | +9.8% | 42 | 79% | 1.68 | 3.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.6% | +8.4% | 46 | 61% | 0.73 | 12.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −7.8% | +16.7% | 45 | 58% | 0.69 | 11.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −11.0% | +21.5% | 50 | 56% | 0.62 | 14.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +2.7% | +148.3% | 52 | 69% | 1.12 | 4.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −8.7% | +17.1% | 41 | 56% | 0.63 | 14.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 15 | 67% | $205.08 |
| Sideways market | 19 | 58% | −$3,017.92 |
| Falling market | 15 | 73% | $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.
All 49 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 6 Apr 2024 67,820.60 | 6 Apr 2024 68,837.90 | 0 | −$1,500.00 |
| short | 9 Jun 2024 69,310.50 | 11 Jun 2024 68,788.90 | 2 | $741.20 |
| short | 20 Jun 2024 64,974.40 | 20 Jun 2024 65,949.00 | 0 | −$1,488.62 |
| long | 22 Jul 2024 68,165.40 | 22 Jul 2024 67,347.40 | 0 | −$1,173.04 |
| short | 6 Sep 2024 56,180.00 | 6 Sep 2024 55,758.70 | 0 | $724.35 |
| long | 23 Sep 2024 63,578.80 | 23 Sep 2024 62,815.80 | 0 | −$1,167.65 |
| long | 27 Sep 2024 65,174.00 | 27 Sep 2024 65,565.00 | 0 | $576.83 |
| short | 3 Nov 2024 69,374.70 | 3 Nov 2024 68,854.40 | 0 | $725.36 |
| short | 11 Dec 2024 96,593.00 | 11 Dec 2024 95,868.60 | 0 | $730.79 |
| short | 12 Jan 2025 94,600.00 | 12 Jan 2025 93,890.50 | 0 | $736.27 |
| long | 21 Jan 2025 102,260.00 | 21 Jan 2025 101,033.00 | 0 | −$1,186.88 |
| long | 24 Jan 2025 103,910.00 | 24 Jan 2025 104,534.00 | 0 | $586.32 |
| short | 5 Feb 2025 97,763.10 | 5 Feb 2025 97,029.90 | 0 | $737.29 |
| short | 6 Feb 2025 96,612.40 | 6 Feb 2025 95,887.80 | 0 | $742.82 |
| short | 9 Feb 2025 96,444.80 | 9 Feb 2025 95,721.40 | 0 | $748.39 |
| short | 4 Mar 2025 86,221.20 | 4 Mar 2025 87,514.50 | 0 | −$1,508.00 |
| short | 9 Apr 2025 76,322.40 | 9 Apr 2025 75,750.00 | 0 | $742.69 |
| long | 10 Apr 2025 82,615.20 | 10 Apr 2025 81,623.80 | 0 | −$1,197.23 |
| long | 29 Apr 2025 95,011.20 | 29 Apr 2025 93,871.00 | 0 | −$1,182.86 |
| short | 20 Jun 2025 104,659.00 | 20 Jun 2025 106,228.00 | 0 | −$1,460.82 |
| short | 24 Aug 2025 115,438.00 | 24 Aug 2025 114,572.00 | 0 | $719.46 |
| long | 16 Sep 2025 115,350.00 | 16 Sep 2025 116,042.00 | 0 | $579.88 |
| short | 28 Sep 2025 109,636.00 | 28 Sep 2025 111,280.00 | 0 | −$1,458.40 |
| short | 12 Oct 2025 110,644.00 | 12 Oct 2025 109,815.00 | 0 | $718.27 |
| short | 16 Oct 2025 110,763.00 | 16 Oct 2025 109,933.00 | 0 | $723.65 |
| short | 7 Nov 2025 101,346.00 | 7 Nov 2025 100,586.00 | 0 | $729.08 |
| short | 9 Nov 2025 102,313.00 | 9 Nov 2025 101,546.00 | 0 | $734.55 |
| short | 23 Nov 2025 84,739.80 | 23 Nov 2025 86,010.90 | 0 | −$1,480.11 |
| short | 7 Dec 2025 89,236.80 | 7 Dec 2025 88,567.50 | 0 | $728.96 |
| long | 8 Dec 2025 90,395.30 | 8 Dec 2025 90,937.70 | 0 | $587.54 |
| long | 10 Dec 2025 92,678.80 | 10 Dec 2025 91,566.70 | 0 | −$1,182.13 |
| long | 22 Dec 2025 88,658.90 | 22 Dec 2025 89,190.80 | 0 | $583.98 |
| long | 27 Dec 2025 87,369.60 | 27 Dec 2025 87,893.80 | 0 | $587.48 |
| short | 8 Feb 2026 69,289.40 | 8 Feb 2026 70,328.70 | 0 | −$1,477.50 |
| long | 6 Apr 2026 69,034.20 | 6 Apr 2026 69,448.40 | 0 | $582.14 |
| long | 8 Apr 2026 71,924.20 | 8 Apr 2026 72,355.80 | 0 | $585.63 |
| long | 10 Apr 2026 71,788.00 | 10 Apr 2026 72,218.70 | 0 | $589.14 |
| long | 17 Apr 2026 75,154.30 | 17 Apr 2026 75,605.20 | 0 | $592.68 |
| short | 20 May 2026 76,834.40 | 21 May 2026 77,997.60 | 1 | −$1,504.51 |
| short | 7 Jun 2026 60,884.60 | 7 Jun 2026 61,797.90 | 0 | −$1,468.01 |
| long | 7 Jul 2026 64,042.90 | 7 Jul 2026 63,274.40 | 0 | −$1,156.80 |
| long | 21 Jul 2026 65,255.50 | 21 Jul 2026 65,647.10 | 0 | $571.46 |
| long | 8 Aug 2026 64,923.20 | 9 Aug 2026 65,313.00 | 1 | $575.24 |
| short | 13 Aug 2026 63,480.00 | 13 Aug 2026 63,003.90 | 0 | $722.92 |
| long | 15 Sep 2026 78,189.20 | 15 Sep 2026 77,250.90 | 0 | −$1,165.35 |
| short | 7 Oct 2026 85,549.90 | 7 Oct 2026 84,908.30 | 0 | $719.61 |
| short | 15 Oct 2026 81,682.00 | 15 Oct 2026 81,069.40 | 0 | $725.00 |
| short | 18 Oct 2026 81,491.00 | 18 Oct 2026 80,879.90 | 0 | $730.44 |
| long | 21 Oct 2026 83,028.10 | 21 Oct 2026 83,526.30 | 0 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Advanced OutSide with HMA and Klinger Forex Swing strategy this page | — | v4 strategy | −1.3% | 49 | 5.3% |
| TriautoETF(TQQQ) Short Strategy B1 by BBcom | hma ema | v5 strategy | No trades on this market | ||
| RMI + Triple HMRSI + Double EVWRSI + TERSI + CMO Strategy by burgercrisis | hma ema | v4 strategy | No trades on this market | ||
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalai | ema hma | v5 strategy | +1.3% | 113 | 5.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 20 ms | Yes 1,000 bars in 30 ms | Not measured |
| PineTS | No 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')