🧹 Add sensible limit checks for max_drawdown#16
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR adds validation to the MaxDrawdown protection to fail fast when max_allowed_drawdown is configured outside an expected range, and adds a regression test to ensure invalid configs raise OperationalException during bot initialization.
Changes:
- Added an
OperationalExceptionguard inMaxDrawdown.__init__whenmax_allowed_drawdownis outside[0.0, 1.0]. - Added a unit test covering invalid
max_allowed_drawdownvalues (> 1.0 and < 0.0).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
freqtrade/plugins/protections/max_drawdown_protection.py |
Adds range validation for max_allowed_drawdown and raises OperationalException on invalid configuration. |
tests/plugins/test_protections.py |
Adds test_MaxDrawdown_invalid_config asserting invalid drawdown limits fail with the expected exception message. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if not (0.0 <= self._max_allowed_drawdown <= 1.0): | ||
| raise OperationalException( | ||
| f"MaxDrawdown protection: max_allowed_drawdown must be between 0.0 and 1.0, " | ||
| f"but got {self._max_allowed_drawdown}." | ||
| ) |
| if not (0.0 <= self._max_allowed_drawdown <= 1.0): | ||
| raise OperationalException( | ||
| f"MaxDrawdown protection: max_allowed_drawdown must be between 0.0 and 1.0, " | ||
| f"but got {self._max_allowed_drawdown}." | ||
| ) |
🎯 What: Added validation to
MaxDrawdownprotection to ensuremax_allowed_drawdownis between 0.0 and 1.0.💡 Why: This improves maintainability and prevents unexpected behavior from invalid configuration values, providing earlier failure and clearer error messages.
✅ Verification: Ran
tests/plugins/test_protections.pywhich includes the newtest_MaxDrawdown_invalid_configtest case to verify exceptions are correctly raised. Ran pre-commit hooks to ensure formatting correctness.✨ Result: MaxDrawdown protection now throws
OperationalExceptionon invalid limits.PR created automatically by Jules for task 7262551468397269019 started by @ymcbzrgn