"""
OPTIMIZED SETTINGS FOR LONG-TERM TRADING
=========================================
Based on 5-year backtest analysis that revealed 248% max drawdown.
These settings prioritize survival through major crashes over maximum profit.

Key changes:
1. Much wider averaging distances (cover 50%+ drops)
2. Lower lot multipliers (1.2x instead of 1.5x cumulative)
3. Lower risk percent (0.5% instead of 1.5%)
4. Capped averaging levels (8 max)
"""

# =============================================================================
# TRADING PAIR
# =============================================================================
SYMBOL = "BTCUSD"

# =============================================================================
# ACCOUNT & RISK MANAGEMENT - REDUCED RISK
# =============================================================================
INITIAL_BALANCE = 10000.0
RISK_PERCENT = 0.5                      # Reduced from 1.5% to 0.5%
                                        # With martingale, lower is safer

# =============================================================================
# STRATEGY PARAMETERS - WIDER SPACING
# =============================================================================
BASE_MULTIPLIER = 6.0                   # Increased from 4.0 to 6.0
                                        # Wider TP = fewer trades but safer

AGGRESSION_LEVEL = 20                   # Reduced from 50 to 20
                                        # Less aggressive lot increases

FIRST_DISTANCE_MULTIPLIER = 2.0         # Increased from 1.0 to 2.0
                                        # First averaging order further away

# =============================================================================
# BIDIRECTIONAL TRADING
# =============================================================================
ENABLE_LONGS = True
ENABLE_SHORTS = False

GRID_SPACING = 1000.0                   # Increased from 500 to 1000
                                        # More space between threads

MAX_CONCURRENT_THREADS = 1

# =============================================================================
# INDIVIDUAL TP MODE
# =============================================================================
INDIVIDUAL_TP_ENABLED = False
INDIVIDUAL_TP_DISTANCE = 500.0          # Increased from 300 to 500

# =============================================================================
# DRAWDOWN HEDGE - ENABLED FOR PROTECTION
# =============================================================================
HEDGE_ENABLED = True                    # Enable hedging for crash protection
HEDGE_TRIGGER_LEVEL = 4                 # Start hedging earlier (was 5)
HEDGE_CLOSE_PROFIT = 200.0
HEDGE_LOT_PERCENT = 75                  # Larger hedge for better protection

# =============================================================================
# WIDE SPACING MARTINGALE LEVELS
# =============================================================================
# Designed to cover 50%+ price drops
# For BTC at $80k: 50% drop = $40k range needed

CUSTOM_LEVELS = [
    1.0, 2.0, 4.0, 7.0, 12.0,          # Levels 1-5: Wider initial spacing
    20.0, 32.0, 50.0,                   # Levels 6-8: Very wide deep levels
]
# With base distance ~$400, level 8 = $20,000 from entry
# This covers a 25% drop - need 2+ threads for larger drops

# CONSERVATIVE multipliers - caps total exposure
CUSTOM_MULTIPLIERS = [
    1.2, 1.2, 1.2, 1.2, 1.2,          # Levels 1-5: 1.2x cumulative (up to 2.5x)
    1.15, 1.15, 1.15,                  # Levels 6-8: 1.15x cumulative (up to ~3.4x)
]
# Level 8 lot = base * 1.2^5 * 1.15^3 = 3.79x base (not 113x!)

USE_CUMULATIVE_MULTIPLIERS = True

MAX_SPREAD = 150.0                      # Allow slightly wider spreads

# =============================================================================
# AVERAGING CONFIGURATION - HARD LIMIT
# =============================================================================
MAX_AVERAGING_LEVELS = 8                # Reduced from 50 to 8
                                        # Accept loss after 8 levels

REENTRY_ENABLED = True
TP_TOLERANCE_PIPS = 0.5

# =============================================================================
# LOT SIZE CONSTRAINTS
# =============================================================================
MIN_LOT_SIZE = 0.001
MAX_LOT_SIZE = 5.0                      # Reduced from 10.0 to 5.0
LOT_STEP = 0.001

# =============================================================================
# EXECUTION COSTS
# =============================================================================
COMMISSION_PERCENT = 0.05
SLIPPAGE_PIPS = 1                       # Added slippage for realism

# =============================================================================
# BACKTESTING DATA
# =============================================================================
SAMPLE_DATA_CANDLES = 5000
SAMPLE_START_PRICE = 50000.0
SAMPLE_VOLATILITY = 0.015

DATA_FILE_CSV = ""
DATA_FILE_JSON = ""

CSV_TIMESTAMP_COL = "timestamp"
CSV_OPEN_COL = "open"
CSV_HIGH_COL = "high"
CSV_LOW_COL = "low"
CSV_CLOSE_COL = "close"
CSV_VOLUME_COL = "volume"

# =============================================================================
# TICK DATA SETTINGS
# =============================================================================
TICK_DATA_FILE = "BTCUSD (2).csv"
TICK_MAX_ROWS = None
TICK_SKIP_ROWS = 0
TICK_REPORT_INTERVAL = 10000

# =============================================================================
# BACKTEST OPTIONS
# =============================================================================
USE_TICK_DATA = False
TICKS_PER_CANDLE = 4

# =============================================================================
# LIVE TRADING
# =============================================================================
EXCHANGE = "simulated"
TESTNET = True
POLL_INTERVAL = 1.0

# =============================================================================
# LOGGING
# =============================================================================
LOG_LEVEL = "INFO"
LOG_FILE = "trading_bot.log"
LOG_TO_CONSOLE = True
LOG_TO_FILE = True
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"

# =============================================================================
# MAGIC NUMBER
# =============================================================================
BASE_MAGIC = 100000

# =============================================================================
# CRYPTO PAIR SPECIFICATIONS
# =============================================================================
CRYPTO_PAIRS = {
    "BTCUSD": {
        "pip_size": 0.1,
        "min_lot": 0.001,
        "max_lot": 100.0,
        "lot_step": 0.001,
        "decimals": 1
    },
    "BTCUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.001,
        "max_lot": 100.0,
        "lot_step": 0.001,
        "decimals": 2
    },
    "ETHUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.01,
        "max_lot": 1000.0,
        "lot_step": 0.01,
        "decimals": 2
    },
    "BNBUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.01,
        "max_lot": 10000.0,
        "lot_step": 0.01,
        "decimals": 2
    },
    "XRPUSDT": {
        "pip_size": 0.0001,
        "min_lot": 1.0,
        "max_lot": 1000000.0,
        "lot_step": 1.0,
        "decimals": 4
    },
    "SOLUSDT": {
        "pip_size": 0.01,
        "min_lot": 0.1,
        "max_lot": 100000.0,
        "lot_step": 0.1,
        "decimals": 2
    },
    "DOGEUSDT": {
        "pip_size": 0.00001,
        "min_lot": 1.0,
        "max_lot": 10000000.0,
        "lot_step": 1.0,
        "decimals": 5
    }
}

DEFAULT_PAIR_CONFIG = {
    "pip_size": 0.01,
    "min_lot": 0.001,
    "max_lot": 100.0,
    "lot_step": 0.001,
    "decimals": 2
}

"""
EXPECTED PERFORMANCE COMPARISON:

Original Settings:
- Risk: 1.5%
- Multiplier: 1.5x cumulative
- Level 12 lot: 113x base
- Max DD: 248%+ (account destruction)

Optimized Settings:
- Risk: 0.5%
- Multiplier: 1.2x cumulative
- Level 8 lot: 3.79x base
- Expected Max DD: ~30-50% (survivable)
- Expected Return: Lower but sustainable

Trade-off: Less profit in bull markets, but SURVIVAL through crashes.
"""
