Skip to content

Fix cTrader Algo Code Bugs with Xen AI

What this Workflow Does

The Fix and Refactor Code Bugs workflow helps you resolve issues in existing trading code, including indicators, cBots, and plugins.

This includes fixing compile errors, runtime exceptions, incorrect logic, and unstable behaviour. It can also be used to clean up and refactor code so it is easier to maintain, without changing how it behaves. The focus is on making the code correct, stable, and maintainable. It is not intended for adding new features.

Watch Video Explainer

Watch this video to learn how to fix bugs in your cBot or indicator.

Tip: Set the video quality to HD (1080p) for the best viewing experience.

When to Use This Workflow

Use this workflow when your code fails to compile, produces errors, or behaves incorrectly. It is also useful when the code works but is difficult to maintain or understand and needs a structured refactor. Do not use this workflow to add new functionality. Fix the issues first, then extend the tool using the appropriate workflow.

What You Should Prepare

Before starting, gather the full source code and any information that explains the problem. Xen needs the complete file to identify and fix issues correctly.

You should provide:

  • the full current source file
  • the exact build error output, copied directly
  • a description of what you expected to happen
  • what actually happened instead
  • steps to reproduce the issue, if applicable
  • any logs or stack traces

If you have already modified the code, include what you changed so Xen can understand the context.

How to Report Build Errors Correctly

Accurate error reporting is critical for fast fixes. Always provide the full code and the exact compiler output without summarising it.

A clear request should include:

  • the full source file
  • the exact error messages
  • a simple instruction such as “Fix compile errors only. Do not add features.”

Avoid rewriting or interpreting the error messages yourself. The original output is what Xen uses to identify the problem.

How to Interact with Xen

Be explicit about what needs to be fixed and what should remain unchanged. This helps avoid unintended behaviour changes.

Good examples:

  • “Fix the compile errors only. Do not change behaviour.”
  • “This throws a null reference exception when I change timeframe.”
  • “The indicator draws but values are wrong after bar 100.”
  • “Refactor this code for readability without changing outputs.”

Avoid requests such as:

  • “Fix it and improve it.”
  • “Refactor and add alerts.”
  • “Make it faster and add features.”

Fixing and extending should always be handled in separate steps.

How Xen Fixes and Refactors

Xen will analyse the code and identify the root cause of the issue. It will apply minimal, targeted fixes first to restore correct behaviour. If refactoring is requested, Xen will improve structure and readability while keeping the output unchanged. It will avoid unnecessary rewrites and will highlight any changes that could affect behaviour. The result is returned as a complete, compile-ready file.

Common Mistakes to Avoid

Most delays in fixing issues come from incomplete or unclear inputs. Always provide the full code and exact error output.

Avoid these common mistakes:

  • sending only partial code
  • omitting the full error output
  • mixing bug fixes with new feature requests
  • re-testing without rebuilding after changes
  • making manual edits without explaining them

A clear fix, compile, and test cycle produces the best results.

After applying the fix, rebuild the code and confirm that all errors are resolved. Run a basic test to ensure the tool behaves as expected. If further issues appear, return with updated details. Once the code is stable, you can continue development using other workflows.