"""United EA (main.mq5) strategy registry — defaults from 123.set + audit 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 enabled in 123.set, ordered for sequential audit.
UNITED_STRATEGIES: list[dict] = [
    {"id": "united_darvas", "engine": "darvas", "symbol": "XAUUSD", "tf": "M15", "lot": 0.05,
     "enable_key": "EnableDarvasBox", "lot_key": "LOT_DB_DarvasBox",
     "defaults": {"box_period": 24, "box_deviation": 90000, "ma_period": 30,
                  "trend_threshold": 1.2, "volume_threshold": 0,
                  "stop_loss_pts": 300, "take_profit_pts": 950},
     "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": "united_rsi_cross", "engine": "rsi_crossover", "symbol": "XAUUSD", "tf": "M15", "lot": 0.06,
     "enable_key": "EnableRSICrossOverReversal", "lot_key": "LOT_RC_RSICrossOver",
     "defaults": {"rsi_period": 19, "overbought_level": 85, "oversold_level": 25, "ema_period": 140,
                  "ema_slope_threshold": 105, "ema_distance_threshold": 350, "exit_buy_rsi": 86,
                  "exit_sell_rsi": 10, "trailing_stop_pts": 295, "cooldown_seconds": 120,
                  "use_trend_strength_filter": True, "entry_rsi_buy_spread": 0, "entry_rsi_sell_spread": 0,
                  "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": (70, 92, 3), "oversold_level": (15, 40, 3),
             "ema_distance_threshold": (200, 600, 50), "cooldown_seconds": (60, 300, 30)}},
    {"id": "united_rsi_scalp_appl", "engine": "rsi_scalp", "symbol": "AAPL", "tf": "M15", "lot": 15.0,
     "enable_key": "EnableRSIScalpingAPPL", "lot_key": "LOT_RS_APPL",
     "defaults": {"rsi_period": 8, "rsi_overbought": 64, "rsi_oversold": 30,
                  "rsi_target_buy": 67, "rsi_target_sell": 2, "bars_to_wait": 5,
                  "use_trailing": True, "trail_distance_pts": 70, "trail_activation_pts": 39, "tf": "M15",
                  "skip_short_hour_after": 17, "use_reversal_escape": False,
                  "use_rsi_against_exit": False, "max_adverse_atr": 2.5, "min_ob_depth": 0},
     "opt": {"rsi_period": (6, 14, 1), "rsi_overbought": (60, 75, 2), "rsi_oversold": (22, 35, 2),
             "rsi_target_buy": (60, 80, 3), "bars_to_wait": (5, 12, 1),
             "trail_distance_pts": (50, 120, 10), "skip_short_hour_after": (15, 20, 1)}},
    {"id": "united_rsi_scalp_adbe", "engine": "rsi_scalp", "symbol": "ADBE", "tf": "H1", "lot": 40.0,
     "enable_key": "EnableRSIScalpingADBE", "lot_key": "LOT_RS_ADBE",
     "defaults": {"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, "tf": "H1"},
     "opt": {"rsi_period": (6, 21, 1), "rsi_overbought": (50, 90, 3), "rsi_oversold": (10, 70, 3),
             "bars_to_wait": (1, 12, 1), "trail_distance_pts": (50, 500, 25)}},
    {"id": "united_rsi_scalp_btc", "engine": "rsi_scalp", "symbol": "BTCUSD", "tf": "H1", "lot": 0.03,
     "enable_key": "EnableRSIScalpingBTCUSD", "lot_key": "LOT_RS_BTCUSD",
     "defaults": {"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, "tf": "H1"},
     "opt": {"rsi_period": (6, 21, 1), "rsi_overbought": (50, 95, 3), "rsi_oversold": (20, 80, 3),
             "bars_to_wait": (1, 8, 1), "trail_distance_pts": (40, 300, 20)}},
    {"id": "united_rsi_scalp_nvda", "engine": "rsi_scalp", "symbol": "NVDA", "tf": "M15", "lot": 50.0,
     "enable_key": "EnableRSIScalpingNVDA", "lot_key": "LOT_RS_NVDA",
     "defaults": {"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, "tf": "M15"},
     "opt": {"rsi_period": (6, 21, 1), "bars_to_wait": (1, 8, 1), "trail_distance_pts": (50, 500, 25)}},
    {"id": "united_rsi_scalp_tsla", "engine": "rsi_scalp", "symbol": "TSLA", "tf": "H1", "lot": 5.0,
     "enable_key": "EnableRSIScalpingTSLA", "lot_key": "LOT_RS_TSLA",
     "defaults": {"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, "tf": "H1"},
     "opt": {"rsi_period": (6, 21, 1), "bars_to_wait": (1, 6, 1), "trail_distance_pts": (100, 1000, 50)}},
    {"id": "united_rsi_scalp_xau", "engine": "rsi_scalp", "symbol": "XAUUSD", "tf": "H1", "lot": 0.02,
     "enable_key": "EnableRSIScalpingXAUUSD", "lot_key": "LOT_RS_XAUUSD",
     "defaults": {"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, "tf": "H1"},
     "opt": {"rsi_period": (6, 21, 1), "rsi_overbought": (55, 85, 3), "rsi_oversold": (40, 75, 3),
             "bars_to_wait": (1, 4, 1), "trail_distance_pts": (20, 150, 10)}},
    {"id": "united_rsi_asian_eur", "engine": "rsi_asian", "symbol": "EURUSD", "tf": "M15", "lot": 0.04,
     "enable_key": "EnableRSIReversalAsianEURUSD", "lot_key": "LOT_RRA_EURUSD",
     "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": "united_rsi_asian_aud", "engine": "rsi_asian", "symbol": "AUDUSD", "tf": "M15", "lot": 0.03,
     "enable_key": "EnableRSIReversalAsianAUDUSD", "lot_key": "LOT_RRA_AUDUSD",
     "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": 48,
                  "close_outside_session": True},
     "opt": {"overbought_level": (55, 80, 5), "oversold_level": (15, 45, 5)}},
    {"id": "united_st_xau", "engine": "simple_trendline", "symbol": "XAUUSD", "tf": "H1", "lot": 0.03,
     "enable_key": "EnableSimpleTrendlineXAUUSD", "lot_key": "LOT_ST_XAUUSD",
     "defaults": {"signal_tf": "H1", "higher_tf": "M10", "ma_period": 65, "ma_method": "ema",
                  "htf_bars_to_scan": 500, "touch_tolerance_pts": 220, "break_buffer_pts": 110},
     "opt": {"ma_period": (40, 120, 10), "touch_tolerance_pts": (100, 350, 25),
             "break_buffer_pts": (50, 200, 15)}},
    {"id": "united_st_ger40", "engine": "simple_trendline", "symbol": "GER40", "tf": "M15", "lot": 0.04,
     "enable_key": "EnableSimpleTrendlineGER40", "lot_key": "LOT_ST_GER40",
     "defaults": {"signal_tf": "M15", "higher_tf": "M15", "ma_period": 65, "ma_method": "lwma",
                  "htf_bars_to_scan": 1200, "touch_tolerance_pts": 100, "break_buffer_pts": 80},
     "opt": {"ma_period": (40, 120, 10), "touch_tolerance_pts": (50, 200, 15)}},
    {"id": "united_rsi_secret", "engine": "rsi_secret", "symbol": "XAUUSD", "tf": "M30", "lot": 0.07,
     "enable_key": "EnableRSISecretSauce", "lot_key": "LOT_RSS_SecretSauce",
     "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)}},
    {"id": "united_usdjpy", "engine": "usdjpy_buster", "symbol": "USDJPY", "tf": "M20", "lot": 0.09,
     "enable_key": "EnableUSDJPYBuster", "lot_key": "LOT_UB_USDJPY",
     "defaults": {"range_start_hour": 3, "range_end_hour": 6, "close_hour": 18,
                  "min_range_pts": 15, "order_buffer_pts": 4.75, "first_trade_only": False,
                  "allow_long": True, "allow_short": True, "use_take_profit": False},
     "opt": {"min_range_pts": (8, 40, 4), "order_buffer_pts": (2, 12, 1)}},
]

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