Pine Script v5 · Strategy
Trading Day and Time Session
A Pine Script v5 strategy built on VWMA (hl2, maLength), Rising (wma, 5) and Falling (wma, 5). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 15 settings; defaults include From 1, From Month 1 and From Year 2010.
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 Trading Day and Time Session repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Trading Day and Time Session 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.
- Does Trading Day and Time Session 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.
- Does Trading Day and Time Session use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Trading Day and Time Session run in Zeal Terminal?
- Yes
- It compiles in 21 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- 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, $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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
5 settings have no label
In the settings dialog fromMonth (line 7), fromYear (line 8), toMonth (line 10), toYear (line 11), i_sess (line 15) 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.
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 |
|---|---|---|---|
| Trade Session | |||
| From | 1 | int · min 1 · max 31 | startDate |
| From Month (no label in the script) | 1 | int · min 1 · max 12 | startDate |
| From Year (no label in the script) | 2010 | int · min 1970 | startDate |
| To | 31 | int · min 1 · max 31 | finishDate |
| To Month (no label in the script) | 12 | int · min 1 · max 12 | finishDate |
| To Year (no label in the script) | 2099 | int · min 1970 | finishDate |
| I sess (no label in the script) | 0400-1900 | session | time_cond |
| UTC Offset | 3 | int · min -10 · max 13 | UTC_string |
| Trade Monday? | true | bool | line 27 |
| Trade Tuesday? | true | bool | line 29 |
| Trade Wednesday? | true | bool | line 31 |
| Trade Thursday? | true | bool | line 33 |
| Trade Friday? | true | bool | line 35 |
| Trade Saturday? | false | bool | line 37 |
| Trade Sunday? | false | bool | line 39 |
What it calculates
- VWMAhl2, maLength
wma · line 45 - Risingwma, 5
uptrend · line 46 - Fallingwma, 5
downtrend · line 47
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 Buy long | uptrend | On | 51 |
| Close Buy | uptrend | On | 53 |
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 |
|---|---|---|---|---|---|
| Trading Day and Time Session this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Quarterly Returns in Strategies vs Buy & Hold by Dannnnnnny | vwma rising falling | v4 strategy | +80.2% | 4 | 10.7% |
| Swing Trading SPX Correlation by exlux99 | vwma rising | v5 strategy | No trades on this market | ||
| PMA Strategy Idea by QuantCT | rising falling | v4 strategy | +51.7% | 129 | 30.8% |
| Trendelicious Strategy by levieux | rising falling | v5 strategy | −12.8% | 9 | 41.4% |
| Linear On MACD by stocktechbot | rising falling vwma | v5 strategy | +1.5% | 16 | 5.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.
- 7 settings use the untyped input() (line 19, 20, 21, 22, 23, 24, 25). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 19: input() → input.bool()
- Line 20: input() → input.bool()
- Line 21: input() → input.bool()
- Line 22: input() → input.bool()
- Line 23: input() → input.bool()
- Line 24: input() → input.bool()
- Line 25: input() → input.bool()
⋯time_cond = time(timeframe.period, i_sess, UTC_string)-is_trade_mon = input(true, title="Trade Monday?", group='Trade Session')+is_trade_mon = input.bool(true, title="Trade Monday?", group='Trade Session')-is_trade_tue = input(true, title="Trade Tuesday?", group='Trade Session')+is_trade_tue = input.bool(true, title="Trade Tuesday?", group='Trade Session')-is_trade_wed = input(true, title="Trade Wednesday?", group='Trade Session')+is_trade_wed = input.bool(true, title="Trade Wednesday?", group='Trade Session')-is_trade_thu = input(true, title="Trade Thursday?", group='Trade Session')+is_trade_thu = input.bool(true, title="Trade Thursday?", group='Trade Session')-is_trade_fri = input(true, title="Trade Friday?", group='Trade Session')+is_trade_fri = input.bool(true, title="Trade Friday?", group='Trade Session')-is_trade_sat = input(false, title="Trade Saturday?", group='Trade Session')+is_trade_sat = input.bool(false, title="Trade Saturday?", group='Trade Session')-is_trade_sun = input(false, title="Trade Sunday?", group='Trade Session')+is_trade_sun = input.bool(false, title="Trade Sunday?", group='Trade Session')day_cond = false⋯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.
⋯// © Dannnnnnny-//@version=5+//@version=6strategy(title="Trade Day-Time Session", overlay = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 21 ms | With a workaround 1,000 bars in 46 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/// © Dannnnnnny//@version=5strategy(title="Trade Day-Time Session", overlay = true)//Session=====================================================================fromDay = input.int(defval = 1, title = "From", minval = 1, maxval = 31, inline="1", group='Trade Session')fromMonth = input.int(defval = 1, title = "", minval = 1, maxval = 12,inline="1", group='Trade Session')fromYear = input.int(defval = 2010, title = "", minval = 1970, inline="1", group='Trade Session')toDay = input.int(defval = 31, title = "To", minval = 1, maxval = 31, inline="2", group='Trade Session')toMonth = input.int(defval = 12, title = "", minval = 1, maxval = 12, inline="2",group='Trade Session')toYear = input.int(defval = 2099, title = "", minval = 1970, inline="2",group='Trade Session')startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)date_cond = time >= startDate and time <= finishDatei_sess = input.session("0400-1900", "Trade time", group='Trade Session')UTC_offset = input.int(3, title='UTC Offset', minval=-10, maxval=13, group='Trade Session')UTC_string = 'UTC' + (UTC_offset > 0 ? '+' : '') + (UTC_offset != 0 ? str.tostring(UTC_offset) : '')time_cond = time(timeframe.period, i_sess, UTC_string)is_trade_mon = input(true, title="Trade Monday?", group='Trade Session')is_trade_tue = input(true, title="Trade Tuesday?", group='Trade Session')is_trade_wed = input(true, title="Trade Wednesday?", group='Trade Session')is_trade_thu = input(true, title="Trade Thursday?", group='Trade Session')is_trade_fri = input(true, title="Trade Friday?", group='Trade Session')is_trade_sat = input(false, title="Trade Saturday?", group='Trade Session')is_trade_sun = input(false, title="Trade Sunday?", group='Trade Session')day_cond = falseif(dayofweek(time_cond, UTC_string) == dayofweek.monday and is_trade_mon) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.tuesday and is_trade_tue) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.wednesday and is_trade_wed) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.thursday and is_trade_thu) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.friday and is_trade_fri) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.saturday and is_trade_sat) day_cond := trueelse if(dayofweek(time_cond, UTC_string) == dayofweek.sunday and is_trade_sun) day_cond := truebgcolor(time == time_cond and day_cond ? color.new(color.gray,90) : na)final_time_cond = time == time_cond and day_cond and date_cond//=====================================================================maLength= 400wma= ta.vwma(hl2,maLength)uptrend= ta.rising(wma, 5)downtrend= ta.falling(wma,5)plot(wma)if(final_time_cond) if uptrend strategy.entry("Buy", strategy.long) else strategy.close("Buy")