Pine Script v5 · Strategy
TradeIQ Darvas Box Backtest
A Pine Script v5 strategy built on Lowest (low, 5), Highest (high, 5) and WMA (close, 3). 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 100% of equity and pays no commission. 7 settings; defaults include Box Length 5, First Moving Average length 3 and Second Moving Average length 5.
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 TradeIQ Darvas Box Backtest repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did TradeIQ Darvas Box Backtest 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 TradeIQ Darvas Box Backtest 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 TradeIQ Darvas Box Backtest use a stop loss?
- Yes
- strategy.exit sets a stop on line 54, 64.
- Does TradeIQ Darvas Box Backtest run in Zeal Terminal?
- Yes
- It compiles in 29 ms and runs 1,000 bars in 61 ms, in the browser.
BTCUSDT · 1D · default settings
- TBbox
- BBbox
- MAVW
- 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 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
1 setting does nothing
“Offset” is declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
2 settings have no label
In the settings dialog fromDate (line 9), toDate (line 10) 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.
-
Note
Uses an argument v6 removed
when = on line 52, 58, 62, 68. 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 |
|---|---|---|---|
| Backtest Range | |||
| From Date (no label in the script) | timestamp("7 Mar 2022 00:00 +0000") | time | line 12 |
| To Date (no label in the script) | timestamp("19 Mar 2022 23:59 +0000") | time | line 12 |
| Darvas Box | |||
| Box Length | 5 | int | LL k1 k2 k3 TopBox BottomBox |
| MavilimW | |||
| First Moving Average length | 3 | int | tmal M1 |
| Second Moving Average length | 5 | int | tmal Fmal M2 |
| Relative Vigor Index | |||
| Length | 10 | int · min 1 | rvi |
| Offset | 0 | int · min -500 · max 500 | unused |
What it calculates
- Lowestlow, Box Length (5)
LL · line 15 - Highesthigh, Box Length (5)
k1 · line 16 - Highesthigh, boxp-1
k2 · line 17 - Highesthigh, boxp-2
k3 · line 18 - WMAclose, First Moving Average length (3)
M1 · line 32 - WMAM1, Second Moving Average length (5)
M2 · line 33 - WMAM2, tmal
M3 · line 34 - WMAM3, Fmal
M4 · line 35 - WMAM4, Ftmal
M5 · line 36 - WMAM5, Smal
MAVW · line 37 - SWMAclose-open
rvi · line 44 - SWMArvi
sig · line 45 - Crossoverclose, TopBox
long · line 50 - Crossunderrvi, sig
longClose · line 51 - Crossunderclose, BottomBox
short · line 60 - Crossoverrvi, sig
shortClose · line 61
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 Position long | long and window() and strategy.position_size==0 and strategy.closedtrades<100 | On | 52 |
| Exit exit stop | (longStopSet==false and strategy.position_size > 0) | On | 54 |
| Close Long Position | longClose | On | 58 |
| Open Short Position short | short and window() and strategy.position_size==0 and strategy.closedtrades<100 | On | 62 |
| Exit exit stop | (shortStopSet==false and strategy.position_size < 0) | On | 64 |
| Close Short Position | shortClose | On | 68 |
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 |
|---|---|---|---|---|---|
| TradeIQ Darvas Box Backtest this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
| Donchian Channels System [racer8] by racer8 | highest lowest | v4 strategy | −3.2% | 36 | 43.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.
- 4 strategy calls use the when = argument (line 52, 58, 62, 68). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 3 settings use the untyped input() (line 14, 26, 27). 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 14: input() → input.int()
- Line 26: input() → input.int()
- Line 27: input() → input.int()
- Line 52: when = long and window() and strategy.position_size==0 and strategy.closedtrades<100 → if block
- Line 58: when = longClose → if block
- Line 62: when = short and window() and strategy.position_size==0 and strategy.closedtrades<100 → if block
- Line 68: when = shortClose → if block
⋯var GRP3 = "Darvas Box"-boxp=input(5, "Box Length", group=GRP3)+boxp=input.int(5, "Box Length", group=GRP3)LL = ta.lowest(low,boxp)⋯var GRP4 = "MavilimW"-fmal=input(3,"First Moving Average length", group=GRP4)+fmal=input.int(3,"First Moving Average length", group=GRP4)-smal=input(5,"Second Moving Average length", group=GRP4)+smal=input.int(5,"Second Moving Average length", group=GRP4)tmal=fmal+smal⋯longClose = strategy.opentrades.profit(strategy.opentrades-1)>0 and ta.crossunder(rvi,sig) ? true : false-strategy.entry("Long Position", strategy.long, when = long and window() and strategy.position_size==0 and strategy.closedtrades<100)+if long and window() and strategy.position_size==0 and strategy.closedtrades<100+ strategy.entry("Long Position", strategy.long)if(longStopSet==false and strategy.position_size > 0)⋯ longStopSet := false-strategy.close("Long Position", when = longClose)+if longClose+ strategy.close("Long Position")var shortStopSet = false⋯shortClose = strategy.opentrades.profit(strategy.opentrades-1)>0 and ta.crossover(rvi,sig) ? true : false-strategy.entry("Short Position", strategy.short, when = short and window() and strategy.position_size==0 and strategy.closedtrades<100)+if short and window() and strategy.position_size==0 and strategy.closedtrades<100+ strategy.entry("Short Position", strategy.short)if(shortStopSet==false and strategy.position_size < 0)⋯ shortStopSet := false-strategy.close("Short Position", when = shortClose)+if shortClose+ strategy.close("Short Position")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.
⋯// This strategy script has been made to backtest the strategy explained in the video above-//@version=5+//@version=6strategy(shorttitle = "Darvas Box Test", title="TradeIQ Darvas Box Test", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, currency=currency.USD)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 29 ms | Yes 1,000 bars in 61 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/// © xxy_theone// https://www.youtube.com/watch?v=YYxlnFOX9sQ// This strategy script has been made to backtest the strategy explained in the video above//@version=5strategy(shorttitle = "Darvas Box Test", title="TradeIQ Darvas Box Test", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, currency=currency.USD)// === INPUT BACKTEST RANGE ===var GRP1 = "Backtest Range"fromDate = input.time(timestamp("7 Mar 2022 00:00 +0000"), "From", group=GRP1)toDate = input.time(timestamp("19 Mar 2022 23:59 +0000"), "To", group=GRP1)window() => // create function "within window of time" time >= fromDate and time <= toDate ? true : falsevar GRP3 = "Darvas Box"boxp=input(5, "Box Length", group=GRP3)LL = ta.lowest(low,boxp)k1=ta.highest(high,boxp)k2=ta.highest(high,boxp-1)k3=ta.highest(high,boxp-2)NH = ta.valuewhen(high>k1[1],high,0)box1 =k3<k2TopBox = ta.valuewhen(ta.barssince(high>k1[1])==boxp-2 and box1, NH, 0)BottomBox = ta.valuewhen(ta.barssince(high>k1[1])==boxp-2 and box1, LL, 0)plot(TopBox, linewidth=3, color=color.green, title="TBbox") plot(BottomBox, linewidth=3, color=color.red, title="BBbox")var GRP4 = "MavilimW"fmal=input(3,"First Moving Average length", group=GRP4)smal=input(5,"Second Moving Average length", group=GRP4)tmal=fmal+smalFmal=smal+tmalFtmal=tmal+FmalSmal=Fmal+FtmalM1= ta.wma(close, fmal)M2= ta.wma(M1, smal)M3= ta.wma(M2, tmal)M4= ta.wma(M3, Fmal)M5= ta.wma(M4, Ftmal)MAVW= ta.wma(M5, Smal)col1= MAVW>MAVW[1]col3= MAVW<MAVW[1]colorM = col1 ? color.blue : col3 ? color.red : color.yellowplot(MAVW, color=colorM, linewidth=2, title="MAVW")var GRP5 = "Relative Vigor Index"len = input.int(10, title="Length", minval=1, group=GRP5)rvi = math.sum(ta.swma(close-open), len)/math.sum(ta.swma(high-low),len)sig = ta.swma(rvi)offset = input.int(0, "Offset", minval = -500, maxval = 500, group=GRP5)//plot(rvi, color=#008000, title="RVGI", offset = offset)//plot(sig, color=#FF0000, title="Signal", offset = offset)var longStopSet = falselong = ta.crossover(close,TopBox) and close > MAVW ? true : falselongClose = strategy.opentrades.profit(strategy.opentrades-1)>0 and ta.crossunder(rvi,sig) ? true : falsestrategy.entry("Long Position", strategy.long, when = long and window() and strategy.position_size==0 and strategy.closedtrades<100)if(longStopSet==false and strategy.position_size > 0) strategy.exit("exit", "Long Position", stop=BottomBox) longStopSet := trueif(strategy.position_size==0) longStopSet := falsestrategy.close("Long Position", when = longClose)var shortStopSet = falseshort = ta.crossunder(close,BottomBox) and close < MAVW ? true : falseshortClose = strategy.opentrades.profit(strategy.opentrades-1)>0 and ta.crossover(rvi,sig) ? true : falsestrategy.entry("Short Position", strategy.short, when = short and window() and strategy.position_size==0 and strategy.closedtrades<100)if(shortStopSet==false and strategy.position_size < 0) strategy.exit("exit", "Short Position", stop=TopBox) shortStopSet := trueif(strategy.position_size==0) shortStopSet := falsestrategy.close("Short Position", when = shortClose)