src.core.regime

๐Ÿฆ‰ 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/core/regime.py. A single stateless class with one static method.

class RegimeDetector

detect(candles: list[Candle], window: int = 30) -> Regime (static)

ParameterTypeDefaultMeaning
candleslist[Candle]โ€”Chronological candles; only the last window are used
windowint30Number of candles analysed (the bot passes BotConfig.regime_window, default 30)

Returns a Regime enum. If len(candles) < window, returns Regime.RANGING immediately (safe default).

Algorithm, with the v6-calibrated thresholds for 1-minute EURUSD (older thresholds 0.005/0.002 classified everything as ranging):

  1. Compute per-candle returns rets = diff(closes) / closes[:-1].
  2. vol = std(rets). If vol > 0.0008 โ†’ Regime.VOLATILE (checked first โ€” volatility wins over trend).
  3. Fit a linear trend (np.polyfit degree 1) over the closes; normalise: rel_trend = slope / last_close * window (roughly the fractional price change over the window).
  4. rel_trend > 0.0003 โ†’ TRENDING_UP; < -0.0003 โ†’ TRENDING_DOWN; otherwise RANGING.

No side effects, no logging, no state. Thresholds are hard-coded โ€” retune them in source for other assets/timeframes.

How it is used

  • src/bot.py _trade_loop(): detected each iteration; a VOLATILE result skips the trade when skip_volatile_regime is enabled, and the regime string is recorded on every trade and fed to AdaptiveStrategy.
  • ExpirySelector.select(): regime is the highest-weighted scoring input.

Usage example

from src.core.regime import RegimeDetector

regime = RegimeDetector.detect(candles, window=30)
print(regime.value)   # e.g. "trending_up"

See also

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