Pine Script v5 · Strategy
DaveStrat
A Pine Script v5 strategy built on Change or SMA. It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. It has no settings.
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 DaveStrat repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
- How did DaveStrat do on BTCUSDT 1D with default settings?
- +24.73%
- From 26 Jan 2024 to 21 Oct 2026, over 36 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does DaveStrat run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 36 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does DaveStrat use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does DaveStrat run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- 50madeltasmooth
- 100madeltasmooth
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +24.73%
- $247,334.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 36
- 12 won · 24 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 1.19
- gross profit ÷ gross loss
- Max drawdown
- 48.52%
- −$575,395.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
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.
-
Note
Uses an argument v6 removed
when = on line 8, 10. 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.
The script declares no settings.
What it calculates
- Change / SMAta.sma(ta.sma(close,25),3)
goindicator · line 6 - Change / SMAta.sma(ta.sma(close,100),3)
dropindicator · line 7
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 | ((goindicator)-dropindicator) > 0.0 | On | 8 |
| Open sell short | dropindicator-goindicator > 0 | On | 10 |
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 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 | +24.7% | +102.5% | 36 | 33% | 1.19 | 48.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.8% | +5.5% | 38 | 26% | 1.05 | 9.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +4.3% | +9.8% | 28 | 39% | 1.96 | 2.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.3% | +8.4% | 42 | 29% | 0.79 | 0.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.2% | +16.7% | 40 | 40% | 1.62 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 48 | 35% | 1.64 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.5% | +148.3% | 42 | 50% | 1.48 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 50 | 24% | 0.58 | 0.2% | 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 | 14 | 7% | −$540,284.00 |
| Sideways market | 18 | 44% | $626,217.00 |
| Falling market | 4 | 75% | $161,401.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
55.0%
The 95th percentile of the worst drawdown when the same 36 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 28.5% to 55.0%; the tick is what actually happened, 41.2%. Order luck alone moves it this much.
All 36 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 8 May 2024 62,312.10 | 23 May 2024 69,166.60 | 15 | −$68,545.50 |
| long | 23 May 2024 69,166.60 | 15 Jun 2024 66,044.00 | 23 | −$31,226.30 |
| short | 15 Jun 2024 66,044.00 | 17 Jul 2024 65,044.00 | 32 | $9,999.90 |
| long | 17 Jul 2024 65,044.00 | 8 Aug 2024 55,133.80 | 22 | −$99,102.40 |
| short | 8 Aug 2024 55,133.80 | 30 Aug 2024 59,359.00 | 22 | −$42,252.40 |
| long | 30 Aug 2024 59,359.00 | 5 Sep 2024 57,970.90 | 6 | −$13,881.00 |
| short | 5 Sep 2024 57,970.90 | 11 Sep 2024 57,636.00 | 6 | $3,349.10 |
| long | 11 Sep 2024 57,636.00 | 21 Dec 2024 97,805.40 | 101 | $401,695.00 |
| short | 21 Dec 2024 97,805.40 | 24 Jan 2025 103,910.00 | 34 | −$61,049.10 |
| long | 24 Jan 2025 103,910.00 | 3 Feb 2025 97,700.60 | 10 | −$62,097.60 |
| short | 3 Feb 2025 97,700.60 | 24 Mar 2025 86,082.50 | 49 | $116,181.00 |
| long | 24 Mar 2025 86,082.50 | 30 Mar 2025 82,648.50 | 6 | −$34,339.70 |
| short | 30 Mar 2025 82,648.50 | 4 Apr 2025 83,213.10 | 5 | −$5,645.60 |
| long | 4 Apr 2025 83,213.10 | 9 Apr 2025 76,322.40 | 5 | −$68,906.70 |
| short | 9 Apr 2025 76,322.40 | 12 Apr 2025 83,423.80 | 3 | −$71,014.10 |
| long | 12 Apr 2025 83,423.80 | 5 Jun 2025 104,697.00 | 54 | $212,730.00 |
| short | 5 Jun 2025 104,697.00 | 11 Jun 2025 110,274.00 | 6 | −$55,775.30 |
| long | 11 Jun 2025 110,274.00 | 14 Jun 2025 106,067.00 | 3 | −$42,078.00 |
| short | 14 Jun 2025 106,067.00 | 12 Jul 2025 117,528.00 | 28 | −$114,611.00 |
| long | 12 Jul 2025 117,528.00 | 4 Aug 2025 114,209.00 | 23 | −$33,188.50 |
| short | 4 Aug 2025 114,209.00 | 20 Sep 2025 115,632.00 | 47 | −$14,235.80 |
| long | 20 Sep 2025 115,632.00 | 28 Sep 2025 109,636.00 | 8 | −$59,965.40 |
| short | 28 Sep 2025 109,636.00 | 2 Oct 2025 118,595.00 | 4 | −$89,591.40 |
| long | 2 Oct 2025 118,595.00 | 12 Oct 2025 110,644.00 | 10 | −$79,505.90 |
| short | 12 Oct 2025 110,644.00 | 22 Oct 2025 108,298.00 | 10 | $23,467.40 |
| long | 22 Oct 2025 108,298.00 | 25 Oct 2025 111,005.00 | 3 | $27,072.40 |
| short | 25 Oct 2025 111,005.00 | 12 Dec 2025 92,513.40 | 48 | $184,915.00 |
| long | 12 Dec 2025 92,513.40 | 31 Jan 2026 84,260.50 | 50 | −$82,528.80 |
| short | 31 Jan 2026 84,260.50 | 3 Mar 2026 68,830.10 | 31 | $154,304.00 |
| long | 3 Mar 2026 68,830.10 | 18 May 2026 77,457.70 | 76 | $86,276.10 |
| short | 18 May 2026 77,457.70 | 2 Jul 2026 60,024.00 | 45 | $174,337.00 |
| long | 2 Jul 2026 60,024.00 | 16 Sep 2026 75,644.50 | 76 | $156,205.00 |
| short | 16 Sep 2026 75,644.50 | 23 Sep 2026 86,208.60 | 7 | −$105,641.00 |
| long | 23 Sep 2026 86,208.60 | 10 Oct 2026 82,635.60 | 17 | −$35,730.10 |
| short | 10 Oct 2026 82,635.60 | 12 Oct 2026 83,773.10 | 2 | −$11,375.60 |
| long | 12 Oct 2026 83,773.10 | 15 Oct 2026 81,682.00 | 3 | −$20,911.00 |
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 |
|---|---|---|---|---|---|
| DaveStrat this page | — | v5 strategy | +24.7% | 36 | 48.5% |
| 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% |
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 8, 10). 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 36 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: when = ((goindicator)-dropindicator) > 0.0 → if block
- Line 10: when = dropindicator-goindicator > 0 → if block
⋯ dropindicator = ta.change(ta.sma(ta.sma(close,100),3))- strategy.entry("buy", strategy.long, 10, when=((goindicator)-dropindicator) > 0.0)+ if ((goindicator)-dropindicator) > 0.0+ strategy.entry("buy", strategy.long, 10) if ta.sma(close,3)-ta.sma(close,25)<0- strategy.entry("sell", strategy.short, 10, when=dropindicator-goindicator > 0)+ if dropindicator-goindicator > 0+ strategy.entry("sell", strategy.short, 10)plot(ta.change(ta.sma(ta.sma(close,25),3)),"50madeltasmooth", color.green)⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 36 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © David Frausto Pena-//@version=5+//@version=6strategy("DaveStrat")⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | Yes 1,000 bars in 43 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/// © David Frausto Pena//@version=5strategy("DaveStrat")if bar_index < 10000 goindicator = ta.change(ta.sma(ta.sma(close,25),3)) dropindicator = ta.change(ta.sma(ta.sma(close,100),3)) strategy.entry("buy", strategy.long, 10, when=((goindicator)-dropindicator) > 0.0) if ta.sma(close,3)-ta.sma(close,25)<0 strategy.entry("sell", strategy.short, 10, when=dropindicator-goindicator > 0)plot(ta.change(ta.sma(ta.sma(close,25),3)),"50madeltasmooth", color.green)plot(ta.change(ta.sma(ta.sma(close,100),3)),"100madeltasmooth", color.red)