"""All SuperEA robot instances with defaults and optimization ranges."""

from __future__ import annotations

import MetaTrader5 as mt5

TF = {
    "M10": mt5.TIMEFRAME_M10,
    "M15": mt5.TIMEFRAME_M15,
    "M20": mt5.TIMEFRAME_M20,
    "M30": mt5.TIMEFRAME_M30,
    "H1": mt5.TIMEFRAME_H1,
    "H4": mt5.TIMEFRAME_H4,
}

STRATEGIES: list[dict] = [
    {"id": "darvas_xau", "engine": "darvas", "symbol": "XAUUSD", "tf": "M15", "lot": 0.07,
     "defaults": {"box_period": 24, "box_deviation": 80000, "ma_period": 60,
                  "trend_threshold": 1.2, "volume_threshold": 0,
                  "stop_loss_pts": 450, "take_profit_pts": 650},
     "opt": {"box_period": (12, 48, 4), "box_deviation": (40000, 150000, 5000),
             "trend_threshold": (0.3, 5.0, 0.3), "stop_loss_pts": (250, 900, 50),
             "take_profit_pts": (350, 1200, 50), "ma_period": (30, 120, 15)}},
    {"id": "ema_slope_unit", "engine": "ema_slope", "symbol": "XAUUSD", "tf": "H1", "lot": 0.07,
     "defaults": {"ema_period": 85, "price_threshold_pips": 350, "slope_threshold_pips": 22.5,
                  "monitor_timeout_sec": 340, "max_trades_per_crossover": 12, "use_trailing_stop": False,
                  "trailing_stop_pips": 74, "max_loss_atr": 1.8, "use_bar_data": True,
                  "close_unprofitable_trades": True, "profit_check_bars": 36,
                  "use_weekly_adx_filter": True, "weekly_adx_period": 28,
                  "weekly_adx_min": 25, "weekly_adx_bar_shift": 8, "weekly_adx_use_direction": True},
     "opt": {"ema_period": (50, 120, 5), "price_threshold_pips": (150, 500, 50),
             "slope_threshold_pips": (10, 50, 5), "max_loss_atr": (1.2, 3.0, 0.3),
             "profit_check_bars": (18, 60, 6), "max_trades_per_crossover": (3, 20, 3)}},
    {"id": "ema_slope_trail", "engine": "ema_slope", "symbol": "XAUUSD", "tf": "H1", "lot": 0.07,
     "defaults": {"ema_period": 50, "price_threshold_pips": 700, "slope_threshold_pips": 25,
                  "monitor_timeout_sec": 340, "max_trades_per_crossover": 3, "use_trailing_stop": True,
                  "trailing_stop_pips": 370, "max_loss_atr": 2.0, "use_bar_data": True,
                  "close_unprofitable_trades": True, "profit_check_bars": 11,
                  "use_weekly_adx_filter": True, "weekly_adx_period": 15,
                  "weekly_adx_min": 40, "weekly_adx_bar_shift": 2, "weekly_adx_use_direction": True},
     "opt": {"ema_period": (30, 90, 5), "trailing_stop_pips": (150, 450, 50),
             "max_loss_atr": (1.2, 3.5, 0.3), "weekly_adx_min": (25, 50, 5)}},
    {"id": "mean_rev_btc", "engine": "mean_reversion", "symbol": "BTCUSD", "tf": "M15", "lot": 0.01,
     "defaults": {"ema_period": 80, "min_ema_distance_pts": 300, "rsi_period": 14,
                  "rsi_oversold": 40, "rsi_overbought": 70, "adx_period": 14,
                  "adx_max_for_entry": 30, "adx_escape": 40, "use_rsi_cross": True,
                  "use_hard_sltp": False, "sl_points": 1300, "tp_points": 13400},
     "opt": {"rsi_oversold": (30, 50, 5), "rsi_overbought": (60, 80, 5),
             "min_ema_distance_pts": (100, 1500, 100), "adx_max_for_entry": (22, 40, 3),
             "ema_period": (40, 120, 20)}},
    {"id": "rsi_cross_xau", "engine": "rsi_crossover", "symbol": "XAUUSD", "tf": "H1", "lot": 0.01,
     "defaults": {"rsi_period": 19, "overbought_level": 93, "oversold_level": 22, "ema_period": 140,
                  "ema_slope_threshold": 105, "ema_distance_threshold": 165, "exit_buy_rsi": 86,
                  "exit_sell_rsi": 10, "trailing_stop_pts": 295, "cooldown_seconds": 209,
                  "tuesday": True, "wednesday": True, "thursday": True,
                  "trading_hour_one_begin": 0, "trading_hour_one_end": 22,
                  "trading_hour_two_begin": 6, "trading_hour_two_end": 19},
     "opt": {"overbought_level": (65, 95, 5), "oversold_level": (10, 45, 5),
             "ema_slope_threshold": (20, 200, 20), "ema_distance_threshold": (40, 300, 20)}},
    {"id": "rsi_asian_eur", "engine": "rsi_asian", "symbol": "EURUSD", "tf": "M15", "lot": 0.1,
     "defaults": {"rsi_period": 28, "overbought_level": 60, "oversold_level": 8,
                  "asian_session_start": 0, "asian_session_end": 8, "use_rsi_exit": True, "rsi_exit_level": 55},
     "opt": {"overbought_level": (50, 80, 5), "oversold_level": (5, 40, 5)}},
    {"id": "rsi_asian_aud", "engine": "rsi_asian", "symbol": "AUDUSD", "tf": "M15", "lot": 0.1,
     "defaults": {"rsi_period": 28, "overbought_level": 68, "oversold_level": 30,
                  "asian_session_start": 0, "asian_session_end": 8, "use_rsi_exit": True, "rsi_exit_level": 55},
     "opt": {"overbought_level": (55, 80, 5), "oversold_level": (15, 45, 5)}},
    {"id": "rsi_asian_gbp", "engine": "rsi_asian", "symbol": "GBPUSD", "tf": "M15", "lot": 0.1,
     "defaults": {"rsi_period": 28, "overbought_level": 80, "oversold_level": 37,
                  "asian_session_start": 0, "asian_session_end": 8, "use_rsi_exit": True, "rsi_exit_level": 55},
     "opt": {"overbought_level": (60, 85, 5), "oversold_level": (20, 50, 5)}},
    {"id": "rsi_secret_xau", "engine": "rsi_secret", "symbol": "XAUUSD", "tf": "M30", "lot": 0.01,
     "defaults": {"rsi_period": 16, "rsi_overbought": 72.5, "rsi_oversold": 32.5,
                  "stop_loss_atr": 2.75, "take_profit_atr": 5.0, "min_bars_between_trades": 7},
     "opt": {"rsi_overbought": (60, 80, 2), "rsi_oversold": (25, 45, 2), "stop_loss_atr": (1.5, 4, 0.5)}},
]

_RSI_SCALPS = [
    ("rsi_scalp_appl_unit", "AAPL", "M10", 25.0, {"rsi_period": 14, "rsi_overbought": 80, "rsi_oversold": 78,
     "rsi_target_buy": 94, "rsi_target_sell": 44, "bars_to_wait": 7, "use_trailing": False}),
    ("rsi_scalp_appl_trail", "AAPL", "H1", 25.0, {"rsi_period": 8, "rsi_overbought": 62, "rsi_oversold": 32,
     "rsi_target_buy": 67, "rsi_target_sell": 2, "bars_to_wait": 5, "use_trailing": True,
     "trail_distance_pts": 50, "trail_activation_pts": 39}),
    ("rsi_scalp_adbe_trail", "ADBE", "H1", 5.0, {"rsi_period": 15, "rsi_overbought": 16, "rsi_oversold": 42,
     "rsi_target_buy": 67, "rsi_target_sell": 62, "bars_to_wait": 8, "use_trailing": True,
     "trail_distance_pts": 425, "trail_activation_pts": 18.5}),
    ("rsi_scalp_btc_unit", "BTCUSD", "H1", 0.1, {"rsi_period": 14, "rsi_overbought": 90, "rsi_oversold": 73,
     "rsi_target_buy": 88, "rsi_target_sell": 48, "bars_to_wait": 6, "use_trailing": False}),
    ("rsi_scalp_btc_trail", "BTCUSD", "H1", 0.1, {"rsi_period": 14, "rsi_overbought": 90, "rsi_oversold": 73,
     "rsi_target_buy": 88, "rsi_target_sell": 48, "bars_to_wait": 6, "use_trailing": True,
     "trail_distance_pts": 120, "trail_activation_pts": 0}),
    ("rsi_scalp_mu", "MU", "H1", 25.0, {"rsi_period": 14, "rsi_overbought": 32, "rsi_oversold": 86,
     "rsi_target_buy": 100, "rsi_target_sell": 24, "bars_to_wait": 34, "use_trailing": False}),
    ("rsi_scalp_nvda_unit", "NVDA", "H1", 25.0, {"rsi_period": 14, "rsi_overbought": 6, "rsi_oversold": 66,
     "rsi_target_buy": 98, "rsi_target_sell": 52, "bars_to_wait": 12, "use_trailing": False}),
    ("rsi_scalp_nvda_trail", "NVDA", "M15", 50.0, {"rsi_period": 8, "rsi_overbought": 36, "rsi_oversold": 38,
     "rsi_target_buy": 90, "rsi_target_sell": 70, "bars_to_wait": 5, "use_trailing": True,
     "trail_distance_pts": 375, "trail_activation_pts": 75}),
    ("rsi_scalp_nvda_trail_v2", "NVDA", "M15", 50.0, {"rsi_period": 8, "rsi_overbought": 36, "rsi_oversold": 38,
     "rsi_target_buy": 90, "rsi_target_sell": 70, "bars_to_wait": 5, "use_trailing": True,
     "trail_distance_pts": 375, "trail_activation_pts": 75}),
    ("rsi_scalp_tsla_unit", "TSLA", "H1", 25.0, {"rsi_period": 14, "rsi_overbought": 32, "rsi_oversold": 86,
     "rsi_target_buy": 100, "rsi_target_sell": 24, "bars_to_wait": 34, "use_trailing": False}),
    ("rsi_scalp_tsla_trail", "TSLA", "H1", 5.0, {"rsi_period": 14, "rsi_overbought": 54, "rsi_oversold": 73,
     "rsi_target_buy": 87, "rsi_target_sell": 33, "bars_to_wait": 1, "use_trailing": True,
     "trail_distance_pts": 900, "trail_activation_pts": 950}),
    ("rsi_scalp_xau_trail", "XAUUSD", "H1", 0.1, {"rsi_period": 14, "rsi_overbought": 71, "rsi_oversold": 57,
     "rsi_target_buy": 80, "rsi_target_sell": 57, "bars_to_wait": 1, "use_trailing": True,
     "trail_distance_pts": 71, "trail_activation_pts": 41}),
]

for sid, sym, tf, lot, defaults in _RSI_SCALPS:
    STRATEGIES.append({
        "id": sid,
        "engine": "rsi_scalp",
        "symbol": sym,
        "tf": tf,
        "lot": lot,
        "defaults": {**defaults, "tf": tf},
        "opt": {
            "rsi_period": (6, 21, 1),
            "rsi_overbought": (50, 90, 3),
            "rsi_oversold": (10, 70, 3),
            "rsi_target_buy": (60, 95, 3),
            "rsi_target_sell": (5, 70, 3),
            "bars_to_wait": (1, 8, 1),
            "trail_distance_pts": (20, 400, 20),
        },
    })

PERIODS = {
    "2021-2026": ("2021-01-01", "2026-06-01"),
    "2024-2026": ("2024-01-01", "2026-06-01"),
}
