Skip to the page

EUR/USD RSI Oversold/Overbought XGBoost Reversal

Market not recorded, published 22 Sep 2026 by @hidden-kernel-596. Community id 332.

Not re-run yet. A new strategy gets its first daily re-run at the next scoring run.

Out-of-sample result at publish, frozen

+18.72%

TradesWin rateProfit factorMax drawdown
6873.5%2.354.11%

A strategy can be published only when this test made money, so this number was chosen to be positive. The daily re-run is the fairer read.

Daily re-run not scored yet

-

Not scored yet. A new strategy gets its first daily re-run at the next scoring run.

Description as published by @hidden-kernel-596

Maximise Sharpe ratio on EUR/USD 15-min data. XGBClassifier trained on a single 70/30 train-test holdout split. RSI(14) oversold/overbought signals are the primary features, supplemented by MACD, Bollinger Band %B, Stochastic, ATR-normalised volatility, price momentum, and candle structure. Regularisation (gamma, alpha, lambda, min_child_weight) and moderate depth (4) are chosen to reduce overfitting and improve out-of-sample Sharpe.

Run it yourself

Trains this exact code on fresh Market not recorded data and deploys it as your own model. Nothing is generated.

Agents: POST /api/v1/fork/332MCP: one_shot(community_id=332)
strategy.py
# ╔══════════════════════════════════════════════════════════════╗
# ║                  STRATEGY REQUEST LOG                       ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated        : 2026-09-22 07:32:22
# Model            : XGBoost
# Task             : classification  (up / down / flat)
# Feature Eng.     : Buy when RSI(14) < 30, sell when RSI(14) > 70. Exit on reverse. + Auto-add features: ON
# Signal / Entry   : —
# Optimization     : —
# Risk Mgmt        : —
# Risk Filter      : —
# ══════════════════════════════════════════════════════════════

# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd

DATA_PATH = "data/ohlc/EURUSD_15min.parquet"
START_DATE = "2026-08-13"
END_DATE   = "2026-09-22"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pct'
STOP_LOSS = None
TAKE_PROFIT = None

# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
    # --- RSI(14) ---
    delta = close.diff()
    gain = delta.clip(lower=0)
    loss = -delta.clip(upper=0)
    avg_gain = gain.ewm(com=13, min_periods=14).mean()
    avg_loss = loss.ewm(com=13, min_periods=14).mean()
    rs = avg_gain / (avg_loss + 1e-10)
    df['rsi_14'] = 100.0 - (100.0 / (1.0 + rs))

    # --- RSI overbought / oversold binary signals ---
    df['rsi_oversold'] = np.where(df['rsi_14'] < 30, 1, 0)
    df['rsi_overbought'] = np.where(df['rsi_14'] > 70, 1, 0)

    # --- RSI distance from extremes ---
    df['rsi_dist_30'] = df['rsi_14'] - 30.0
    df['rsi_dist_70'] = df['rsi_14'] - 70.0
    df['rsi_dist_50'] = df['rsi_14'] - 50.0

    # --- RSI(7) for shorter-term momentum ---
    gain7 = gain.ewm(com=6, min_periods=7).mean()
    loss7 = loss.ewm(com=6, min_periods=7).mean()
    rs7 = gain7 / (loss7 + 1e-10)
    df['rsi_7'] = 100.0 - (100.0 / (1.0 + rs7))

    # --- RSI(21) for longer-term context ---
    gain21 = gain.ewm(com=20, min_periods=21).mean()
    loss21 = loss.ewm(com=20, min_periods=21).mean()
    rs21 = gain21 / (loss21 + 1e-10)
    df['rsi_21'] = 100.0 - (100.0 / (1.0 + rs21))

    # --- RSI momentum: difference between short and long RSI ---
    df['rsi_momentum'] = df['rsi_7'] - df['rsi_21']

    # --- RSI slope (1-bar change) ---
    df['rsi_slope'] = df['rsi_14'].diff(1)
    df['rsi_slope_3'] = df['rsi_14'].diff(3)

    # --- MACD ---
    ema12 = close.ewm(span=12, min_periods=12).mean()
    ema26 = close.ewm(span=26, min_periods=26).mean()
    df['macd_line'] = ema12 - ema26
    df['macd_signal'] = df['macd_line'].ewm(span=9, min_periods=9).mean()
    df['macd_hist'] = df['macd_line'] - df['macd_signal']
    df['macd_hist_slope'] = df['macd_hist'].diff(1)

    # --- Bollinger Bands (20, 2) ---
    sma20 = close.rolling(20).mean()
    std20 = close.rolling(20).std()
    bb_upper = sma20 + 2.0 * std20
    bb_lower = sma20 - 2.0 * std20
    bb_width = bb_upper - bb_lower
    df['bb_pct_b'] = np.where(bb_width > 0, (close - bb_lower) / bb_width, 0.5)
    df['bb_width_norm'] = np.where(sma20 > 0, bb_width / sma20, 0.0)

    # --- ATR(14) and Normalised ATR ---
    tr = pd.concat([
        high - low,
        (high - close.shift(1)).abs(),
        (low - close.shift(1)).abs()
    ], axis=1).max(axis=1)
    df['atr_14'] = tr.ewm(com=13, min_periods=14).mean()
    df['natr_14'] = np.where(close > 0, df['atr_14'] / close, 0.0)

    # --- Price momentum / returns ---
    df['ret_1'] = close.pct_change(1)
    df['ret_3'] = close.pct_change(3)
    df['ret_8'] = close.pct_change(8)
    df['ret_16'] = close.pct_change(16)

    # --- Candle body and shadow features ---
    df['body'] = (close - open_).abs()
    df['upper_shadow'] = high - pd.concat([close, open_], axis=1).max(axis=1)
    df['lower_shadow'] = pd.concat([close, open_], axis=1).min(axis=1) - low
    df['body_ratio'] = np.where(
        (high - low) > 1e-10,
        df['body'] / (high - low),
        0.0
    )
    df['close_is_up'] = np.where(close > open_, 1, 0)

    # --- SMA trend features ---
    sma50 = close.rolling(50).mean()
    sma100 = close.rolling(100).mean()
    df['close_vs_sma50'] = np.where(sma50 > 0, (close - sma50) / sma50, 0.0)
    df['close_vs_sma100'] = np.where(sma100 > 0, (close - sma100) / sma100, 0.0)
    df['sma50_vs_sma100'] = np.where(sma100 > 0, (sma50 - sma100) / sma100, 0.0)

    # --- EMA(9) proximity ---
    ema9 = close.ewm(span=9, min_periods=9).mean()
    df['close_vs_ema9'] = np.where(ema9 > 0, (close - ema9) / ema9, 0.0)

    # --- Stochastic %K and %D (14,3) ---
    lowest_low_14 = low.rolling(14).min()
    highest_high_14 = high.rolling(14).max()
    stoch_range = highest_high_14 - lowest_low_14
    df['stoch_k'] = np.where(stoch_range > 1e-10, (close - lowest_low_14) / stoch_range * 100.0, 50.0)
    df['stoch_d'] = df['stoch_k'].rolling(3).mean()
    df['stoch_kd_diff'] = df['stoch_k'] - df['stoch_d']

    # --- Williams %R (14) ---
    df['williams_r'] = np.where(
        stoch_range > 1e-10,
        (highest_high_14 - close) / stoch_range * -100.0,
        -50.0
    )

    # --- Rolling volatility (std of returns) ---
    df['vol_8'] = df['ret_1'].rolling(8).std()
    df['vol_20'] = df['ret_1'].rolling(20).std()
    df['vol_ratio'] = np.where(df['vol_20'] > 1e-10, df['vol_8'] / df['vol_20'], 1.0)

    # --- High-Low range normalised ---
    df['hl_range_norm'] = np.where(close > 0, (high - low) / close, 0.0)

    # --- Rolling max / min drawdown over 8 bars ---
    df['roll_max_8'] = high.rolling(8).max()
    df['roll_min_8'] = low.rolling(8).min()
    df['price_pos_8'] = np.where(
        (df['roll_max_8'] - df['roll_min_8']) > 1e-10,
        (close - df['roll_min_8']) / (df['roll_max_8'] - df['roll_min_8']),
        0.5
    )

    # --- RSI divergence proxy: RSI slope vs price slope ---
    price_slope_3 = close.diff(3)
    df['rsi_price_div'] = np.where(
        (df['rsi_slope_3'] < 0) & (price_slope_3 > 0), -1,
        np.where((df['rsi_slope_3'] > 0) & (price_slope_3 < 0), 1, 0)
    )

    # --- Hour-of-day (cyclical encoding for session context) ---
    if hasattr(df.index, 'hour'):
        hour = df.index.hour
        df['hour_sin'] = np.sin(2 * np.pi * hour / 24.0)
        df['hour_cos'] = np.cos(2 * np.pi * hour / 24.0)
    else:
        df['hour_sin'] = 0.0
        df['hour_cos'] = 1.0

    # --- Fill NaN from warm-up periods ---
    df = df.bfill().ffill()
    return df


# SECTION 2 — STRATEGY CONFIG
def strategy_config():
    return {
        "title": "EUR/USD RSI Oversold/Overbought XGBoost Reversal",
        "model_type": "XGBClassifier",
        "model_params": {
            "n_estimators": 400,
            "max_depth": 4,
            "learning_rate": 0.04,
            "subsample": 0.75,
            "colsample_bytree": 0.70,
            "min_child_weight": 5,
            "gamma": 0.15,
            "reg_alpha": 0.1,
            "reg_lambda": 1.5,
            "scale_pos_weight": 1.0,
            "objective": "binary:logistic",
            "n_jobs": -1,
            "random_state": 42,
        },
        "signal_threshold": 0.55,
        "direction": "both",
        "stop_loss": None,
        "take_profit": None,
        "cooldown": 0,
        "max_positions": 1,
        "on_opposite": "reverse",
        "session_filter": [6, 18],
        "min_atr": None,
        "trend_filter": None,
        "target_horizon": 4,
        "objective": (
            "Maximise Sharpe ratio on EUR/USD 15-min data. "
            "XGBClassifier trained on a single 70/30 train-test holdout split. "
            "RSI(14) oversold/overbought signals are the primary features, "
            "supplemented by MACD, Bollinger Band %B, Stochastic, ATR-normalised "
            "volatility, price momentum, and candle structure. "
            "Regularisation (gamma, alpha, lambda, min_child_weight) and moderate "
            "depth (4) are chosen to reduce overfitting and improve out-of-sample "
            "Sharpe. Session filter restricts trading to London/NY overlap hours."
        ),
        "notes": (
            "Model: XGBClassifier, one holdout split (TRAIN_SPLIT=0.7). "
            "Entry threshold 0.55 requires moderate confidence, reducing noise trades. "
            "on_opposite=reverse flips position immediately on counter-signal, "
            "consistent with a mean-reversion RSI strategy. "
            "target_horizon=4 bars (1 hour) aligns with typical RSI mean-reversion speed. "
            "Round-trip cost of 2e-5 is handled by the framework's backtest engine."
        ),
    }

# ---------------------------------------------------------------
# AUX_FEEDS - written by the strategy BUILDER, not by the model.
# Last module-level statement on purpose: module execution is
# last-write-wins, so this is the value run_strategy() sees no matter
# what appears above. Do not move it, and add nothing after it.
# ---------------------------------------------------------------
AUX_FEEDS = []

More strategies

Every published strategy on Community
QuantifyMe
DocsAgentsCommunityPricing
Sign in