dragon_deep_oversold_classifier.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from __future__ import annotations
  2. from dragon_strategy_config import StrategyConfig
  3. def deep_oversold_base_entry(*, a1: float, b1: float, c1: float, config: StrategyConfig) -> bool:
  4. if (
  5. config.deep_oversold_filter1_c1_low < c1 < config.deep_oversold_filter1_c1_high
  6. and a1 > config.deep_oversold_filter1_a1_min
  7. and b1 < config.deep_oversold_filter1_b1_max
  8. ):
  9. return False
  10. if (
  11. config.deep_oversold_filter2_c1_low < c1 < config.deep_oversold_filter2_c1_high
  12. and a1 > config.deep_oversold_filter2_a1_min
  13. and b1 > config.deep_oversold_filter2_b1_min
  14. ):
  15. return False
  16. return (
  17. c1 < config.deep_oversold_entry_c1_max
  18. and a1 > config.deep_oversold_entry_a1_min
  19. and b1 > config.deep_oversold_entry_b1_min
  20. )
  21. def deep_oversold_subtype(*, a1: float, b1: float, c1: float) -> str:
  22. if b1 > 0:
  23. return "positive_b1_rebound"
  24. if c1 < 11 and a1 < -0.05 and b1 < -0.08:
  25. return "deep_capitulation"
  26. if c1 < 12 and b1 < -0.06:
  27. return "classic_oversold"
  28. if c1 >= 15 or a1 > -0.03 or b1 > -0.03:
  29. return "shallow_false_start"
  30. return "mixed_oversold"
  31. def deep_oversold_requires_confirmation(
  32. *,
  33. subtype: str,
  34. ql_buy: bool,
  35. config: StrategyConfig,
  36. ) -> bool:
  37. if not config.deep_oversold_confirm_weak_with_ql:
  38. return False
  39. if subtype not in {"positive_b1_rebound", "shallow_false_start"}:
  40. return False
  41. if ql_buy:
  42. return False
  43. return True
  44. def deep_oversold_selective_veto(
  45. *,
  46. subtype: str,
  47. c1: float,
  48. b1: float,
  49. ql_buy: bool,
  50. config: StrategyConfig,
  51. ) -> bool:
  52. if (
  53. subtype == "positive_b1_rebound"
  54. and config.deep_oversold_selective_positive_b1_c1_max > 0
  55. and c1 < config.deep_oversold_selective_positive_b1_c1_max
  56. ):
  57. return True
  58. if (
  59. subtype == "shallow_false_start"
  60. and config.deep_oversold_selective_shallow_c1_min > 0
  61. and c1 >= config.deep_oversold_selective_shallow_c1_min
  62. and b1 > config.deep_oversold_selective_shallow_b1_min
  63. ):
  64. return True
  65. if (
  66. subtype == "mixed_oversold"
  67. and config.deep_oversold_selective_mixed_c1_max > 0
  68. and c1 < config.deep_oversold_selective_mixed_c1_max
  69. and (not config.deep_oversold_selective_mixed_require_no_ql or not ql_buy)
  70. ):
  71. return True
  72. return False