Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100$203Equity from $100
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Backtest Range
From Date (no label in the script)timestamp("7 Mar 2022 00:00 +0000")timeline 12
To Date (no label in the script)timestamp("19 Mar 2022 23:59 +0000")timeline 12
Darvas Box
Box Length5intLL k1 k2 k3 TopBox BottomBox
MavilimW
First Moving Average length3inttmal M1
Second Moving Average length5inttmal Fmal M2
Relative Vigor Index
Length10int · min 1rvi
Offset0int · min -500 · max 500unused

What it calculates

  • Lowestlow, Box Length (5)LL · line 15
  • Highesthigh, Box Length (5)k1 · line 16
  • Highesthigh, boxp-1k2 · line 17
  • Highesthigh, boxp-2k3 · line 18
  • WMAclose, First Moving Average length (3)M1 · line 32
  • WMAM1, Second Moving Average length (5)M2 · line 33
  • WMAM2, tmalM3 · line 34
  • WMAM3, FmalM4 · line 35
  • WMAM4, FtmalM5 · line 36
  • WMAM5, SmalMAVW · line 37
  • SWMAclose-openrvi · line 44
  • SWMArvisig · line 45
  • Crossoverclose, TopBoxlong · line 50
  • Crossunderrvi, siglongClose · line 51
  • Crossunderclose, BottomBoxshort · line 60
  • Crossoverrvi, sigshortClose · 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.

lowlowprice databoxpBox Lengthsetting · 5highhighprice dataclosecloseprice datafmalFirst Moving Average le…setting · 3smalSecond Moving Average l…setting · 5openopenprice datalenLengthsetting · 10LLLowest→ LLk1Highest→ k1k2Highest→ k2k3Highest→ k3M1WMA→ M1M2WMA→ M2M3WMA→ M3M4WMA→ M4M5WMA→ M5MAVWWMA→ MAVWrviSWMA→ rvisigSWMA→ siglongCrossover→ longlongCloseCrossunder→ longCloseshortCrossunder→ shortshortCloseCrossover→ shortClosetmaltmalvalueFmalFmalvalueFtmalFtmalvalueSmalSmalvalueNHNHconditionbox1box1conditionTopBoxTopBoxconditionBottomBoxBottomBoxconditioncol1, col3col1 · col32 conditionscolorMColourcolorMentry:Long PositionOpen Long Positionstrategy.entryexit:exitexit exitstrategy.exitclose:Long PositionClose Long Positionstrategy.closeentry:Short PositionOpen Short Positionstrategy.entryclose:Short PositionClose Short Positionstrategy.closeplot:23TBboxplotplot:24BBboxplotplot:41MAVWplot

Order rules

OrderFires whenBy defaultLine
Open Long Position longlong and window() and strategy.position_size==0 and strategy.closedtrades<100On52
Exit exit stop(longStopSet==false and strategy.position_size > 0)On54
Close Long PositionlongCloseOn58
Open Short Position shortshort and window() and strategy.position_size==0 and strategy.closedtrades<100On62
Exit exit stop(shortStopSet==false and strategy.position_size < 0)On64
Close Short PositionshortCloseOn68

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—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.

ScriptSharesTypeNetTradesMax drawdown
TradeIQ Darvas Box Backtest this page—v5 strategy0.0%00.0%
Alex Days HiLo Rajib by 14rajibhighest lowestv4 strategyNo trades on this market
Donchian Strat EXMO by pskoroplashighest lowestv4 strategy+12.1%2268.0%
Average Highest High and Lowest Low Swinger Strategy by exlux99lowest highestv4 strategy+6.4%2049.6%
Highest High and Lowest Low Channel Strategy by ceyhunhighest lowestv5 strategy−3.7%267.9%
Donchian Channels System [racer8] by racer8highest lowestv4 strategy−3.2%3643.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 verified

Neither 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msYes 1,000 bars in 61 msNot measured
PineTSNot testedNot testedNot 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)