Pine Script v4 · Strategy
Swing-Daytrading strategy with reversal option
A Pine Script v4 strategy built on EMA (xPrice, 9). It has 10 order rules, 8 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 14 settings; defaults include From Day 1, From Month 1 and From Year 2000.
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-Daytrading strategy with reversal option 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-Daytrading strategy with reversal option do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Swing-Daytrading strategy with reversal option be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Swing-Daytrading strategy with reversal option use a stop loss?
- Yes
- strategy.exit sets a stop on line 63, 64.
- Does Swing-Daytrading strategy with reversal option run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- T3
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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.
-
Note
6 settings have no label
In the settings dialog Length (line 17), tp (line 43), sl (line 44), modified (line 45), inverse (line 46), exit (line 47) 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 51, 52, 57, 58, 67, 68, 73, 74. The upgraded version below moves each call inside an if block.
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 ema → ta.ema.
- 8 strategy calls use the when = argument (line 51, 52, 57, 58, 67, 68, 73, 74). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 19: ema → ta.ema
- Line 20: ema → ta.ema
- Line 21: ema → ta.ema
- Line 22: ema → ta.ema
- Line 23: ema → ta.ema
11 more edits
- Line 24: ema → ta.ema
- Line 32: input(type = input.session) → input.session()
- Line 34: input(type = input.session) → input.session()
- Line 51: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 52: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
- Line 57: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 58: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
- Line 67: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 68: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
- Line 73: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 74: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © SoftKill21-//@version=4+//@version=5strategy("CLOSE HIGH T3",overlay=true)⋯xPrice = close-xe1 = ema(xPrice, Length)+xe1 = ta.ema(xPrice, Length)-xe2 = ema(xe1, Length)+xe2 = ta.ema(xe1, Length)-xe3 = ema(xe2, Length)+xe3 = ta.ema(xe2, Length)-xe4 = ema(xe3, Length)+xe4 = ta.ema(xe3, Length)-xe5 = ema(xe4, Length)+xe5 = ta.ema(xe4, Length)-xe6 = ema(xe5, Length)+xe6 = ta.ema(xe5, Length)b = 0.7⋯plot(nT3Average, color=color.blue, title="T3")-myspecifictradingtimes = input('1000-1900', type=input.session, title="My Defined Hours")+myspecifictradingtimes = input.session('1000-1900', title="My Defined Hours")//myspecifictradingtimes2 = input('1000-1900', type=input.session, title="My Defined Hours")-exittime = input('2100-2115', type=input.session, title="exit time")+exittime = input.session('2100-2115', title="exit time")optionmacd=true⋯ if(inverse)- strategy.entry("long",1,when=short)+ strategy.entry("long",strategy.long,when=short)- strategy.entry("short",0,when=long)+ strategy.entry("short",strategy.short,when=long) /// strategy.exit("xlong","long",profit=200, loss=200)⋯ if(inverse==false)- strategy.entry("long",1,when=long)+ strategy.entry("long",strategy.long,when=long)- strategy.entry("short",0,when=short)+ strategy.entry("short",strategy.short,when=short) ⋯ if(inverse)- strategy.entry("long",1,when=short)+ strategy.entry("long",strategy.long,when=short)- strategy.entry("short",0,when=long)+ strategy.entry("short",strategy.short,when=long) /// strategy.exit("xlong","long",profit=200, loss=200)⋯ if(inverse==false)- strategy.entry("long",1,when=long)+ strategy.entry("long",strategy.long,when=long)- strategy.entry("short",0,when=short)+ strategy.entry("short",strategy.short,when=short) ⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
14 more edits
- Line 17: input() → input.int()
- Line 43: input() → input.float()
- Line 44: input() → input.float()
- Line 45: input() → input.bool()
- Line 46: input() → input.bool()
- Line 47: input() → input.bool()
- Line 51: when = short → if block
- Line 52: when = long → if block
- Line 57: when = long → if block
- Line 58: when = short → if block
- Line 67: when = short → if block
- Line 68: when = long → if block
- Line 73: when = long → if block
- Line 74: when = short → if block
⋯strategy("CLOSE HIGH T3",overlay=true)-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2000, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2000, title = "From Year", minval = 1970) //monday and session // To Date Inputs-toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 31, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2020, title = "To Year", minval = 1970)+toYear = input.int(defval = 2020, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)⋯timeinrange(res, sess) => time(res, sess) != 0-Length = input(9, minval=1)+Length = input.int(9, minval=1)xPrice = close⋯short =time_cond and (entrytime) and close < low[1] and close < nT3Average -tp = input(0.01)+tp = input.float(0.01)-sl = input(0.01)+sl = input.float(0.01)-modified=input(true)+modified=input.bool(true)-inverse=input(true)+inverse=input.bool(true)-exit = input(false)+exit = input.bool(false)if(modified)⋯ if(inverse)- strategy.entry("long",strategy.long,when=short)+ if short+ strategy.entry("long",strategy.long)- strategy.entry("short",strategy.short,when=long)+ if long+ strategy.entry("short",strategy.short) /// strategy.exit("xlong","long",profit=200, loss=200)⋯ if(inverse==false)- strategy.entry("long",strategy.long,when=long)+ if long+ strategy.entry("long",strategy.long)- strategy.entry("short",strategy.short,when=short)+ if short+ strategy.entry("short",strategy.short) ⋯ if(inverse)- strategy.entry("long",strategy.long,when=short)+ if short+ strategy.entry("long",strategy.long)- strategy.entry("short",strategy.short,when=long)+ if long+ strategy.entry("short",strategy.short) /// strategy.exit("xlong","long",profit=200, loss=200)⋯ if(inverse==false)- strategy.entry("long",strategy.long,when=long)+ if long+ strategy.entry("long",strategy.long)- strategy.entry("short",strategy.short,when=short)+ if short+ strategy.entry("short",strategy.short) ⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © SoftKill21-//@version=5+//@version=6strategy("CLOSE HIGH T3",overlay=true)⋯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 |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2000 | int · min 1970 | startDate |
| To Day | 31 | int · min 1 · max 31 | finishDate |
| To Month | 12 | int · min 1 · max 12 | finishDate |
| To Year | 2020 | int · min 1970 | finishDate |
| Length (no label in the script) | 9 | int · min 1 | xe1 xe2 xe3 xe4 xe5 xe6 |
| My Defined Hours | 1000-1900 | session | entrytime |
| exit time | 2100-2115 | session | exiton |
| Tp (no label in the script) | 0.01 | float | exit closelong exit closeshort |
| Sl (no label in the script) | 0.01 | float | exit closelong exit closeshort |
| Modified (no label in the script) | true | bool | line 48 line 65 |
| Inverse (no label in the script) | true | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 50 line 56 line 66 line 72 |
| Exit (no label in the script) | false | bool | exit closelong exit closeshort line 60 |
What it calculates
- EMA (
ema,ta.emain v5)xPrice, Length (9)xe1 · line 19 - EMA (
ema,ta.emain v5)xe1, Length (9)xe2 · line 20 - EMA (
ema,ta.emain v5)xe2, Length (9)xe3 · line 21 - EMA (
ema,ta.emain v5)xe3, Length (9)xe4 · line 22 - EMA (
ema,ta.emain v5)xe4, Length (9)xe5 · line 23 - EMA (
ema,ta.emain v5)xe5, Length (9)xe6 · line 24
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 | shorttime_cond and (entrytime) and close < low[1] and close < nT3Average | On | 51 |
| Open short short | longtime_cond and (entrytime ) and close > high[1] and close > nT3Average | On | 52 |
| Open long long | longtime_cond and (entrytime ) and close > high[1] and close > nT3Average | On | 57 |
| Open short short | shorttime_cond and (entrytime) and close < low[1] and close < nT3Average | On | 58 |
| Exit closelong stop and limit | (exit) | On | 63 |
| Exit closeshort stop and limit | (exit) | On | 64 |
| Open long long | shorttime_cond and (entrytime) and close < low[1] and close < nT3Average | On | 67 |
| Open short short | longtime_cond and (entrytime ) and close > high[1] and close > nT3Average | On | 68 |
| Open long long | longtime_cond and (entrytime ) and close > high[1] and close > nT3Average | On | 73 |
| Open short short | shorttime_cond and (entrytime) and close < low[1] and close < nT3Average | On | 74 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 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.0% | +9.8% | 0 | 0% | — | 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% | 0 | 0% | — | 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% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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-Daytrading strategy with reversal option this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | With a workaround 1,000 bars in 43 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 51, 52, 57, 58, 67, 68 and more) so the engine trades the way the script says. 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. 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/// © SoftKill21//@version=4strategy("CLOSE HIGH T3",overlay=true)fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2000, title = "From Year", minval = 1970) //monday and session // To Date InputstoDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2020, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDate timeinrange(res, sess) => time(res, sess) != 0Length = input(9, minval=1)xPrice = closexe1 = ema(xPrice, Length)xe2 = ema(xe1, Length)xe3 = ema(xe2, Length)xe4 = ema(xe3, Length)xe5 = ema(xe4, Length)xe6 = ema(xe5, Length)b = 0.7c1 = -b*b*bc2 = 3*b*b+3*b*b*bc3 = -6*b*b-3*b-3*b*b*bc4 = 1+3*b+b*b*b+3*b*bnT3Average = c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3plot(nT3Average, color=color.blue, title="T3")myspecifictradingtimes = input('1000-1900', type=input.session, title="My Defined Hours")//myspecifictradingtimes2 = input('1000-1900', type=input.session, title="My Defined Hours")exittime = input('2100-2115', type=input.session, title="exit time")optionmacd=trueentrytime = time(timeframe.period, myspecifictradingtimes) != 0exiton = time(timeframe.period, exittime) != 0//entrytime2 = time(timeframe.period, myspecifictradingtimes2) != 0// long =time_cond and (entrytime or entrytime2) and close > high[1] and close > nT3Average // short =time_cond and (entrytime or entrytime2) and close < low[1] and close < nT3Average long =time_cond and (entrytime ) and close > high[1] and close > nT3Average short =time_cond and (entrytime) and close < low[1] and close < nT3Average tp = input(0.01)sl = input(0.01)modified=input(true)inverse=input(true)exit = input(false)if(modified) if(not exiton) if(inverse) strategy.entry("long",1,when=short) strategy.entry("short",0,when=long) /// strategy.exit("xlong","long",profit=200, loss=200) // strategy.exit("xshort","short",profit=200, loss=200) if(inverse==false) strategy.entry("long",1,when=long) strategy.entry("short",0,when=short) if(exit) // strategy.close("long", when = crossover(close,nT3Average)) // strategy.close("short", when = crossunder(close,nT3Average)) strategy.exit("closelong", "long" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closelong") strategy.exit("closeshort", "short" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closeshort")if(modified==false) if(inverse) strategy.entry("long",1,when=short) strategy.entry("short",0,when=long) /// strategy.exit("xlong","long",profit=200, loss=200) // strategy.exit("xshort","short",profit=200, loss=200) if(inverse==false) strategy.entry("long",1,when=long) strategy.entry("short",0,when=short) // if(exit) // // strategy.close("long", when = crossover(close,nT3Average)) // // strategy.close("short", when = crossunder(close,nT3Average)) // strategy.exit("closelong", "long" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closelong") // strategy.exit("closeshort", "short" , profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closeshort")//strategy.close_all(when =exiton )//gbpnzd 10-20//gbpcad 10-19//gbpaud 07-19//euruad 10-19 / 16-20//eurnzd 08-21 / 10-20//eurchf 08-20//gbpchf 06-18// 18-19settings entry gbp aud, gbpcad gbpnzd ??? 1 entry only big spread//test