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)
| Parameter | Type | Default | Meaning |
|---|---|---|---|
review_interval | int | 25 | Run _review() every N recorded trades (the bot uses 25) |
min_samples | int | 15 | Minimum 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
| Parameter | Type | Meaning |
|---|---|---|
direction | str | "call" / "put" |
regime | str | Regime string value |
confidence | float | Entry confidence (fraction) |
hour | int | UTC hour 0β23 at entry |
result | str | "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:
- Regimes β any regime with β₯
min_samplestrades and win rate < 0.48 is added toblocked_regimes. - Hours β any UTC hour with β₯
min_samplestrades and win rate < 0.47 is added toblocked_hours. - Direction β if both directions have β₯
min_samplestrades: CALL WR < 0.45 while PUT WR > 0.55 setspreferred_direction = "put"(and vice versa); otherwiseNone. - Confidence adjustment β based on the
"low"band (< 0.70): WR < 0.50 βconfidence_adj = +0.05; WR > 0.55 ββ0.03; otherwise0.0. - Recent momentum β over the last 10 trades: WR < 0.30 β
adaptive_cooldown = 300s; 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:
- Regime in
blocked_regimesβ(False, "Regime '<r>' blocked by adaptive strategy"). - Hour in
blocked_hoursβ(False, "Hour HH:00 blocked ..."). - Non-preferred direction is not hard-blocked; it just needs
confidence β₯ base_min_conf + 0.08. - Finally
confidencemust 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
- Adaptive strategy concept
- Signal gates concept
- bot.md β where the gate sits in the trade loop
π¬ Unsure how this interacts with the rest of the configuration? Ask in the Chipa Discord β or prototype strategies no-code with ChipaEditor.