Pine Script v4 · Strategy
Date Range Demonstration
A Pine Script v4 strategy built on Crossover or SMA (close, 14, close, 28). It has 1 order rule, 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. 4 settings; defaults include Date range: Custom.
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 Date Range Demonstration repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Date Range Demonstration 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; it opened a long position that was still open on the last bar, 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 Date Range Demonstration 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 Date Range Demonstration use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Date Range Demonstration run in Zeal Terminal?
- Yes
- It compiles in 5 ms and runs 1,000 bars in 26 ms, in the browser.
BTCUSDT · 1D · default settings
- 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
- 18.82%
- −$18,820.60
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long 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
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
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 crossover → ta.crossover, sma → ta.sma.
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 15: input(type = input.bool) → input.bool()
- Line 17: input(type = input.time) → input.time()
- Line 19: input(type = input.time) → input.time()
- Line 30: crossover → ta.crossover
- Line 30: sma → ta.sma
- Line 30: sma → ta.sma
⋯// © LasciviousMonk-//@version=4+//@version=5//⋯//////////////////////////////-useDateRange = input(defval=true, title="Limit backtesting by date", type=input.bool, group="Limit by date")+useDateRange = input.bool(defval=true, title="Limit backtesting by date", group="Limit by date")rangeType = input(defval="Custom", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date", tooltip="If set to other than custom, this overrides any set dates.")-startDate = input(title="Start Date (YYYY/DD/MM)", type=input.time,+startDate = input.time(title="Start Date (YYYY/DD/MM)", defval=timestamp("1 Jan 2021 1:01 -0400"), group="Limit by date")-endDate = input(title="End Date (YYYY/DD/MM) ", type=input.time,+endDate = input.time(title="End Date (YYYY/DD/MM) ", defval=timestamp("31 Dec 2100 19:59 -0400"), group="Limit by date", tooltip="You likely want to leave this far in the future.")⋯//////////////////////////////-longCondition = crossover(sma(close, 14), sma(close, 28))+longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))if inDateRange and longCondition⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 16: input() → input.string()
⋯useDateRange = input.bool(defval=true, title="Limit backtesting by date", group="Limit by date")-rangeType = input(defval="Custom", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date", tooltip="If set to other than custom, this overrides any set dates.")+rangeType = input.string(defval="Custom", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date", tooltip="If set to other than custom, this overrides any set dates.")startDate = input.time(title="Start Date (YYYY/DD/MM)",⋯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.
⋯// © LasciviousMonk-//@version=5+//@version=6//⋯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 |
|---|---|---|---|
| Limit by date | |||
| Limit backtesting by date | true | bool | inDateRange |
| Date range:If set to other than custom, this overrides any set dates. | Custom | string · options ["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"] | startDate |
| Start Date (YYYY/DD/MM) | timestamp("1 Jan 2021 1:01 -0400") | time | inDateRange |
| End Date (YYYY/DD/MM) You likely want to leave this far in the future. | timestamp("31 Dec 2100 19:59 -0400") | time | inDateRange |
What it calculates
- Crossover / SMA (
crossover,ta.crossoverin v5)sma(close, 14), sma(close, 28)longCondition · line 30
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 My Long Entry Id long | inDateRange and longCondition | On | 32 |
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% | — | 18.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 19.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.1% | 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.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.1% | 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 |
|---|---|---|---|---|---|
| Date Range Demonstration this page | — | v4 strategy | 0.0% | 0 | 18.8% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 5 ms | Yes 1,000 bars in 26 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © LasciviousMonk//@version=4//// This is a simple strategy to demonstrate a quick and easy way to impose a date range on a strategy for// for backtesting purposes.// To use:// 1. Copy the code between the '////' lines into your strategy// 2. Add the variable 'inDateRange' to your entry conditions.//strategy("Date Range Demonstration", overlay=true)//////////////////////////////// Limit backtesting dates ////////////////////////////////useDateRange = input(defval=true, title="Limit backtesting by date", type=input.bool, group="Limit by date")rangeType = input(defval="Custom", title="Date range:", options=["Custom", "30 Days", "90 Days", "180 Days", "Year to Date"], group="Limit by date", tooltip="If set to other than custom, this overrides any set dates.")startDate = input(title="Start Date (YYYY/DD/MM)", type=input.time, defval=timestamp("1 Jan 2021 1:01 -0400"), group="Limit by date")endDate = input(title="End Date (YYYY/DD/MM) ", type=input.time, defval=timestamp("31 Dec 2100 19:59 -0400"), group="Limit by date", tooltip="You likely want to leave this far in the future.")// subtract number of days (in milliseconds) from current timestartDate := rangeType == "Custom" ? startDate : rangeType == "30 Days" ? timenow - 2592000000 : rangeType == "90 Days" ? timenow - 7776000000 : rangeType == "180 Days" ? timenow - 15552000000 : rangeType == "Year to Date" ? timestamp(syminfo.timezone, year(timenow), 01, 01, 00, 01) : nainDateRange = (time >= startDate) and (time < endDate)inDateRange := useDateRange ? inDateRange : 1//////////////////////////////longCondition = crossover(sma(close, 14), sma(close, 28))if inDateRange and longCondition strategy.entry("My Long Entry Id", strategy.long)