Dollar Cost Averaging ladders are a position-building technique where, instead of committing all capital at a single entry price, you open an initial position and add subsequent βrungsβ at progressively better prices as the market moves against you. By spreading entries, you lower the blended effective price, which reduces the percentage drawdown needed to reach breakeven and increases the probability of hitting a profit target on the blended position. Backtest Kit implements this natively withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-docs/llms.txt
Use this file to discover all available pages before exploring further.
commitAverageBuy, which tracks a harmonic mean cost basis across all entries and automatically rejects rungs that would average the wrong direction.
Backtest results
The same ladder mechanics were backtested against two distinct market regimes in 2026. Both produced significantly better outcomes than single-entry equivalents.π§ LONG DCA Ladder β April 2026
BTC rose +15.3% over the month, providing ideal conditions for a LONG ladder.
| Metric | Value |
|---|---|
| Net PNL | +67.85% on deployed capital |
| Sharpe ratio | 0.12 |
| Total trades | 7 (100% win rate) |
| Avg entries per trade | 2.4 |
| Max entries in one trade | 5 |
| Best trade | +$16.53 (5 entries, +3.31% blended) |
| Worst drawdown | β2.59% per position |
| Without DCA | +12.45% PNL, β3.99% drawdown |
πͺ SHORT DCA Ladder β March 2026
BTC was nearly flat (β0.3%) with intra-month swings of Β±15% β ideal for SHORT mean-reversion.
| Metric | Value |
|---|---|
| Net PNL | +37.83% on deployed capital |
| Sharpe ratio | 0.35 |
| Total trades | 21 (95.2% win rate) |
| Avg entries per trade | 3.1 |
| Max entries in one trade | 10 |
| Best trade | +$6.36 (8 entries, +0.79% blended) |
| Worst drawdown | β10.49% per position |
| Without DCA | β0.41% PNL (losing month) |
The DCA ladder is percentage-safer but fiat-riskier. In April, DCA improved drawdown from β3.99% to β2.59% per position. However, the maximum absolute dollar drawdown rose from β100) to β100). With 10 rungs fully deployed, the worst-case single-position loss is 250 for a single entry. Size your
LADDER_STEP_COST accordingly.Full strategy code (LONG DCA Ladder)
The following is the completeapr_2026_strategy implementation. It opens a LONG signal on every idle tick, dollar-cost-averages down on every active ping, and closes as soon as portfolio PnL crosses +3%.
How the strategy works
The strategy has three independent concerns, each handled in isolation: Signal opening (getSignal): Called on every idle tick (no active position). Returns a LONG signal using Position.moonbag, which sets a hard stop loss at β25% and an infinite hold time (minuteEstimatedTime: Infinity). The position will never time out β it stays open until explicitly closed by the profit target handler or the hard stop is hit.
DCA ladder (listenActivePing β first handler): Called on every tick while a position is active. Checks two conditions before adding a rung: the current number of entries must be below LADDER_MAX_STEPS (10), and the current price must fall outside a Β±1β5% band around the last entry via getPositionEntryOverlap. If price is still within the band, no new entry is added β this prevents excessive churn on small oscillations. When both conditions pass, commitAverageBuy adds a new $100 entry and updates the harmonic mean cost basis.
Profit-target close (listenActivePing β second handler): Also called on every active tick. Reads the current blended PnL percentage via getPositionPnlPercent and closes the entire position with commitClosePending as soon as it exceeds +3%. Because the effective price is a harmonic mean across all entries, even if individual entries are still underwater, the blended position can reach the target early.
Key techniques
getPositionEntryOverlap β preventing rungs that are too close together
getPositionEntryOverlap β preventing rungs that are too close together
getPositionEntryOverlap(symbol, currentPrice, { upperPercent, lowerPercent }) returns true if currentPrice falls within [lastEntry * (1 - lowerPercent/100), lastEntry * (1 + upperPercent/100)]. In the LONG ladder, this means: donβt add a new rung unless price has moved at least 1% below the previous entry. The asymmetric band (upperPercent: 5, lowerPercent: 1) reflects that for a LONG we primarily care about price moving down (new rung makes sense) but also want to avoid a rung being placed on a brief spike above the last entry.Harmonic mean effective price β how blended cost basis is tracked
Harmonic mean effective price β how blended cost basis is tracked
Each This is the true break-even price for the position. After each partial or average buy,
commitAverageBuy call adds a fixed-cost rung (e.g. $100). The effective price (priceOpen) of the blended position is the harmonic mean of all accepted entry prices, weighted by cost:priceOpen shifts, which in turn affects whether the next commitAverageBuy will be accepted β the engine enforces that new entries must be below the current harmonic mean for LONG positions (or above for SHORT).Position.moonbag β hard stop with infinite hold
Position.moonbag β hard stop with infinite hold
Position.moonbag({ position, currentPrice, percentStopLoss }) is a convenience factory that returns signal parameters configured for indefinite holds: minuteEstimatedTime: Infinity (never times out), a priceStopLoss at currentPrice * (1 - percentStopLoss/100), and an effectively unreachable priceTakeProfit far above current price. The position is expected to be closed programmatically (by commitClosePending) rather than by hitting the take-profit level. The stop loss is the only exchange-level protection.Adapting for SHORT
The SHORT DCA Ladder (March 2026) uses identical mechanics. The only change is the direction flag ingetSignal:
commitAverageBuy works identically for SHORT positions β for a SHORT, it adds a rung when price moves upward beyond the band, since higher entries lower the effective short cost basis. getPositionEntryOverlap automatically applies the band check in the correct direction based on the position type. The March SHORT strategy used a lower profit target (TARGET_PROFIT = 0.5) to match the mean-reverting, choppier market regime.