Skip to content

Fix and Refactor Code Bugs in Trading Tools

What this Workflow Does

The Fix and Refactor Code Bugs workflow helps you correct build issues, runtime errors, and logic bugs in trading-related code.

It is designed for:

  • Compile and build errors
  • API misuse or incorrect method usage
  • Runtime exceptions and unstable behaviour
  • Logic bugs that produce incorrect signals or trades
  • Safe refactoring to improve structure without changing behaviour

This workflow focuses on making the code correct and maintainable, not adding new features.


When to Use This Workflow

Use this workflow when:

  • Your tool fails to compile or build
  • The tool runs but behaves incorrectly
  • You have error messages, logs, or clear symptoms
  • You need a clean refactor to reduce complexity or improve structure

Do not use this workflow to add functionality.
Fix first, then extend using the appropriate workflow.


What You Should Prepare

Before starting, gather the following:

  1. The full current source file (not snippets)
  2. The exact build error output (copy and paste)
  3. If it runs but is wrong:
  4. What you expected
  5. What actually happened
  6. When it happens (steps to reproduce)
  7. Any logs or stack traces (if available)

If you changed the code manually, include what you changed.


How to Report Build Errors Correctly

To get fast, accurate fixes, report errors like this:

  1. Paste the full source file.
  2. Paste the build error output exactly as shown.
  3. State:
  4. “Fix compile errors only.”
  5. “Do not add features.”

Avoid summarising errors in your own words.
The exact compiler output matters.


How to Interact with CodePilot

Be explicit about the scope of the fix.

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 be done in separate steps.


How CodePilot Fixes and Refactors

CodePilot will:

  • Identify the root cause of build or runtime issues
  • Apply minimal, targeted fixes first
  • Preserve behaviour unless you explicitly request changes
  • Refactor structure only when it improves clarity and does not alter results
  • Return a complete, compile-ready file

If a requested change could alter behaviour, CodePilot should highlight the risk before proceeding.


Common Mistakes to Avoid

  • Sending only partial code
  • Omitting the full error output
  • Mixing bug fixes with new features
  • Re-testing without rebuilding after changes
  • Making manual edits and not telling CodePilot

Keep the workflow tight: fix, compile, test, then continue.


After the fix: