Pine Script v5 · Strategy
Wyckoff Range Strategy
A Pine Script v5 strategy built on Crossover or SMA (close) and Crossunder or SMA (close). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays no commission. 5 settings; defaults include Accumulation 32, Distribution 35 and Spring 10.
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 Wyckoff Range Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Wyckoff Range Strategy do on BTCUSDT 1D with default settings?
- +6.17%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Wyckoff Range Strategy have?
- 2
- Enter Long Position; Enter Short Position.
- Does Wyckoff Range Strategy run in Pine Script v6?
- Yes
- Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Wyckoff Range Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 33, 34.
BTCUSDT · 1D · default settings
- Accumulation Phase
- Distribution Phase
- Spring
- Upthrust
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +6.17%
- $61.73
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 4 won · 2 lost
- Profitable
- 66.7%
- of closed trades
- Profit factor
- 8.43
- gross profit ÷ gross loss
- Max drawdown
- 2.31%
- −$23.06
One run with the author's default settings, $1,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 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.
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 |
|---|---|---|---|
| Accumulation | 32 | int | isAccumulation |
| Distribution | 35 | int | isDistribution |
| Spring | 10 | int | isSpring |
| Upthrust | 20 | int | isUpthrust |
| Stop Percentage | 10 | int | stopLossLevelLong stopLossLevelShort |
What it calculates
- Crossover / SMAclose, ta.sma(close, AccumulationLength)
isAccumulation · line 12 - Crossunder / SMAclose, ta.sma(close, DistributionLength)
isDistribution · line 14 - Crossover / SMAlow, ta.sma(low, SpringLength)
isSpring · line 16 - Crossunder / SMAhigh, ta.sma(high, UpthrustLength)
isUpthrust · line 17
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 |
|---|---|---|---|
| Close Short | (enterLong) | On | 23 |
| Open Long long | (enterLong) | On | 24 |
| Close Long | (enterShort) | On | 27 |
| Open Short short | (enterShort) | On | 28 |
| Exit Stop Loss Long stop | every bar | On | 33 |
| Exit Stop Loss Short stop | every bar | On | 34 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | Enter Long Position | 25 |
| (no title) | alert | Enter Short Position | 29 |
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 | +6.2% | +102.5% | 6 | 67% | 8.43 | 2.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.3% | +5.5% | 8 | 50% | 1.07 | 3.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +12.8% | +9.8% | 8 | 63% | 6.68 | 2.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.1% | +8.4% | 9 | 33% | 0.16 | 7.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.5% | +16.7% | 7 | 57% | 1.33 | 2.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.7% | +21.5% | 13 | 31% | 1.52 | 3.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −11.0% | +148.3% | 6 | 33% | 0.23 | 14.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.6% | +17.1% | 8 | 38% | 1.48 | 1.2% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Accumulation 19, Distribution 21) made +10.5% before 26 Dec 2025 and −2.7% after it, worse than the defaults' +3.0% after. Tuning on the past did not carry forward. 70% of the 64 combinations made money in-sample and 70% out-of-sample.
| Distribution ↓ · Accumulation → | 16 | 19 | 22 | 27 | 32 | 38 | 45 | 54 |
|---|---|---|---|---|---|---|---|---|
| 18 | +6% | +7% | +5% | −0% | +3% | +0% | +1% | +0% |
| 21 | +10% | +10% | +10% | −1% | +6% | −1% | +1% | −2% |
| 25 | +8% | +9% | +8% | +0% | +3% | −0% | +2% | +0% |
| 30 | +9% | +9% | +9% | +1% | +3% | +0% | +1% | +2% |
| 35 | +8% | +9% | +8% | +1% | +3% | +0% | +1% | +2% |
| 42 | +7% | +6% | +6% | −1% | +1% | −2% | −1% | −0% |
| 49 | +6% | +5% | +5% | −2% | −0% | −3% | −2% | −1% |
| 60 | +5% | +4% | +4% | −2% | −0% | −3% | −2% | −3% |
| Distribution ↓ · Accumulation → | 16 | 19 | 22 | 27 | 32 | 38 | 45 | 54 |
|---|---|---|---|---|---|---|---|---|
| 18 | +1% | −3% | −3% | −2% | +3% | −1% | 0% | +3% |
| 21 | −1% | −3% | −3% | −2% | +1% | −1% | 0% | +0% |
| 25 | +4% | −0% | −0% | −0% | +6% | +2% | +2% | +5% |
| 30 | +4% | −0% | −0% | −0% | +6% | +2% | +2% | +5% |
| 35 | +3% | +0% | +0% | +0% | +3% | +2% | +2% | +3% |
| 42 | −0% | +0% | +0% | +0% | −0% | +2% | +2% | +3% |
| 49 | +3% | +0% | +0% | +0% | +3% | +2% | +2% | +3% |
| 60 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 2 | 0% | −$8.31 |
| Sideways market | 2 | 100% | $40.37 |
| Falling market | 2 | 100% | $29.66 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.8%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.5% to 0.8%; the tick is what actually happened, 0.8%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 3 Apr 2024 65,464.00 | 7 Apr 2024 68,896.00 | 4 | −$5.24 |
| long | 7 Apr 2024 68,896.00 | 14 Jun 2024 66,773.00 | 68 | −$3.07 |
| short | 14 Jun 2024 66,773.00 | 8 Aug 2024 60,647.60 | 55 | $9.10 |
| long | 12 Apr 2025 83,423.80 | 10 Oct 2025 109,496.00 | 181 | $31.28 |
| short | 21 Jan 2026 88,427.70 | 6 Feb 2026 69,200.90 | 16 | $22.44 |
| short | 27 Mar 2026 68,820.30 | 5 Aug 2026 64,106.60 | 131 | $7.22 |
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 |
|---|---|---|---|---|---|
| Wyckoff Range Strategy this page | — | v5 strategy | +6.2% | 6 | 2.3% |
| 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.
- 5 settings use the untyped input() (line 6, 7, 8, 9, 10). 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.
Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
⋯// Input Variables-AccumulationLength = input(32, "Accumulation")+AccumulationLength = input.int(32, "Accumulation")-DistributionLength = input(35, "Distribution")+DistributionLength = input.int(35, "Distribution")-SpringLength = input(10, "Spring")+SpringLength = input.int(10, "Spring")-UpthrustLength = input(20, "Upthrust")+UpthrustLength = input.int(20, "Upthrust")-stopPercentage = input(10, "Stop Percentage")+stopPercentage = input.int(10, "Stop Percentage")// Accumulation Phase⋯Does it run in Pine Script v6?
Yes
Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © deperp-//@version=5+//@version=6strategy("Wyckoff Range Strategy by deperp", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 21 ms | Yes 1,000 bars in 39 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/// © deperp//@version=5strategy("Wyckoff Range Strategy by deperp", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent)// Input VariablesAccumulationLength = input(32, "Accumulation")DistributionLength = input(35, "Distribution")SpringLength = input(10, "Spring")UpthrustLength = input(20, "Upthrust")stopPercentage = input(10, "Stop Percentage")// Accumulation PhaseisAccumulation = ta.crossover(close, ta.sma(close, AccumulationLength))// Distribution PhaseisDistribution = ta.crossunder(close, ta.sma(close, DistributionLength))// Spring and UpthrustisSpring = ta.crossover(low, ta.sma(low, SpringLength))isUpthrust = ta.crossunder(high, ta.sma(high, UpthrustLength))// Strategy ConditionsenterLong = isAccumulation and isSpringenterShort = isDistribution and isUpthrust// Entry and Exit Conditionsif (enterLong) strategy.close("Short") strategy.entry("Long", strategy.long, comment="Enter Long") alert("Enter Long Position")if (enterShort) strategy.close("Long") strategy.entry("Short", strategy.short, comment="Enter Short") alert("Enter Short Position")// Stop LossstopLossLevelLong = close * (1 - stopPercentage / 100)stopLossLevelShort = close * (1 + stopPercentage / 100)strategy.exit("Stop Loss Long", "Long", stop=stopLossLevelLong)strategy.exit("Stop Loss Short", "Short", stop=stopLossLevelShort)// Plotting Wyckoff Schematicsplotshape(isAccumulation, title="Accumulation Phase", location=location.belowbar, color=color.green, style=shape.labelup, text="Accumulation")plotshape(isDistribution, title="Distribution Phase", location=location.abovebar, color=color.red, style=shape.labeldown, text="Distribution")plotshape(isSpring, title="Spring", location=location.belowbar, color=color.blue, style=shape.triangleup)plotshape(isUpthrust, title="Upthrust", location=location.abovebar, color=color.orange, style=shape.triangledown)