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:
- The full current source file (not snippets)
- The exact build error output (copy and paste)
- If it runs but is wrong:
- What you expected
- What actually happened
- When it happens (steps to reproduce)
- 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:
- Paste the full source file.
- Paste the build error output exactly as shown.
- State:
- “Fix compile errors only.”
- “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.
Recommended Next Steps
After the fix:
- Rebuild and confirm errors are resolved
- Run a basic functional test
- Return only if something still breaks
-
Then continue with the next workflow, such as:
- Add Risk Management
- Build a Trading Robot