src.trading.strategy

πŸ¦‰ AthenaAI is an AI-powered ensemble machine-learning trading bot for PocketOption, built on BinaryOptionsToolsV2 β†’ Get it on GitLab
πŸ’¬ Need help? Join the Chipa Discord Β· ⚑ Go no-code with ChipaEditor

Source: src/trading/strategy.py. AdaptiveStrategy is a self-tuning gate layered on top of the ML signal. It tracks win/loss counts across four dimensions and, every review_interval trades, adjusts its outputs: blocked regimes, blocked UTC hours, a confidence adjustment, a preferred direction, and an extra cooldown.

class AdaptiveStrategy

__init__(self, review_interval: int = 25, min_samples: int = 15)

ParameterTypeDefaultMeaning
review_intervalint25Run _review() every N recorded trades (the bot uses 25)
min_samplesint15Minimum trades in a bucket before it can influence decisions (the bot uses 15)

State created: per-dimension stat dicts (by_regime, by_hour, by_direction, by_conf_band β€” each {key: {"wins": int, "losses": int}}); adaptive outputs (blocked_regimes: set[str], blocked_hours: set[int], confidence_adj: float = 0.0, preferred_direction: Optional[str] = None, adaptive_cooldown: int = 0 seconds); and _recent, a deque(maxlen=50) of the last 50 trades.

Confidence bands (_conf_band): "low" < 0.70 ≀ "med" < 0.80 ≀ "high".

record_trade(self, direction: str, regime: str, confidence: float, hour: int, result: str) -> None

ParameterTypeMeaning
directionstr"call" / "put"
regimestrRegime string value
confidencefloatEntry confidence (fraction)
hourintUTC hour 0–23 at entry
resultstr"win" counts as a win; anything else (including "draw") counts as a loss

Updates all four dimension buckets and the rolling deque; every review_interval trades triggers _review(). Side effect: _review() writes a multi-line log block.

_review(self) (internal, but the heart of the class)

Logs 🧠 Adaptive Strategy Review (after N trades): then recomputes all outputs from scratch:

  1. Regimes β€” any regime with β‰₯ min_samples trades and win rate < 0.48 is added to blocked_regimes.
  2. Hours β€” any UTC hour with β‰₯ min_samples trades and win rate < 0.47 is added to blocked_hours.
  3. Direction β€” if both directions have β‰₯ min_samples trades: CALL WR < 0.45 while PUT WR > 0.55 sets preferred_direction = "put" (and vice versa); otherwise None.
  4. Confidence adjustment β€” based on the "low" band (< 0.70): WR < 0.50 β†’ confidence_adj = +0.05; WR > 0.55 β†’ βˆ’0.03; otherwise 0.0.
  5. Recent momentum β€” over the last 10 trades: WR < 0.30 β†’ adaptive_cooldown = 300 s; WR < 0.40 β†’ 120 s; otherwise 0 (and a β€œπŸ”₯ On fire!” log line when WR > 0.65).

should_trade(self, direction: str, regime: str, confidence: float, hour: int, base_min_conf: float) -> tuple[bool, str]

Returns (allowed, reason). Checks in order:

  1. Regime in blocked_regimes β†’ (False, "Regime '<r>' blocked by adaptive strategy").
  2. Hour in blocked_hours β†’ (False, "Hour HH:00 blocked ...").
  3. Non-preferred direction is not hard-blocked; it just needs confidence β‰₯ base_min_conf + 0.08.
  4. Finally confidence must be β‰₯ base_min_conf + confidence_adj.

base_min_conf is BotConfig.min_confidence in the live bot. No side effects.

get_extra_cooldown(self) -> int

Returns adaptive_cooldown in seconds. The bot enforces this in addition to min_wait_between_trades after each trade.

status_line(self) -> str

Compact status for logs, e.g. "β›”reg:volatile | β›”hr:3,14 | prefer:put | conf:+5% | cool:120s", or "all-clear".

Persistence

The object itself is not saved. On startup AITradingBot._reload_from_journal() replays completed trades from the journal through record_trade(), which rebuilds the buckets and re-runs reviews.

Usage example

from src.trading.strategy import AdaptiveStrategy

ad = AdaptiveStrategy(review_interval=25, min_samples=15)
ad.record_trade("call", "ranging", 0.66, hour=20, result="win")
ok, reason = ad.should_trade("call", "ranging", 0.66, 20, base_min_conf=0.63)

See also

πŸ’¬ Unsure how this interacts with the rest of the configuration? Ask in the Chipa Discord β€” or prototype strategies no-code with ChipaEditor.