| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- from __future__ import annotations
- from datetime import date
- from typing import Optional
- from dragon_strategy_config import StrategyConfig
- def allow_predictive_error_reentry(
- *,
- enabled: bool,
- last_exit_predictive_break: bool,
- last_real_sell_date: Optional[date],
- row_date: date,
- a1: float,
- b1: float,
- c1: float,
- ) -> bool:
- if not enabled:
- return False
- if not last_exit_predictive_break:
- return False
- if last_real_sell_date is None:
- return False
- return (
- (row_date - last_real_sell_date).days <= 3
- and -0.02 < a1 < 0.01
- and b1 > -0.16
- and c1 > 50
- )
- def allow_predictive_b1_break_short_exit(
- *,
- enabled: bool,
- has_sell_signal: bool,
- entry_is_glued: bool,
- holding_days: int,
- a1: float,
- b1: float,
- c1: float,
- config: StrategyConfig,
- ) -> bool:
- if not enabled or has_sell_signal or not entry_is_glued:
- return False
- return (
- holding_days <= config.predictive_b1_break_short_holding_days_max
- and config.predictive_b1_break_short_a1_min < a1 < config.predictive_b1_break_short_a1_max
- and b1 < config.predictive_b1_break_short_b1_max
- and config.predictive_b1_break_short_c1_low < c1 < config.predictive_b1_break_short_c1_high
- )
- def allow_predictive_b1_break_long_exit(
- *,
- enabled: bool,
- has_sell_signal: bool,
- entry_is_glued: bool,
- holding_days: int,
- max_c1_since_entry: float,
- max_a1_since_entry: float,
- max_b1_since_entry: float,
- last_ql_sell_date: Optional[date],
- row_date: date,
- a1: float,
- b1: float,
- c1: float,
- config: StrategyConfig,
- ) -> bool:
- if not enabled or has_sell_signal or not entry_is_glued:
- return False
- if last_ql_sell_date is None:
- return False
- ql_days = (row_date - last_ql_sell_date).days
- return (
- holding_days >= config.predictive_b1_break_long_holding_days_min
- and max_c1_since_entry < config.predictive_b1_break_long_max_c1
- and max_a1_since_entry > config.predictive_b1_break_long_max_a1
- and max_b1_since_entry > config.predictive_b1_break_long_max_b1
- and 0 < ql_days <= config.predictive_b1_break_long_ql_days_max
- and config.predictive_b1_break_long_a1_min < a1 < config.predictive_b1_break_long_a1_max
- and b1 < config.predictive_b1_break_long_b1_max
- and config.predictive_b1_break_long_c1_low < c1 < config.predictive_b1_break_long_c1_high
- )
|