Debug a Trading Strategy: Trace Any Bad Trade

To debug a trading strategy, you stop asking why it lost and start asking what it saw. A backtest report tells you that a trade went wrong. It cannot tell you whether your rules misfired or simply lost, as sound rules sometimes do. Only the values at that exact candle can separate the two.
Our post on AI backtest analysis covers reading the finished report. This one goes a level deeper, to a single bad trade.
What Does It Mean to Debug a Trading Strategy?
Debugging a strategy means comparing what your rules were meant to do with what they actually did. You pick one specific candle. Then you inspect the inputs and outputs of each step in the logic at that moment.
Debugging is an old software idea, but it needs no programming here. In a visual strategy, each block receives values and produces a result. You are simply reading those results in order.
Why a Losing Trade Is Not Always a Bug
Losing trades come in two very different kinds. Each needs the opposite response.
Some losses are correct. The rules did what you intended, and the market went the other way. Changing anything here means tuning the strategy to one past event.
Others are errors. An input is connected to the wrong source, or a crossover points the wrong way. The report can show a respectable profit while one of these sits inside it.
Summary numbers cannot tell the two apart. That is why tracing candles belongs before any change to the rules. It also applies to winners, since a bug can make money by accident.
How Do You Capture the Right Candles?
Saving every block value for every candle produces a lot of data. So debug logging works best on a focused window.
Arrow Algo’s backtest has an option to save these logs. Keep logged runs to about two weeks, or roughly 2,000 candles. For a longer test, set a separate debug date range around the trade you care about. The backtest still covers its full period, and only the logging narrows.
Choose your candles first:
- The signal candle. This is the completed candle where the entry condition became true.
- The candle before it. Crossovers depend on a change between two candles, so you need both.
- The fill candle. The next candle’s open is usually the earliest realistic fill.
- The exit candle. Check that the intended rule closed the position, not a different branch.
Read One Trade Candle by Candle
Start at the action block and work backwards. It is the fastest route to the cause.
First, confirm that the action fired on the candle you expected. Next, read the condition feeding it, and note whether it was true or false. Then read the indicator values feeding that condition. Finally, compare those values with your charting tool.
Say a strategy buys when the Relative Strength Index (RSI) crosses above 30, and one entry looks wrong. These illustrative questions lead the trace:
- What was the RSI on the signal candle and the candle before it?
- Was the block reading the close, as intended?
- Was the indicator still warming up, with too little history to settle?
- Did any other condition change on that candle?
Be careful with times. A value from a candle that has not closed can look like a perfect signal in hindsight. Our posts on look-ahead bias and candle-close confirmation explain why.
Which Failure Did You Find?
Each trace should end with a classification. Write it down before you change anything.
| What the trace shows | Likely cause | What to do |
|---|---|---|
| A block read the wrong input or timeframe | Wiring error | Fix it, then rerun the full test |
| The condition is true on the wrong side of a cross | Logic error | Correct the condition and check earlier trades |
| The trade fired during the warm-up | Too little history | Exclude that period from the test window |
| The signal was right, but the fill was far away | Cost or slippage | Review your cost model and position size |
| Every value matches your intent | Normal loss | Change nothing, and log it |
The last row is the one traders resist. If every value is right, the trace has done its job. It has stopped you from fixing something that was not broken.
The Trade That Never Fired
Missing trades deserve the same treatment. Pick a candle where you expected an entry, and ask which condition blocked it.
Arrow Algo’s trace reports this on the action block, including when an upstream condition was false or missing. Often the cause is a filter that is stricter than you remember. Sometimes a position-state check is still waiting for a previous trade to close.
Debug a Trading Strategy With an AI Assistant
Tracing by hand works, but a connected AI assistant makes it quicker. Arrow Algo connects to assistants through the Model Context Protocol, and our MCP guide covers the setup. The assistant can then read the same per-candle values.
Plain-English requests work well here:
- “Run this strategy again with debug logs on for 10 to 14 March.”
- “Show me each block’s value on the candle before the worst trade.”
- “Why was there no entry at 08:00 on 12 March? Which condition blocked it?”
Stay in charge of the conclusion, though. An assistant can write a fluent explanation that the numbers do not support. Ask it to quote the exact values, then check one or two yourself.
Do Not Patch One Trade
A new rule that removes one bad trade always looks clever on that trade. It may also remove ten good ones. Treat any change as a new hypothesis. Test it across the full period, then on data you did not use to find it.
How to Apply Strategy Debugging in Arrow Algo
Here is the routine, using the no-code visual builder and drag-and-drop blocks you already have:
- Run the full backtest as normal, then pick the worst trade from the order list.
- Rerun with debug logs on, and set the debug range to a few days around that trade.
- Open the diagnostic view, or ask your connected assistant for the trace.
- Select the signal candle, and walk from the action block back to the indicators.
- Classify the result using the table above.
- Fix real errors and rerun. Leave normal losses alone.
- Repeat for the best trade and one missed entry.
Three traces like this take little time and often reveal more than another round of parameter tests. If you later choose to deploy, your rules signal your own exchange account and the exchange decides whether to execute.
What Are the Key Takeaways?
- To debug a trading strategy, inspect one candle and compare intent with behaviour.
- Log only a short window around the trade you want to examine.
- Work backwards from the action block to the indicators.
- Classify each finding before changing a rule, because many losses are not bugs.
- Trace winners and missed entries as well as losers.
- Test any fix across the full period, never just on the trade that prompted it.
Disclaimer: This content is for educational purposes only and does not constitute financial advice. Trading involves significant risk and you should only trade with capital you can afford to lose. Past performance is not indicative of future results. Always conduct your own research before making any trading decisions.
Ready to build your own automated trading strategies without writing a single line of code? Start for free at Arrow Algo and join thousands of traders who've made the switch to systematic trading.