Backtests, Not Signals

I Built a ‘Safe’ 10% Monthly DCA Strategy. It Still Got Liquidated.

A statistical example of how in-sample optimization and martingale dynamics guarantee eventual ruin.

Ale's avatar
Ale
Feb 08, 2026
∙ Paid

This article is not about how to make 10% per month.

It is about why a strategy that did make 10% per month still ended in liquidation.

I originally developed this system for TradingView and FreqTrade.

Here, however, the focus is not on execution, but on the backtesting and optimization process used to push a martingale-style strategy as far as possible before it inevitably fails.


The contest is of a mean reverting greedy strategy, that use leverage and trade long and short. The original goal was to find parameter configurations that would make liquidation effectively impossible.

In practice, this means pushing the failure mode outside the observed sample.

Unfortunately, overfitting is unforgiving.

The goal of the backtest was not to maximize profit, but to measure how close the strategy operates to liquidation over time.

Strategy

The strategy is a leveraged mean-reversion system that trades both long and short using Bollinger Bands as entry triggers.

When price crosses a band, a base order is opened.

If price continues to move against the position, additional safety orders are placed at increasing distances and sizes, progressively shifting the average entry price.

A fixed take-profit closes the entire position when mean reversion occurs.

A very important aspect of the strategy is the search for a stable setup. Since it’s a strategy that doesn’t accept losses, the trade can remain open for a long time, despite the potential for liquidation. The optimization process takes these aspects into account, and liquidation has been modeled using typical “isolated margin” limits plus an additional safety buffer.

The algorithm
For each new bar:
  if no open position:
    if price crosses Bollinger Band:
      open base order
      schedule safety orders
  else:
    update average entry price
    if price reaches take profit:
      close position
    if price reaches next safety order:
      increase position size
    if price reaches liquidation boundary:
      liquidate position

Note on position sizing

this backtest explores the survival limits of a leveraged DCA system under isolated margin.

Position sizes are therefore expressed as a fraction of maximum notional (equity × leverage), not as portfolio allocation.

Limiting risk in practice must happen at the allocation level, not inside the position.


Backtest setup

The results presented in this article were obtained using backtesting.py on DOGEUSDT perpetual futures from Bybit.

  • 5-minute candles

  • Isolated margin: limit damage in case of liquidation, is handled by ccxt library, and supported by freqtrade bot;

  • in-sample and out-of-sample separation

  • explicit liquidation modeling

Under isolated margin, a liquidation does not necessarily imply the end of the trading system.

It can be interpreted as a very deep stop loss applied to a single position.

Once the isolated margin is exhausted, the position is force-closed, but the remaining capital outside that allocation is unaffected, allowing the strategy to continue operating.

For this reason, liquidations are treated in this analysis as extreme risk events rather than terminal failures.

This is also why the optimization explicitly accounts for the number of margin calls, penalizing parameter configurations that rely on frequent liquidations to achieve higher returns.

Custom plots display both liquidation levels and safety order levels, making it possible to visually identify proximity to ruin.



Backtest with heuristic parameters

Before introducing the optimization process, it is useful to observe how the strategy behaves under a set of reasonable, manually selected parameters.

These values are not the result of any optimization procedure and are used only as a baseline.

Fig.1 backtest without optimization


Optimization against ruin

It is crucial for the strategy to manage volatility effectively and avoid liquidation scenarios that would permanently disable the bot.

The objective is not to maximize returns at all costs, but to identify parameter configurations that, while potentially less profitable, demonstrate greater resilience to adverse market conditions.

The optimization process searches for the best combination of parameters (including safety order count, price deviations, scaling factors, and trigger logic).
However, profit alone was not the optimization target.

I explicitly penalized strategies that experienced margin calls.

In other words, liquidation risk was part of the objective function:

maximize=lambda x: x[’Equity Final [$]’] / ( 1 + x[’margin calls’])

This formulation favors strategies that survive longer under leverage, even at the cost of reduced returns.

And yet, survival is still not guaranteed.


Supplementary material

Subscribers get access to a fully documented Jupyter notebook containing:
– the complete backtesting workflow
– the optimization process
– interactive charts with liquidation and safety order levels

The article is fully readable without it, but the notebook provides additional depth for those who want to explore the analysis in detail.

Subscribe to access the research notebook (free subscription available)

Margin calls and backtesting.py

The standard backtesting.py framework does not track margin calls as a first-class metric.
To properly model leveraged trading, I extended it to explicitly count liquidation events during the backtest.

The modified version of the framework is publicly available to subscribers.

Optimization does not eliminate tail risk.
It pushes it outside the observed sample.

The optimizer did not remove the failure mode. It delayed it.

The optimization process tries multiple solutions before find the bests

Results

The following tables summarize the same strategy under two different conditions:
survival inside the optimization window, and failure outside of it.

The in-sample performance is intentionally strong.

The purpose of the analysis is not to demonstrate realistic returns,

but to show how aggressive optimization can produce apparently robust results

that fail once exposed to new market regimes.

Start                     2021-06-02 10:40:00
End                       2024-09-28 10:45:00
Duration                   1214 days 00:05:00
Equity Final [$]                   5209.83856
Commissions [$]                     420.80113
Return [%]                          941.96771
Buy & Hold Return [%]                -71.5597
Return (Ann.) [%]                   102.19721
CAGR [%]                             102.3141
Sharpe Ratio                          1.13084
Max. Drawdown [%]                   -42.69857
# Trades                                 2573
Win Rate [%]                         82.66615
margin calls                                0
Perfect in sample backtest too good to be true

When the strategy eventually got liquidated during the last bull run, it was not a surprise.

It was simply an out-of-sample event.

The following results show what happens when this optimized configuration is exposed to market conditions outside the optimization window.

Start                     2024-09-29 00:00:00
End                       2026-02-01 13:45:00
Duration                    490 days 13:45:00
Equity Final [$]                    239.13059
Commissions [$]                      28.75532
Return [%]                          -52.17388
Buy & Hold Return [%]               -13.25971
CAGR [%]                            -42.23539
Sharpe Ratio                         -0.68357
Max. Drawdown [%]                   -68.24254
# Trades                                 1057
Win Rate [%]                         82.87606
margin calls                                2
the real world is out sample and in this case I had 2 margin calls

Does the strategy always fail



The strategy does not fail immediately, nor does it fail deterministically.

Bayesian optimization produces multiple viable parameter configurations, many of which survive the out-of-sample window.

However, for martingale-style systems, “survival” is not a sufficient criterion.

Without an explicit bound on losses, time becomes the enemy.

Bayesian optimization is a method for optimizing complex and expensive-to-evaluate functions, is particularly effective in reducing the number of evaluations needed to find the optimal solution, making it ideal for hyperparameter tuning where evaluations are costly or time-consuming.

Leverage as a structural choice

A common objection to this analysis is straightforward: why use leverage at all?

If the strategy were applied only long and without leverage, liquidation would not occur.

This is true.

However, the absence of liquidation does not imply the absence of risk.

In a DCA-based mean reversion system, risk does not disappear — it changes form.

Without leverage, it concentrates into extremely long holding periods, sometimes lasting months or years, during which capital remains locked and unusable.

Leverage was therefore not introduced to amplify returns, but to change the time profile of risk.

By allowing both long and short exposure and by operating on small price movements, the strategy can generate frequent exits in range-bound markets, which represent the dominant regime for most liquid crypto assets.

This comes at a cost.

Leverage transforms time risk into tail risk.

Instead of being stuck indefinitely in a trade, the strategy becomes exposed to rare but catastrophic liquidation events.

This trade-off is precisely the subject of this article.

The failure observed is not the result of reckless leverage usage, but of a structural decision to exchange persistence risk for ruin risk.

Conclusion


This article is not a warning against DCA, nor a rejection of optimization.

It is a reminder that backtests do not eliminate risk — they only hide it.

In leveraged systems, ruin is not an anomaly. It is a statistical certainty whose timing is unknown.

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2026 Alessandro Arrabito · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture