Pine Script v5 · Strategy
Swing Trades Validator - The One Trader
A Pine Script v5 strategy built on EMA (close, 8). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 3 settings; defaults include Profit Target % 10 and Stop Loss % 10.
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 Trades Validator - The One Trader repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did Swing Trades Validator - The One Trader do on BTCUSDT 1D with default settings?
- +0.68%
- 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 Trades Validator - The One Trader 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: 5 before, 4 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 Trades Validator - The One Trader use a stop loss?
- Yes
- strategy.exit sets a stop on line 75.
- Does Swing Trades Validator - The One Trader run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 191 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.68%
- $6,755.03
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 3 won · 2 lost
- Profitable
- 60.0%
- of closed trades
- Profit factor
- 1.30
- gross profit ÷ gross loss
- Max drawdown
- 1.17%
- −$11,941.60
One run with the author's default settings, $1,000,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.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 |
|---|---|---|---|
| Profit Target % | 10 | float · min 1 · step 0.05 | ProfitTarget |
| Stop Loss % | 10 | float · min 1 · step 0.05 | StopLoss |
| Enhanced Entry Rules | true | bool | pullback |
What it calculates
- EMAclose, 8
emaH · line 11 - EMAclose[1], 8
emaHyest · line 12 - EMAclose[2], 8
emaHyest1 · line 13 - EMAclose[3], 8
emaHyest2 · line 14 - EMAclose, 21
emaL · line 15 - EMAclose[1], 21
emaLyest · line 16 - EMAclose[2], 21
emaLyest1 · line 17 - EMAclose[3], 21
emaLyest2 · line 18 - EMAclose, 50
emaf · line 19 - EMAclose, 200
emath · line 20 - EMAhigh, 200
emathhigh · line 21 - EMAlow, 200
emathlow · line 22
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 | (longCondition) | On | 74 |
| Exit Exit stop and limit | (longCondition) | On | 75 |
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.
- CheckHigher-timeframe data10 request.security call(s) use lookahead_on (line 40, 41, 42, 43, 44, 45, 46, 47, 48, 49). Without a [1] offset this reads future bars in history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.7% | +102.5% | 5 | 60% | 1.30 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.1% | +9.8% | 2 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 6 | 67% | 1.74 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 10 | 60% | 1.36 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT M (Binance BTCUSDT 1M), 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 33% | −$10,827.60 |
| Sideways market | 2 | 100% | $17,582.60 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.2%
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, 1.2% to 2.2%; the tick is what actually happened, 1.2%. Order luck alone moves it this much.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Oct 2024 69,962.20 | 8 Nov 2024 76,899.40 | 10 | $6,937.21 |
| long | 21 Jan 2025 102,260.00 | 3 Feb 2025 91,772.90 | 13 | −$10,487.10 |
| long | 7 May 2025 96,834.00 | 21 May 2025 107,479.00 | 14 | $10,645.40 |
| long | 26 May 2025 109,004.00 | 14 Jul 2025 120,605.00 | 49 | $11,601.00 |
| long | 28 Jul 2025 119,416.00 | 29 Aug 2025 107,474.00 | 32 | −$11,941.60 |
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 |
|---|---|---|---|---|---|
| Swing Trades Validator - The One Trader this page | — | v5 strategy | +0.7% | 5 | 1.2% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
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: 5 before, 4 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.
⋯// © the_daily_trader-//@version=5+//@version=6// --------------------- Start of Code ---------------------⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 191 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © the_daily_trader//@version=5// --------------------- Start of Code ---------------------strategy("Swing Trades Validator", overlay=true, margin_long=100, pyramiding = 0)// Indicator Display ChecksTakeProfitPercent = input.float(title="Profit Target %", defval=10, minval=1, step=0.05)StopLossPercent = input.float(title="Stop Loss %", defval=10, minval=1, step=0.05)pullbackchoice = input.bool(true, "Enhanced Entry Rules")// EMAsemaH = ta.ema(close, 8)emaHyest = ta.ema(close[1], 8)emaHyest1 = ta.ema(close[2], 8)emaHyest2 = ta.ema(close[3], 8)emaL = ta.ema(close, 21)emaLyest = ta.ema(close[1], 21)emaLyest1 = ta.ema(close[2], 21)emaLyest2 = ta.ema(close[3], 21)emaf = ta.ema(close, 50)emath = ta.ema(close, 200)emathhigh = ta.ema(high, 200)emathlow = ta.ema(low, 200)emaslowmonthly = request.security(syminfo.tickerid, "M", emaL) // Monthly 21emaemafastmonthly = request.security(syminfo.tickerid, "M", emaH) // Monthly 8emaemaslowweekly = request.security(syminfo.tickerid, "W", emaL) // Weekly 21emaemafastweekly = request.security(syminfo.tickerid, "W", emaH) // Weekly 8emaemaslowdaily = request.security(syminfo.tickerid, "D", emaL) // Daily 21emaemafastdaily = request.security(syminfo.tickerid, "D", emaH) // Daily 8emaemafdaily = request.security(syminfo.tickerid, "D", emaf) // Daily 50emaemathdaily = request.security(syminfo.tickerid, "D", emath) // Daily emaemathdailyhigh = request.security(syminfo.tickerid, "D", emathhigh) // Daily ema Highemathdailylow = request.security(syminfo.tickerid, "D", emathlow) // Daily ema Lowema21yest = request.security(syminfo.tickerid, "D", emaLyest) // Daily 21ema 1 day agoema21yest1 = request.security(syminfo.tickerid, "D", emaLyest1) // Daily 21ema 2 days agoema21yest2 = request.security(syminfo.tickerid, "D", emaLyest2) // Daily 21ema 3 days agoema8yest = request.security(syminfo.tickerid, "D", emaHyest) // Daily 8ema 1 day agoema8yest1 = request.security(syminfo.tickerid, "D", emaHyest1) // Daily 8ema 2 days agoema8yest2 = request.security(syminfo.tickerid, "D", emaHyest2) // Daily 8ema 3 days ago// Pricesmonthopen = request.security(syminfo.tickerid, 'M', open, barmerge.gaps_off, barmerge.lookahead_on)monthclose = request.security(syminfo.tickerid, 'M', close, barmerge.gaps_off, barmerge.lookahead_on)weekopen = request.security(syminfo.tickerid, 'W', open, barmerge.gaps_off, barmerge.lookahead_on)weekclose = request.security(syminfo.tickerid, 'W', close, barmerge.gaps_off, barmerge.lookahead_on)dayopen = request.security(syminfo.tickerid, 'D', open, barmerge.gaps_off, barmerge.lookahead_on)dayclose = request.security(syminfo.tickerid, 'D', close, barmerge.gaps_off, barmerge.lookahead_on)threedayhigh = request.security(syminfo.tickerid, 'D', high[3], barmerge.gaps_off, barmerge.lookahead_on)twodayhigh = request.security(syminfo.tickerid, 'D', high[2], barmerge.gaps_off, barmerge.lookahead_on)yesthigh = request.security(syminfo.tickerid, 'D', high[1], barmerge.gaps_off, barmerge.lookahead_on)yestlow = request.security(syminfo.tickerid, 'D', low[1], barmerge.gaps_off, barmerge.lookahead_on)// Conditions monthlybullish = emafastmonthly > emaslowmonthlymonthlybullishprice = close > emafastmonthlymonthlybullishcandle = monthclose > monthopenweeklybullish = emafastweekly > emaslowweeklyweeklybullishprice = close > emafastweeklyweeklybullishcandle = weekclose > weekopenrealbullish = dayclose > emathdailyhighgoldencross = emafdaily > emathdailyhighdailybullish1 = emafdaily > emathdailydailybullish2 = emafastdaily > emaslowdailydailybullishprice = close > emafastdailydailybullishcandle = dayclose > dayopenringlow = yestlow <= ema8yestaggropullback = twodayhigh < threedayhighpullback = (pullbackchoice ? aggropullback : 0)pullbackfailure = dayclose > yesthigh and yesthigh < twodayhigh or pullbackemasetup = ema8yest > ema21yest and ema8yest1 > ema21yest1 and ema8yest2 > ema21yest2// Target Profit and Stop Loss Inputs// Input parameters can be found at the beginning of the codeProfitTarget = (close * (TakeProfitPercent / 100)) / syminfo.mintickStopLoss = (close * (StopLossPercent / 100)) / syminfo.minticklongCondition = monthlybullish and monthlybullishprice and monthlybullishcandle and weeklybullish and weeklybullishprice and weeklybullishcandle and dailybullish1 and dailybullish2 and dailybullishprice and dailybullishcandle and ringlow and pullbackfailure and emasetup and realbullish and goldencrossif (longCondition) strategy.entry("Long", strategy.long) strategy.exit ("Exit", "Long", profit = ProfitTarget, loss = StopLoss)// -----------xxxxxxxxxxx------------- End of Code -----------xxxxxxxxxxx---------------