Pine Script v5 · Strategy
Overnight Gap Analysis
A Pine Script v5 strategy built on Change (time_tradingday) and Crossover (strategy.position_size, 0.5). It has 3 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 1 commission. 5 settings; defaults include Number of Bars on Your Chart Per Day 7 and EMA Qual Length 1400.
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 Overnight Gap Analysis repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Overnight Gap Analysis 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. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does Overnight Gap Analysis run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L13:C17: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
- Does Overnight Gap Analysis use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Overnight Gap Analysis run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 24 ms, in the browser.
BTCUSDT · 1D · default settings
- Change
- Crossover
- 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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 21, 23, 25. 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 |
|---|---|---|---|
| Script Date Range Settings | |||
| Start Time | timestamp('01 Jan 2010 05:00 +0000') | time | InDateRange |
| End Time | timestamp('01 Jan 2099 00:00 +0000') | time | InDateRange |
| Number of Bars on Your Chart Per DayThis is used to identify the last bar of the day. A Long order is placed on the close of this bar | 7 | int | entry Long |
| Only Enter Trade if Above EMA? | false | bool | entry Long entry Long line 20 line 22 |
| EMA Qual Length | 1400 | int | entry Long |
What it calculates
- Changetime_tradingday
todaybarcount · line 13 - Crossoverstrategy.position_size, 0.5
EnteredLastBar · line 18
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 | LongTrigger and EMAFilter | On | 21 |
| Open Long long | LongTrigger | On | 23 |
| Close Long | EnteredLastBar==1 | On | 25 |
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 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.5% | +5.5% | 1 | 100% | — | 0.1% | 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.6% | +8.4% | 1 | 100% | — | 0.1% | 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.5% | +21.5% | 1 | 100% | — | 0.3% | 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.5% | +17.1% | 1 | 100% | — | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
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.
- 3 strategy calls use the when = argument (line 21, 23, 25). 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.
Same 1 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 21: when = LongTrigger and EMAFilter → if block
- Line 23: when = LongTrigger → if block
- Line 25: when = EnteredLastBar==1 → if block
⋯if (InDateRange and EMAFilterInput==true)- strategy.entry("Long", strategy.long, when = LongTrigger and EMAFilter, alert_message="Buy")+ if LongTrigger and EMAFilter+ strategy.entry("Long", strategy.long, alert_message="Buy")if (InDateRange and EMAFilterInput==false)- strategy.entry("Long", strategy.long, when = LongTrigger, alert_message="Buy")+ if LongTrigger+ strategy.entry("Long", strategy.long, alert_message="Buy")if (InDateRange)- strategy.close("Long", when = EnteredLastBar==1)+ if EnteredLastBar==1+ strategy.close("Long")Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L13:C17: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version = 5+// @version = 6// Author = TradeAutomation⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 24 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/// @version = 5// Author = TradeAutomationstrategy(title="Overnight Gap Analysis", shorttitle="Overnight Gap Analysis", process_orders_on_close=true, calc_on_every_tick=false, overlay=true, commission_type=strategy.commission.cash_per_order, commission_value=1, slippage=0, initial_capital = 100000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Default settings are for a 1 hour chart in a market that has 7 bars per day. The number of bars on the chart per day must be adjusted with an input for the script to work on other types of charts/markets. // Script Date Range Inputs StartTime = input.time(defval=timestamp('01 Jan 2010 05:00 +0000'), group="Script Date Range Settings", title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), group="Script Date Range Settings", title='End Time')InDateRange = time>=StartTime and time<=EndTime// Identifies the Last Bar of the Dayvar todaybarcount = 0todaybarcount := close and not ta.change(time_tradingday) ? todaybarcount + 1 : ta.change(time_tradingday) ? 1 : todaybarcount[1]// Calculates Trigger and Filter CriteriaLongTrigger = todaybarcount==input.int(7, "Number of Bars on Your Chart Per Day", tooltip="This is used to identify the last bar of the day. A Long order is placed on the close of this bar")EMAFilterInput = input.bool(false, "Only Enter Trade if Above EMA?")EMAFilter = close>ta.ema(close, input.int(1400, "EMA Qual Length")) EnteredLastBar = ta.crossover(strategy.position_size, 0.5) ? 1 : 0// Entry and Exit Functionsif (InDateRange and EMAFilterInput==true) strategy.entry("Long", strategy.long, when = LongTrigger and EMAFilter, alert_message="Buy")if (InDateRange and EMAFilterInput==false) strategy.entry("Long", strategy.long, when = LongTrigger, alert_message="Buy")if (InDateRange) strategy.close("Long", when = EnteredLastBar==1)