Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$911,496$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
ATR settings
Period20intatr
Multiplier1.0float · min 0.0 · step 0.1atr 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.3int · min 0exitMessage exitLateCond
Direction of ordersBOTHstringentry 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.trueboolline 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.

high · low · closehigh · low · closeprice dataATR_PERIODPeriodsetting · 20ATR_MULTMultipliersetting · 1.0closecloseprice dataMAX_BARSMax bars with open trad…setting · 3lowlowprice datahighhighprice dataDIRECTIONDirection of orderssetting · BOTHatrATR→ atrentryPriceentryPricevaluelongTarget, shortTargetlongTarget · shortTarget2 valuesexitMessageexitMessagevalueplotTargetplotTargetvalueoutsideDayoutsideDayconditionoutsideLowoutsideLowconditionoutsideHighoutsideHighconditiondaysInTradedaysInTradeconditionexitLateCondexitLateCondconditionp_colorColourp_colorentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Longexit Longstrategy.exitexit:Shortexit Shortstrategy.exitclose_all:exitLateCondclose_all exitLateCondstrategy.close_allplot:67Take profitplot

Order rules

OrderFires whenBy defaultLine
Open Long longDIRECTION != SHORTOn29
Open Short shortDIRECTION != LONGOn30
Exit Long limitATR_MULT != 0.0On53
Exit Short limitATR_MULT != 0.0On54
Close exitLateCondevery barOn58

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.

13/13trades 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. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−7.4%+102.5%5262%0.8525.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.3%+5.5%6566%0.7813.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.6%+9.8%5368%1.0146.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−14.0%+8.4%4560%0.5621.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−6.4%+16.7%4856%0.9141.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+22.6%+21.5%5178%2.987.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−12.7%+148.3%3762%0.7731.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+20.8%+17.1%5287%6.513.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 barsTradesWonP&L
Rising market2264%−$24,069.20
Sideways market1861%$36,544.20
Falling market1258%−$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.

0%35%
All 52 trades
SideEntryExitBarsP&L
short26 Feb 2024 54,476.5017 Apr 2024 61,277.4051−$62,420.50
long17 Apr 2024 61,277.4017 Apr 2024 61,277.400$0.00
long30 Apr 2024 60,672.004 May 2024 63,850.104$24,556.20
short9 May 2024 63,074.0019 May 2024 66,274.0010−$24,406.50
long19 May 2024 66,274.0019 May 2024 66,274.000$0.00
long7 Jun 2024 69,355.609 Jun 2024 69,648.102$1,977.66
short9 Jun 2024 69,648.1011 Jun 2024 66,956.502$18,158.20
short21 Jul 2024 68,165.3023 Jul 2024 65,734.402$17,079.80
long29 Jul 2024 66,784.702 Sep 2024 59,132.1035−$55,857.30
short2 Sep 2024 59,132.102 Sep 2024 59,132.100$0.00
short8 Sep 2024 54,869.9021 Oct 2024 67,377.5043−$104,753.00
long21 Oct 2024 67,377.5021 Oct 2024 67,377.500$0.00
long25 Nov 2024 93,010.0027 Nov 2024 96,334.602$14,554.00
short8 Dec 2024 101,110.009 Dec 2024 97,373.001$15,316.20
long26 Dec 2024 95,791.606 Jan 2025 99,908.6011$18,141.30
long7 Jan 2025 96,954.6015 Jan 2025 100,681.008$16,570.60
long19 Jan 2025 101,332.0020 Jan 2025 105,240.001$16,949.60
long26 Jan 2025 102,620.009 Apr 2025 82,615.2073−$87,320.30
short9 Apr 2025 82,615.209 Apr 2025 82,615.200$0.00
long15 Apr 2025 83,644.0021 Apr 2025 87,545.006$18,854.80
long27 Apr 2025 93,749.301 May 2025 96,975.604$14,237.10
short6 May 2025 96,834.0012 May 2025 102,791.006−$25,889.10
long12 May 2025 102,791.0012 May 2025 102,791.000$0.00
long20 Jun 2025 103,298.0024 Jun 2025 106,205.004$11,478.70
long30 Jun 2025 107,147.002 Jul 2025 108,850.002$6,574.42
short2 Jul 2025 108,850.0020 Jul 2025 117,265.0018−$32,232.00
long20 Jul 2025 117,265.0020 Jul 2025 117,265.000$0.00
short22 Jul 2025 119,954.0025 Jul 2025 117,016.003$9,818.29
long31 Jul 2025 115,764.003 Aug 2025 114,209.003−$5,450.47
short3 Aug 2025 114,209.005 Aug 2025 112,957.002$4,417.85
long14 Aug 2025 118,295.0022 Aug 2025 116,936.008−$4,655.12
short22 Aug 2025 116,936.0023 Aug 2025 115,267.001$5,748.31
short24 Sep 2025 113,307.0025 Sep 2025 110,919.001$8,549.66
short19 Oct 2025 108,643.004 Nov 2025 104,836.0016$14,364.90
short9 Nov 2025 104,723.0011 Nov 2025 103,059.002$6,628.71
long11 Nov 2025 103,059.007 Dec 2025 90,395.3026−$51,669.70
short7 Dec 2025 90,395.307 Dec 2025 90,395.300$0.00
short9 Dec 2025 92,678.8014 Dec 2025 88,862.805$16,250.10
short21 Dec 2025 88,658.9029 Dec 2025 87,237.108$6,459.07
long29 Dec 2025 87,237.105 Jan 2026 92,184.107$23,024.00
short11 Jan 2026 91,013.6020 Jan 2026 88,478.009$11,632.30
short5 Apr 2026 69,034.2026 May 2026 75,930.0051−$42,287.90
long26 May 2026 75,930.0026 May 2026 75,930.000$0.00
short6 Jul 2026 64,042.008 Jul 2026 61,794.402$14,115.60
long13 Jul 2026 62,334.5014 Jul 2026 64,390.901$13,501.00
short20 Jul 2026 65,255.5027 Jul 2026 63,755.907$9,560.38
long27 Jul 2026 63,755.9019 Aug 2026 67,180.5023$22,602.80
long28 Aug 2026 77,845.903 Sep 2026 80,102.506$12,525.40
short6 Sep 2026 80,341.808 Sep 2026 78,109.702$12,178.80
short14 Sep 2026 78,189.2015 Sep 2026 76,025.101$12,301.20
long23 Sep 2026 84,397.602 Oct 2026 86,827.809$12,974.50
long12 Oct 2026 81,850.0013 Oct 2026 83,986.101$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.

ScriptSharesTypeNetTradesMax drawdown
Outside Day this page—v5 strategy−7.4%5225.1%
SOJA PIVOT by ParaBellum68atrv4 strategy+3.3%918.2%
Volatility System by EduardoMattjeatrv5 strategy+150.2%221.5%
ATR Stop Buy Strategy by phobo3satrv4 strategyNo trades on this market
VBand Strategy by Saravanan_Ragavanatrv4 strategyNo trades on this market
Volatility Breakout Strategy [Angel Algo] by AngelAlgoatrv5 strategy+3.1%183.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

Verified

Nothing 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 26 msYes 1,000 bars in 44 msNot measured
PineTSNot testedNot testedNot 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)