Pine Script v5 · Strategy
Outside Day
A Pine Script v5 strategy built on ATR (20). It has 5 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 50% of equity and pays no commission. 5 settings; defaults include Period 20, Multiplier 1.0 and Max bars with open trading 3.
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 Outside Day repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 13 of 13 trades.
- How did Outside Day do on BTCUSDT 1D with default settings?
- −7.39%
- From 26 Jan 2024 to 21 Oct 2026, over 52 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Outside Day run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C51: 'strategy.entry' has no 'when' parameter in Pine Script v6. Put the call inside an 'if' instead. The v6 version is shown for reference and is not offered as a download.
- Does Outside Day use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does Outside Day run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 44 ms, in the browser.
BTCUSDT · 1D · default settings
- Take profit
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −7.39%
- −$73,911.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 52
- 32 won · 11 lost
- Profitable
- 61.5%
- of closed trades
- Profit factor
- 0.85
- gross profit ÷ gross loss
- Max drawdown
- 25.06%
- −$250,643.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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 stop loss
strategy.exit is used without a stop, loss or trailing stop.
-
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.
-
Note
Uses an argument v6 removed
when = on line 29, 30. 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| ATR settings | |||
| Period | 20 | int | atr |
| Multiplier | 1.0 | float · min 0.0 · step 0.1 | atr exit Long exit Short line 22 line 31 line 52 |
| Entry settings | |||
| Max bars with open tradingDetermine how many bars you can stay with an open position.\nEntries longer than this will automatically be closed. | 3 | int · min 0 | exitMessage exitLateCond |
| Direction of orders | BOTH | string | entry Long entry Short line 31 |
| Exit settings | |||
| Mean reverseEntries will be done as a mean reverse, so it will sell at up days, and buy at down days. | true | bool | line 34 line 39 |
What it calculates
- ATRPeriod (20)
atr · line 23
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 | DIRECTION != SHORT | On | 29 |
| Open Short short | DIRECTION != LONG | On | 30 |
| Exit Long limit | ATR_MULT != 0.0 | On | 53 |
| Exit Short limit | ATR_MULT != 0.0 | On | 54 |
| Close exitLateCond | every bar | On | 58 |
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, and the live replay matched history.
- 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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 | −7.4% | +102.5% | 52 | 62% | 0.85 | 25.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.3% | +5.5% | 65 | 66% | 0.78 | 13.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.6% | +9.8% | 53 | 68% | 1.01 | 46.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −14.0% | +8.4% | 45 | 60% | 0.56 | 21.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −6.4% | +16.7% | 48 | 56% | 0.91 | 41.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +22.6% | +21.5% | 51 | 78% | 2.98 | 7.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −12.7% | +148.3% | 37 | 62% | 0.77 | 31.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +20.8% | +17.1% | 52 | 87% | 6.51 | 3.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 22 | 64% | −$24,069.20 |
| Sideways market | 18 | 61% | $36,544.20 |
| Falling market | 12 | 58% | −$86,386.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
30.5%
The 95th percentile of the worst drawdown when the same 52 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 15.6% to 30.5%; the tick is what actually happened, 21.2%. Order luck alone moves it this much.
All 52 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 26 Feb 2024 54,476.50 | 17 Apr 2024 61,277.40 | 51 | −$62,420.50 |
| long | 17 Apr 2024 61,277.40 | 17 Apr 2024 61,277.40 | 0 | $0.00 |
| long | 30 Apr 2024 60,672.00 | 4 May 2024 63,850.10 | 4 | $24,556.20 |
| short | 9 May 2024 63,074.00 | 19 May 2024 66,274.00 | 10 | −$24,406.50 |
| long | 19 May 2024 66,274.00 | 19 May 2024 66,274.00 | 0 | $0.00 |
| long | 7 Jun 2024 69,355.60 | 9 Jun 2024 69,648.10 | 2 | $1,977.66 |
| short | 9 Jun 2024 69,648.10 | 11 Jun 2024 66,956.50 | 2 | $18,158.20 |
| short | 21 Jul 2024 68,165.30 | 23 Jul 2024 65,734.40 | 2 | $17,079.80 |
| long | 29 Jul 2024 66,784.70 | 2 Sep 2024 59,132.10 | 35 | −$55,857.30 |
| short | 2 Sep 2024 59,132.10 | 2 Sep 2024 59,132.10 | 0 | $0.00 |
| short | 8 Sep 2024 54,869.90 | 21 Oct 2024 67,377.50 | 43 | −$104,753.00 |
| long | 21 Oct 2024 67,377.50 | 21 Oct 2024 67,377.50 | 0 | $0.00 |
| long | 25 Nov 2024 93,010.00 | 27 Nov 2024 96,334.60 | 2 | $14,554.00 |
| short | 8 Dec 2024 101,110.00 | 9 Dec 2024 97,373.00 | 1 | $15,316.20 |
| long | 26 Dec 2024 95,791.60 | 6 Jan 2025 99,908.60 | 11 | $18,141.30 |
| long | 7 Jan 2025 96,954.60 | 15 Jan 2025 100,681.00 | 8 | $16,570.60 |
| long | 19 Jan 2025 101,332.00 | 20 Jan 2025 105,240.00 | 1 | $16,949.60 |
| long | 26 Jan 2025 102,620.00 | 9 Apr 2025 82,615.20 | 73 | −$87,320.30 |
| short | 9 Apr 2025 82,615.20 | 9 Apr 2025 82,615.20 | 0 | $0.00 |
| long | 15 Apr 2025 83,644.00 | 21 Apr 2025 87,545.00 | 6 | $18,854.80 |
| long | 27 Apr 2025 93,749.30 | 1 May 2025 96,975.60 | 4 | $14,237.10 |
| short | 6 May 2025 96,834.00 | 12 May 2025 102,791.00 | 6 | −$25,889.10 |
| long | 12 May 2025 102,791.00 | 12 May 2025 102,791.00 | 0 | $0.00 |
| long | 20 Jun 2025 103,298.00 | 24 Jun 2025 106,205.00 | 4 | $11,478.70 |
| long | 30 Jun 2025 107,147.00 | 2 Jul 2025 108,850.00 | 2 | $6,574.42 |
| short | 2 Jul 2025 108,850.00 | 20 Jul 2025 117,265.00 | 18 | −$32,232.00 |
| long | 20 Jul 2025 117,265.00 | 20 Jul 2025 117,265.00 | 0 | $0.00 |
| short | 22 Jul 2025 119,954.00 | 25 Jul 2025 117,016.00 | 3 | $9,818.29 |
| long | 31 Jul 2025 115,764.00 | 3 Aug 2025 114,209.00 | 3 | −$5,450.47 |
| short | 3 Aug 2025 114,209.00 | 5 Aug 2025 112,957.00 | 2 | $4,417.85 |
| long | 14 Aug 2025 118,295.00 | 22 Aug 2025 116,936.00 | 8 | −$4,655.12 |
| short | 22 Aug 2025 116,936.00 | 23 Aug 2025 115,267.00 | 1 | $5,748.31 |
| short | 24 Sep 2025 113,307.00 | 25 Sep 2025 110,919.00 | 1 | $8,549.66 |
| short | 19 Oct 2025 108,643.00 | 4 Nov 2025 104,836.00 | 16 | $14,364.90 |
| short | 9 Nov 2025 104,723.00 | 11 Nov 2025 103,059.00 | 2 | $6,628.71 |
| long | 11 Nov 2025 103,059.00 | 7 Dec 2025 90,395.30 | 26 | −$51,669.70 |
| short | 7 Dec 2025 90,395.30 | 7 Dec 2025 90,395.30 | 0 | $0.00 |
| short | 9 Dec 2025 92,678.80 | 14 Dec 2025 88,862.80 | 5 | $16,250.10 |
| short | 21 Dec 2025 88,658.90 | 29 Dec 2025 87,237.10 | 8 | $6,459.07 |
| long | 29 Dec 2025 87,237.10 | 5 Jan 2026 92,184.10 | 7 | $23,024.00 |
| short | 11 Jan 2026 91,013.60 | 20 Jan 2026 88,478.00 | 9 | $11,632.30 |
| short | 5 Apr 2026 69,034.20 | 26 May 2026 75,930.00 | 51 | −$42,287.90 |
| long | 26 May 2026 75,930.00 | 26 May 2026 75,930.00 | 0 | $0.00 |
| short | 6 Jul 2026 64,042.00 | 8 Jul 2026 61,794.40 | 2 | $14,115.60 |
| long | 13 Jul 2026 62,334.50 | 14 Jul 2026 64,390.90 | 1 | $13,501.00 |
| short | 20 Jul 2026 65,255.50 | 27 Jul 2026 63,755.90 | 7 | $9,560.38 |
| long | 27 Jul 2026 63,755.90 | 19 Aug 2026 67,180.50 | 23 | $22,602.80 |
| long | 28 Aug 2026 77,845.90 | 3 Sep 2026 80,102.50 | 6 | $12,525.40 |
| short | 6 Sep 2026 80,341.80 | 8 Sep 2026 78,109.70 | 2 | $12,178.80 |
| short | 14 Sep 2026 78,189.20 | 15 Sep 2026 76,025.10 | 1 | $12,301.20 |
| long | 23 Sep 2026 84,397.60 | 2 Oct 2026 86,827.80 | 9 | $12,974.50 |
| long | 12 Oct 2026 81,850.00 | 13 Oct 2026 83,986.10 | 1 | $11,928.90 |
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 |
|---|---|---|---|---|---|
| Outside Day this page | — | v5 strategy | −7.4% | 52 | 25.1% |
| SOJA PIVOT by ParaBellum68 | atr | v4 strategy | +3.3% | 9 | 18.2% |
| Volatility System by EduardoMattje | atr | v5 strategy | +150.2% | 2 | 21.5% |
| ATR Stop Buy Strategy by phobo3s | atr | v4 strategy | No trades on this market | ||
| VBand Strategy by Saravanan_Ragavan | atr | v4 strategy | No trades on this market | ||
| Volatility Breakout Strategy [Angel Algo] by AngelAlgo | atr | v5 strategy | +3.1% | 18 | 3.6% |
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.
- 2 strategy calls use the when = argument (line 29, 30). 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
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C51: 'strategy.entry' has no 'when' parameter in Pine Script v6. Put the call inside an 'if' instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © EduardoMattje-//@version=5+//@version=6strategy("Outside Day", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=50,⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | Yes 1,000 bars in 44 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © EduardoMattje//@version=5strategy("Outside Day", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=50, process_orders_on_close=true, margin_long=100, margin_short=100)// Constantsvar G_ATR = "ATR settings"var G_ENTRY = "Entry settings"var G_EXIT = "Exit settings"var LONG = "Long"var SHORT = "Short"var BOTH = "Both"// Inputsvar ATR_PERIOD = input.int(20, "Period", 1, inline=G_ATR, group=G_ATR)var ATR_MULT = input.float(1.0, "Multiplier", minval=0.0, step=0.1, inline=G_ATR, group=G_ATR)var MAX_BARS = input.int(3, "Max bars with open trading", minval=0, tooltip="Determine how many bars you can stay with an open position.\nEntries longer than this will automatically be closed.", group=G_ENTRY)var DIRECTION = input.string(BOTH, "Direction of orders", [BOTH, LONG, SHORT])var MEAN_REVERSE = input.bool(true, "Mean reverse", tooltip="Entries will be done as a mean reverse, so it will sell at up days, and buy at down days.", group=G_EXIT)// ATRvar float atr = naif ATR_MULT != 0.0 atr := ta.atr(ATR_PERIOD) * ATR_MULT// ConditionsoutsideDay = high[0] > high[1] and low[0] < low[1]outsideLow = close[0] < low[1]outsideHigh = close[0] > high[1]// Entry ordersenterLong() => strategy.entry(LONG, strategy.long, when=DIRECTION != SHORT)enterShort() => strategy.entry(SHORT, strategy.short, when=DIRECTION != LONG)if not na(atr) or (DIRECTION == BOTH and ATR_MULT == 0) if outsideDay if outsideLow if MEAN_REVERSE enterLong() else enterShort() else if outsideHigh if MEAN_REVERSE enterShort() else enterLong()// Exit ordersvar float entryPrice = navar float longTarget = navar float shortTarget = natargetCalc(increment_) => entryPrice + increment_if strategy.position_size[0] == 0.0 entryPrice := close longTarget := targetCalc(atr) shortTarget := targetCalc(-atr)if ATR_MULT != 0.0 strategy.exit("Long", "Long", limit=longTarget) strategy.exit("Short", "Short", limit=shortTarget)daysInTrade = ta.barssince(strategy.opentrades == 0)exitMessage = "This position has remained open for more than " + str.tostring(MAX_BARS) + " day" + (MAX_BARS > 1 ? "s" : "")exitLateCond = daysInTrade >= MAX_BARS and MAX_BARS != 0strategy.close_all(exitLateCond, exitMessage)// PlotsplotTarget = strategy.position_size > 0 ? longTarget : strategy.position_size < 0 ? shortTarget : naplotTarget := not exitLateCond[1] and strategy.position_size[1] != 0 ? plotTarget[1] : plotTarget[0]var color p_color = naif strategy.position_size > 0 p_color := color.tealelse if strategy.position_size < 0 p_color := color.redplot(plotTarget, "Take profit", p_color, 2, plot.style_linebr)