dragon_glued_followthrough_confirmation.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from __future__ import annotations
  2. from dragon_strategy_config import StrategyConfig
  3. def glued_high_weak_rebound_subtype(
  4. *,
  5. a1: float,
  6. b1: float,
  7. c1: float,
  8. ql_buy: bool,
  9. config: StrategyConfig,
  10. ) -> str:
  11. if c1 > config.glued_high_weak_rebound_high_c1 and b1 < config.glued_high_weak_rebound_high_b1:
  12. return "high_zone_weak_b1"
  13. if c1 > config.glued_high_weak_rebound_mid_c1 and b1 < config.glued_high_weak_rebound_mid_b1:
  14. return "mid_zone_very_weak_b1"
  15. if (
  16. ql_buy
  17. and config.glued_high_weak_rebound_ql_c1_low < c1 < config.glued_high_weak_rebound_ql_c1_high
  18. and b1 < config.glued_high_weak_rebound_ql_b1
  19. and a1 > config.glued_high_weak_rebound_ql_a1
  20. ):
  21. return "ql_rebound_weak_followthrough"
  22. return ""
  23. def glued_followthrough_pending_allowed(
  24. *,
  25. subtype: str,
  26. config: StrategyConfig,
  27. ) -> bool:
  28. if not config.glued_followthrough_pending_enabled:
  29. return False
  30. if subtype == "mid_zone_very_weak_b1":
  31. return config.glued_followthrough_allow_mid_zone_very_weak_b1
  32. if subtype == "high_zone_weak_b1":
  33. return config.glued_followthrough_allow_high_zone_weak_b1
  34. if subtype == "ql_rebound_weak_followthrough":
  35. return config.glued_followthrough_allow_ql_rebound_weak_followthrough
  36. return False
  37. def evaluate_glued_followthrough_confirmation(
  38. *,
  39. active: bool,
  40. subtype: str,
  41. in_position: bool,
  42. kdj_sell: bool,
  43. ql_sell: bool,
  44. bars_waited: int,
  45. ql_buy: bool,
  46. close: float,
  47. signal_close: float,
  48. b1: float,
  49. signal_b1: float,
  50. config: StrategyConfig,
  51. ) -> tuple[str, str, bool]:
  52. if not active or not subtype:
  53. return "NONE", "", False
  54. if in_position:
  55. return "NONE", "", True
  56. if kdj_sell or ql_sell:
  57. return "NONE", "", True
  58. if bars_waited > config.glued_followthrough_confirm_window_bars:
  59. return "NONE", "", True
  60. if bars_waited < 1:
  61. return "NONE", "", False
  62. if config.glued_followthrough_require_ql_buy_reconfirm and not ql_buy:
  63. return "NONE", "", False
  64. if config.glued_followthrough_require_close_break_signal_close and close <= signal_close:
  65. return "NONE", "", False
  66. if config.glued_followthrough_require_b1_repair and (b1 - signal_b1) < config.glued_followthrough_b1_repair_min:
  67. return "NONE", "", False
  68. return "BUY", f"glued_followthrough_reentry_buy:confirmed_{subtype}", True