4. Reading the backtest chart: price, trades and equity
Level 12: Backtesting and Real Risk Metrics
The chart Backtrader produces with cerebro.plot() is a visual representation of the strategy's performance over the backtesting period. Reading it well is a skill in itself: most of a strategy's serious problems show up in the chart before they show up in the metrics table. These are its main components.
1. The price chart
- Candles or OHLC bars: they represent the open, high, low and close prices of the asset in each period.
- Moving averages: if your strategy uses them, they are drawn overlaid on the price.
- Buy and sell markers: arrows or marks showing where the strategy executed buy or sell orders.
2. Portfolio value
- Cash: the horizontal line represents the cash available in the broker account.
- Portfolio value: the line chart shows the total value of the portfolio over time, including cash and the value of open positions.
3. Trades
- Closed trades: depending on the plotting settings, dots or markers indicate where trades were closed, along with their outcome.
4. Indicators
If you have used additional indicators (MACD, RSI, and so on), they are drawn in separate panels below the price, showing how they evolve.
5. Zoom and pan
You can zoom in and out and pan across the chart to inspect specific stretches in detail. That is exactly what you should do when something does not add up.
How to analyze it
- Profitability: look at the portfolio value line to judge the strategy's profitability over time. What matters is not where it ends up, but how it gets there: a steady, stepwise climb is worth far more than a rise created by two or three lucky trades.
- Drawdown: look for the stretches where portfolio value declines. Those are the drawdowns. Pay attention not only to their depth but to their duration: a 20% drawdown that takes three years to recover is psychologically and commercially worse than a 30% one that recovers in two months.
- Trade execution: check that the buy and sell marks appear where the strategy logic says they should. If you see a buy at a point your rules do not justify, you have a bug, not a discovery.
- Indicator behavior: if you use technical indicators, watch how they evolve and make sure they are computed the way you expect. An RSI that never drops below 40 may indicate a badly chosen period rather than a bull market.
- Overfitting: be cautious. If the strategy performs exceptionally well in the backtest, it may be overfitted to the past and fail to work live.
Patterns that give problems away
There are three pictures that should set off an immediate alarm.
A flat equity curve with a huge number of trade markers means the strategy trades non-stop and costs are eating the gross margin. The signal may be real and still not be exploitable.
A curve that rises in a single step (flat for years with a vertical jump on one specific date) indicates that the entire result depends on a single trade. Remove that date and there is probably nothing left.
A cash line that separates from the portfolio value and never comes back reveals an open position that was never closed: the rest of the curve is the underlying asset, not your strategy. Many spectacular curves are an accidental buy and hold.
Finally, test sensitivity: check how much the results change when you vary the parameters, and make sure the strategy is not excessively optimized for the period tested.
To go deeper into this lesson
- Backtestin the glossary