Browse AI-generated trading strategies shared by the community. Fork, learn, and build on each other's work.
| Score▼ | Strategy | Author | Win Rate▼ | Return▼ | PF▼ | MDD▼ | Trades▼ | Actions | ||
|---|---|---|---|---|---|---|---|---|---|---|
|
🥇
|
EMA Cross 50/200 + ATR Momentum (XGBoost)
Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min data. EMA 50/200 cross provides the primary trend regime filter. ATR 14 gate…
|
D
@delta-atlas-858
|
EURUSD | 15min | 48.5%66.7% | +8.52%+2.32% | 2.419.14 | 0.83%0.83% | 6818 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-05 10:27:10
# Model : XGBoost
# Feature Eng. : EMA (50,200), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-23"
END_DATE = "2026-04-23"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── EMA 50 and EMA 200 ──────────────────────────────────────────────────
ema_50 = close.ewm(span=50, adjust=False).mean()
ema_200 = close.ewm(span=200, adjust=False).mean()
df["ema_50"] = ema_50
df["ema_200"] = ema_200
df["dm_ema_50"] = (close - ema_50) / ema_50
df["dm_ema_200"] = (close - ema_200) / ema_200
# EMA cross signal: positive when fast > slow
df["ema_cross"] = ema_50 - ema_200
df["ema_cross_norm"] = df["ema_cross"] / ema_200
# Cross direction change (momentum of the spread)
df["ema_cross_delta"] = df["ema_cross"].diff(1)
df["ema_cross_accel"] = df["ema_cross_delta"].diff(1)
# ── ATR 14 ──────────────────────────────────────────────────────────────
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(span=14, adjust=False).mean()
df["atr"] = atr
df["natr"] = atr / close
# ── Price momentum features ─────────────────────────────────────────────
for lag in [1, 2, 4, 8, 16]:
df[f"ret_{lag}"] = close.pct_change(lag)
# ── Volatility regime ───────────────────────────────────────────────────
df["atr_ratio"] = atr / atr.rolling(50).mean() # ATR vs its own MA
df["natr_ma20"] = df["natr"].rolling(20).mean()
# ── RSI 14 ──────────────────────────────────────────────────────────────
delta = close.diff(1)
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_g = gain.ewm(span=14, adjust=False).mean()
avg_l = loss.ewm(span=14, adjust=False).mean()
rs = avg_g / avg_l.replace(0, np.nan)
df["rsi_14"] = 100 - (100 / (1 + rs))
df["rsi_delta"] = df["rsi_14"].diff(1)
# ── MACD (12/26/9) ──────────────────────────────────────────────────────
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd = ema_12 - ema_26
signal = macd.ewm(span=9, adjust=False).mean()
df["macd"] = macd
df["macd_signal"] = signal
df["macd_hist"] = macd - signal
df["macd_hist_delta"] = df["macd_hist"].diff(1)
# ── Bollinger Bands (20, 2σ) ─────────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std()
bb_up = bb_mid + 2 * bb_std
bb_lo = bb_mid - 2 * bb_std
df["bb_pos"] = (close - bb_lo) / (bb_up - bb_lo).replace(0, np.nan)
df["bb_width"] = (bb_up - bb_lo) / bb_mid
# ── Stochastic %K / %D (14, 3) ──────────────────────────────────────────
low14 = low.rolling(14).min()
high14 = high.rolling(14).max()
stoch_k = 100 * (close - low14) / (high14 - low14).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_kd"] = stoch_k - stoch_d
# ── Volume / body / wick features ───────────────────────────────────────
body = (close - open_).abs()
candle = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle
df["bull_candle"] = np.where(close > open_, 1, 0)
# ── Rolling z-score of close vs SMA 50 ──────────────────────────────────
sma_50 = close.rolling(50).mean()
sma_50_std = close.rolling(50).std()
df["zscore_50"] = (close - sma_50) / sma_50_std.replace(0, np.nan)
# ── High/Low breakout flags ──────────────────────────────────────────────
df["high_20_break"] = np.where(close > high.rolling(20).max().shift(1), 1, 0)
df["low_20_break"] = np.where(close < low.rolling(20).min().shift(1), 1, 0)
# ── Time-of-day features (cyclical encoding) ─────────────────────────────
if hasattr(df.index, 'hour'):
hour = df.index.hour + df.index.minute / 60.0
df["hour_sin"] = np.sin(2 * np.pi * hour / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * hour / 24.0)
# ── Fill NaN from indicator warm-up ─────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EMA Cross 50/200 + ATR Momentum (XGBoost)",
"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": 3,
"gamma": 0.15,
"reg_alpha": 0.10,
"reg_lambda": 1.50,
"objective": "binary:logistic",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min data. "
"EMA 50/200 cross provides the primary trend regime filter. "
"ATR 14 gates entries by volatility (min_atr avoids dead-market noise). "
"XGBoost chosen for its ability to capture non-linear feature interactions. "
"Conservative depth=4 and regularisation (alpha/lambda) prevent overfitting "
"on the relatively short 1-year window. 2:1 reward/risk (SL=0.5%, TP=1.0%) "
"ensures positive expectancy even at modest hit-rates. Session filter 06-20 UTC "
"keeps the strategy in liquid London/NY hours only."
),
"notes": (
"Feature set combines trend (EMA cross, z-score), momentum (RSI, MACD, returns), "
"volatility (ATR ratio, BB width), and price structure (body/wick ratios, "
"stochastic). Cyclical hour encoding captures intraday seasonality without "
"introducing lookahead. bfill().ffill() handles EMA warm-up NaNs gracefully."
),
}
|
||||||||||
|
🥈
|
EMA Cross 9/21 + RSI14 Gradient Boost Scalper
Maximize risk-adjusted return (Sharpe/Calmar) using a GradientBoostingClassifier with EMA 9/21 crossover as the primary signal source and RS…
|
P
@pivot_kid
|
EURUSD | 15min | 43.3%88.9% | +11.79%+1.42% | 2.924.10 | 0.83%0.83% | 679 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:37:57
# Model : Gradient Boosting
# Feature Eng. : EMA (9,21), RSI 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA 9 and EMA 21 (required) ---
ema_9 = close.ewm(span=9, adjust=False).mean()
ema_21 = close.ewm(span=21, adjust=False).mean()
df["ema_9"] = ema_9
df["ema_21"] = ema_21
df["dm_ema_9"] = (close - ema_9) / ema_9
df["dm_ema_21"] = (close - ema_21) / ema_21
# EMA crossover signal: positive when fast > slow
df["ema_cross"] = ema_9 - ema_21
# Crossover direction change (sign flip)
df["ema_cross_signal"] = np.sign(df["ema_cross"])
df["ema_cross_prev"] = df["ema_cross_signal"].shift(1)
df["ema_cross_flip"] = (df["ema_cross_signal"] != df["ema_cross_prev"]).astype(float)
# --- RSI 14 (required) ---
delta = close.diff()
gain = delta.clip(lower=0)
loss = -delta.clip(upper=0)
avg_gain = gain.ewm(com=13, adjust=False).mean()
avg_loss = loss.ewm(com=13, adjust=False).mean()
rs = avg_gain / (avg_loss + 1e-10)
rsi_14 = 100 - (100 / (1 + rs))
df["rsi_14"] = rsi_14
# RSI normalised to [-1, 1] range
df["rsi_norm"] = (rsi_14 - 50) / 50
# RSI overbought/oversold flags
df["rsi_ob"] = np.where(rsi_14 > 70, 1.0, 0.0)
df["rsi_os"] = np.where(rsi_14 < 30, 1.0, 0.0)
# --- Additional momentum and volatility features ---
# EMA 50 for trend context
ema_50 = close.ewm(span=50, adjust=False).mean()
df["ema_50"] = ema_50
df["dm_ema_50"] = (close - ema_50) / ema_50
# Price momentum: rate of change over multiple horizons
df["roc_4"] = close.pct_change(4)
df["roc_8"] = close.pct_change(8)
df["roc_16"] = close.pct_change(16)
# ATR (Average True Range) for volatility
tr = pd.concat([
high - low,
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs()
], axis=1).max(axis=1)
atr_14 = tr.ewm(span=14, adjust=False).mean()
df["atr_14"] = atr_14
# Normalised ATR
df["natr_14"] = atr_14 / close
# Bollinger Bands (20-period, 2 std)
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std()
bb_upper = bb_mid + 2 * bb_std
bb_lower = bb_mid - 2 * bb_std
df["bb_pct"] = (close - bb_lower) / (bb_upper - bb_lower + 1e-10)
df["bb_width"] = (bb_upper - bb_lower) / (bb_mid + 1e-10)
# BB squeeze: narrow bands signal potential breakout
df["bb_squeeze"] = np.where(df["bb_width"] < df["bb_width"].rolling(50).mean(), 1.0, 0.0)
# MACD-like: difference between two EMAs
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema_12 - ema_26
macd_signal = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line / (close + 1e-10)
df["macd_signal"] = macd_signal / (close + 1e-10)
df["macd_hist"] = (macd_line - macd_signal) / (close + 1e-10)
df["macd_cross"] = np.sign(macd_line - macd_signal)
# Stochastic oscillator (14-period)
lowest_low = low.rolling(14).min()
highest_high = high.rolling(14).max()
stoch_k = 100 * (close - lowest_low) / (highest_high - lowest_low + 1e-10)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_diff"] = stoch_k - stoch_d
# Volume of price movement (candle body and shadows)
df["body"] = (close - open_).abs() / (atr_14 + 1e-10)
df["upper_shadow"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / (atr_14 + 1e-10)
df["lower_shadow"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / (atr_14 + 1e-10)
df["candle_dir"] = np.sign(close - open_)
# Rolling volatility (realised vol over 20 bars)
log_ret = np.log(close / close.shift(1))
df["realvol_20"] = log_ret.rolling(20).std()
# Close relative to recent high/low channel (20-bar)
roll_high_20 = high.rolling(20).max()
roll_low_20 = low.rolling(20).min()
df["chan_pct_20"] = (close - roll_low_20) / (roll_high_20 - roll_low_20 + 1e-10)
# Lagged RSI and EMA cross for temporal context
df["rsi_14_lag1"] = rsi_14.shift(1)
df["rsi_14_lag2"] = rsi_14.shift(2)
df["ema_cross_lag1"] = df["ema_cross"].shift(1)
df["ema_cross_lag2"] = df["ema_cross"].shift(2)
df["macd_hist_lag1"] = df["macd_hist"].shift(1)
# RSI momentum: change in RSI
df["rsi_delta_1"] = rsi_14.diff(1)
df["rsi_delta_4"] = rsi_14.diff(4)
# EMA9 slope (normalised)
df["ema9_slope"] = ema_9.diff(3) / (ema_9.shift(3) + 1e-10)
df["ema21_slope"] = ema_21.diff(3) / (ema_21.shift(3) + 1e-10)
# Interaction: RSI * EMA cross direction
df["rsi_ema_cross_interact"] = df["rsi_norm"] * df["ema_cross_signal"]
# Fill NaN from indicator warm-up
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EMA Cross 9/21 + RSI14 Gradient Boost Scalper",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.8,
"min_samples_leaf": 20,
"min_samples_split": 40,
"max_features": "sqrt",
"n_iter_no_change": 30,
"validation_fraction": 0.1,
"tol": 1e-4,
},
"signal_threshold": 0.56,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [7, 17],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) using a GradientBoostingClassifier "
"with EMA 9/21 crossover as the primary signal source and RSI 14 as confirmation. "
"Deep feature set includes MACD, Bollinger Bands, Stochastic, ATR normalisation, "
"candle structure, lagged features and RSI/EMA interaction terms. "
"Gradient boosting chosen for its ability to capture non-linear interactions between "
"trend, momentum and volatility features without overfitting when regularised via "
"subsample, max_features, and early stopping. Threshold 0.56 filters marginal signals. "
"Session filter [7,17] focuses on London/NY overlap for highest EUR/USD liquidity. "
"SL 0.5% / TP 1.0% gives 1:2 risk-reward aligned with scalper momentum targets. "
"Reverse on opposite signal to stay in sync with fast EMA crossover momentum."
),
"notes": (
"EMA 9/21 cross captures short-term momentum shifts typical of active EUR/USD sessions. "
"RSI 14 filters entries in extreme overbought/oversold conditions. "
"NATR min_atr filter removes flat/low-vol periods. "
"Trend filter (SMA 50) ensures longs only above and shorts only below the medium-term trend. "
"n_iter_no_change=30 provides early stopping to prevent overfitting on the training split. "
"400 estimators with depth 4 and lr 0.04 balance bias-variance tradeoff for intraday data."
),
}
|
||||||||||
|
🥉
|
EUR/USD SMA Trend + Multi-Indicator GBM Scalper
Maximise risk-adjusted return (Sharpe / Calmar). GradientBoostingClassifier chosen for its strong performance on tabular financial data with…
|
S
@still-lynx-704
|
EURUSD | 15min | 39.7%63.2% | +5.29%+1.98% | 1.626.43 | 1.82%1.82% | 7319 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:35:43
# Model : Gradient Boosting
# Feature Eng. : SMA (20,50,200) + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA core features (required) ──────────────────────────────────────
for period in [20, 50, 200]:
sma = close.rolling(period).mean()
df[f"sma_{period}"] = sma
df[f"dm_sma_{period}"] = (close - sma) / sma
# ── SMA slope (momentum of the moving average itself) ──────────────────
for period in [20, 50, 200]:
df[f"sma_{period}_slope"] = df[f"sma_{period}"].diff(5) / df[f"sma_{period}"].shift(5)
# ── SMA crossover signals ──────────────────────────────────────────────
df["sma_20_50_cross"] = df["sma_20"] - df["sma_50"]
df["sma_50_200_cross"] = df["sma_50"] - df["sma_200"]
df["sma_20_200_cross"] = df["sma_20"] - df["sma_200"]
# Sign of crossover difference (trend direction)
df["trend_20_50"] = np.where(df["sma_20_50_cross"] > 0, 1, -1)
df["trend_50_200"] = np.where(df["sma_50_200_cross"] > 0, 1, -1)
# ── Price momentum ────────────────────────────────────────────────────
for lag in [1, 4, 8, 16, 32]:
df[f"return_{lag}"] = close.pct_change(lag)
# ── Volatility features ───────────────────────────────────────────────
# True Range
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
for atr_period in [14, 50]:
atr = tr.rolling(atr_period).mean()
df[f"atr_{atr_period}"] = atr
df[f"natr_{atr_period}"] = atr / close
# Rolling realised volatility
log_ret = np.log(close / close.shift(1))
for vol_period in [20, 50]:
df[f"realvol_{vol_period}"] = log_ret.rolling(vol_period).std()
# ── Bollinger Bands (20, 2σ) ──────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std()
bb_upper = bb_mid + 2 * bb_std
bb_lower = bb_mid - 2 * bb_std
df["bb_width"] = (bb_upper - bb_lower) / bb_mid
df["bb_pct"] = (close - bb_lower) / (bb_upper - bb_lower + 1e-12)
df["bb_position"] = (close - bb_mid) / (bb_std + 1e-12)
# ── RSI (14) ──────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0).rolling(14).mean()
loss = (-delta.clip(upper=0)).rolling(14).mean()
rs = gain / (loss + 1e-12)
df["rsi_14"] = 100 - (100 / (1 + rs))
# RSI normalised to [-1, 1]
df["rsi_14_norm"] = (df["rsi_14"] - 50) / 50
# ── MACD (12, 26, 9) ─────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
signal_line = macd_line.ewm(span=9, adjust=False).mean()
df["macd"] = macd_line
df["macd_signal"] = signal_line
df["macd_hist"] = macd_line - signal_line
df["macd_hist_chg"] = df["macd_hist"].diff()
# Normalise MACD by price
df["macd_norm"] = df["macd"] / close
df["macd_hist_norm"] = df["macd_hist"] / close
# ── Stochastic Oscillator (14, 3) ─────────────────────────────────────
low14 = low.rolling(14).min()
high14 = high.rolling(14).max()
stoch_k = 100 * (close - low14) / (high14 - low14 + 1e-12)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_diff"] = stoch_k - stoch_d
# ── Rate-of-change ────────────────────────────────────────────────────
for roc_period in [5, 10, 20]:
df[f"roc_{roc_period}"] = (close - close.shift(roc_period)) / (close.shift(roc_period) + 1e-12)
# ── Candle body and wick features ─────────────────────────────────────
body = (close - open_).abs()
candle_rng = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_rng
df["upper_wick_ratio"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_rng
df["lower_wick_ratio"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_rng
df["candle_direction"] = np.where(close >= open_, 1, -1)
# ── Time-of-day features (hour) ───────────────────────────────────────
hour = df.index.hour
df["hour_sin"] = np.sin(2 * np.pi * hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * hour / 24)
# ── Lagged returns as features ────────────────────────────────────────
for lag in [1, 2, 3, 4]:
df[f"close_lag_{lag}"] = close.shift(lag)
df[f"ret_lag_{lag}"] = log_ret.shift(lag)
# ── Volume proxy: range-based ─────────────────────────────────────────
df["range_abs"] = high - low
df["range_norm"] = (high - low) / close
# ── High-Low channel position ─────────────────────────────────────────
for ch_period in [20, 50]:
ch_high = high.rolling(ch_period).max()
ch_low = low.rolling(ch_period).min()
df[f"channel_pos_{ch_period}"] = (close - ch_low) / (ch_high - ch_low + 1e-12)
# ── Fill NaN from warm-up ─────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD SMA Trend + Multi-Indicator GBM Scalper",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.75,
"max_features": "sqrt",
"min_samples_leaf": 20,
"min_samples_split": 40,
"validation_fraction": 0.1,
"n_iter_no_change": 30,
"tol": 1e-4,
"random_state": 42,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 18],
"min_atr": None,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximise risk-adjusted return (Sharpe / Calmar). "
"GradientBoostingClassifier chosen for its strong performance on "
"tabular financial data with moderate feature sets. "
"Shallow trees (max_depth=4) with high n_estimators and a low "
"learning_rate reduce overfitting. subsample=0.75 adds stochastic "
"regularisation. Early stopping via n_iter_no_change prevents "
"over-training on the validation split. "
"SL=0.5%, TP=1.0% gives a 1:2 risk-reward ratio, "
"targeting positive expectancy even at sub-60% accuracy. "
"Session filter (06-18 UTC) restricts trading to liquid hours "
"covering London and New York overlap for EUR/USD. "
"SMA-50 trend filter ensures trades align with the medium-term "
"trend, reducing counter-trend noise."
),
"notes": (
"Features include required SMA(20,50,200) distances and crossovers, "
"RSI-14, MACD histogram, Bollinger Band position, Stochastic, ATR, "
"realised volatility, rate-of-change, candle structure ratios, "
"channel position, lagged returns, and cyclical time encoding. "
"Target horizon of 4 bars (1 hour) on 15-min data balances "
"signal frequency with meaningful directional moves."
),
}
|
||||||||||
|
4.28
|
EUR/USD SMA+RSI+MACD+BB Momentum XGBoost
Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min. XGBoost with moderate depth and strong regularisation to avoid overfitting …
|
E
@echo-quanta-127
|
EURUSD | 15min | 42.7%69.6% | +5.42%+2.44% | 1.606.33 | 2.51%2.51% | 9623 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:04:57
# Model : XGBoost
# Feature Eng. : SMA (20,50,200), BB (20,2.0), RSI 14, MACD (12,26,9), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# EUR/USD Multi-Indicator Momentum + Mean-Reversion (XGBoost)
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA 20, 50, 200 + distance-from-close ──────────────────────────────
for period in [20, 50, 200]:
sma = close.rolling(period).mean()
df[f"sma_{period}"] = sma
df[f"dm_sma_{period}"] = (close - sma) / sma
# ── Bollinger Bands (20, 2) ─────────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std(ddof=0)
bb_upper = bb_mid + 2.0 * bb_std
bb_lower = bb_mid - 2.0 * bb_std
df["bb_mid"] = bb_mid
df["bb_upper"] = bb_upper
df["bb_lower"] = bb_lower
df["bb_width"] = (bb_upper - bb_lower) / bb_mid
bb_range = bb_upper - bb_lower
df["bb_pct"] = np.where(bb_range != 0, (close - bb_lower) / bb_range, 0.5)
# ── RSI 14 ──────────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(com=13, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(com=13, min_periods=14, adjust=False).mean()
rs = np.where(avg_loss != 0, avg_gain / avg_loss, 100.0)
df["rsi_14"] = 100.0 - (100.0 / (1.0 + rs))
# ── MACD (12, 26, 9) ────────────────────────────────────────────────────
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema_12 - ema_26
signal_line = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line
df["macd_signal"] = signal_line
df["macd_hist"] = macd_line - signal_line
# ── ATR 14 + NATR ───────────────────────────────────────────────────────
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(com=13, min_periods=14, adjust=False).mean()
df["atr_14"] = atr
df["natr"] = np.where(close != 0, atr / close, 0.0)
# ── Price momentum features ─────────────────────────────────────────────
for lag in [1, 2, 4, 8]:
df[f"ret_{lag}"] = close.pct_change(lag)
# ── Candle body / wick features ─────────────────────────────────────────
candle_range = (high - low).replace(0, np.nan)
df["body_ratio"] = np.where(
candle_range.notna(),
(close - open_).abs() / candle_range,
0.0
)
df["upper_wick"] = np.where(
candle_range.notna(),
(high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_range,
0.0
)
df["lower_wick"] = np.where(
candle_range.notna(),
(pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_range,
0.0
)
df["candle_dir"] = np.where(close >= open_, 1.0, -1.0)
# ── Volume-proxy: normalised range ─────────────────────────────────────
df["norm_range"] = (high - low) / close.rolling(20).mean()
# ── RSI derived ─────────────────────────────────────────────────────────
df["rsi_ob"] = np.where(df["rsi_14"] > 70, 1.0, 0.0)
df["rsi_os"] = np.where(df["rsi_14"] < 30, 1.0, 0.0)
df["rsi_mid_cross"] = np.where(df["rsi_14"] > 50, 1.0, -1.0)
# ── Trend alignment flags ───────────────────────────────────────────────
df["above_sma_20"] = np.where(close > df["sma_20"], 1.0, -1.0)
df["above_sma_50"] = np.where(close > df["sma_50"], 1.0, -1.0)
df["above_sma_200"] = np.where(close > df["sma_200"], 1.0, -1.0)
df["sma_20_50_cross"] = np.where(df["sma_20"] > df["sma_50"], 1.0, -1.0)
# ── MACD cross flag ─────────────────────────────────────────────────────
df["macd_cross"] = np.where(df["macd_line"] > df["macd_signal"], 1.0, -1.0)
# ── Bollinger squeeze ───────────────────────────────────────────────────
bb_width_ma = df["bb_width"].rolling(20).mean()
df["bb_squeeze"] = np.where(df["bb_width"] < bb_width_ma, 1.0, 0.0)
# ── Lagged RSI and MACD hist for regime detection ───────────────────────
df["rsi_14_lag1"] = df["rsi_14"].shift(1)
df["macd_hist_lag1"] = df["macd_hist"].shift(1)
df["rsi_slope"] = df["rsi_14"] - df["rsi_14_lag1"]
df["macd_hist_slope"] = df["macd_hist"] - df["macd_hist_lag1"]
# ── Rolling volatility ratio ─────────────────────────────────────────────
vol_short = close.pct_change().rolling(8).std()
vol_long = close.pct_change().rolling(32).std()
df["vol_ratio"] = np.where(vol_long != 0, vol_short / vol_long, 1.0)
# ── Hour-of-day (session proxy) ─────────────────────────────────────────
if hasattr(df.index, "hour"):
df["hour_sin"] = np.sin(2 * np.pi * df.index.hour / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * df.index.hour / 24.0)
else:
df["hour_sin"] = 0.0
df["hour_cos"] = 1.0
# ── Fill any NaN from warm-up ───────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD SMA+RSI+MACD+BB Momentum XGBoost",
"model_type": "XGBClassifier",
"model_params": {
"n_estimators": 600,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.8,
"colsample_bytree": 0.75,
"min_child_weight": 3,
"gamma": 0.1,
"reg_alpha": 0.05,
"reg_lambda": 1.5,
"objective": "binary:logistic",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.54,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min. "
"XGBoost with moderate depth and strong regularisation to avoid "
"overfitting on noisy FX data. 2:1 TP:SL ratio with trend filter "
"on SMA-50 to avoid counter-trend noise. Session filter 06-20 UTC "
"covers London + NY overlap for best liquidity."
),
"notes": (
"Features: SMA cross distances, RSI overbought/oversold flags, "
"MACD histogram slope, Bollinger squeeze, ATR normalisation, "
"candle body/wick ratios, momentum returns at 1/2/4/8 bars, "
"session encoding via hour sin/cos. "
"Threshold 0.54 keeps precision high while capturing enough trades. "
"Reverse on opposite signal maximises capital utilisation."
),
}
|
||||||||||
|
4.26
|
EUR/USD SMA Trend + Multi-Indicator XGBoost
Maximize risk-adjusted return (Sharpe/Calmar) via XGBoost with deep SMA-based trend features (20/50/200), momentum, volatility, RSI, MACD, B…
|
E
@elastic-moose-350
|
EURUSD | 15min | 53.6%71.4% | +5.89%+1.99% | 1.974.90 | 1.64%1.64% | 5614 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-05 10:44:36
# Model : XGBoost
# Feature Eng. : SMA (20,50,200) + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-23"
END_DATE = "2026-04-23"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA core features (required) ──────────────────────────────────────────
for p in [20, 50, 200]:
sma = close.rolling(p).mean()
df[f"sma_{p}"] = sma
df[f"dm_sma_{p}"] = (close - sma) / sma
# ── SMA cross-ratios ──────────────────────────────────────────────────────
df["sma_20_50_ratio"] = df["sma_20"] / df["sma_50"]
df["sma_50_200_ratio"] = df["sma_50"] / df["sma_200"]
df["sma_20_200_ratio"] = df["sma_20"] / df["sma_200"]
# ── SMA slope (rate of change of SMA over N bars) ─────────────────────────
for p in [20, 50, 200]:
df[f"sma_{p}_slope5"] = df[f"sma_{p}"].diff(5) / df[f"sma_{p}"].shift(5)
# ── Price momentum / returns ───────────────────────────────────────────────
for lag in [1, 2, 3, 4, 8, 16]:
df[f"ret_{lag}"] = close.pct_change(lag)
# ── Volatility (rolling std of returns) ───────────────────────────────────
ret1 = close.pct_change(1)
for w in [8, 20, 50]:
df[f"vol_std_{w}"] = ret1.rolling(w).std()
# ── ATR (manual) ──────────────────────────────────────────────────────────
tr = pd.concat([
high - low,
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs()
], axis=1).max(axis=1)
for w in [8, 14, 20]:
atr = tr.rolling(w).mean()
df[f"atr_{w}"] = atr
df[f"natr_{w}"] = atr / close
# ── RSI (manual) ──────────────────────────────────────────────────────────
for period in [7, 14, 21]:
delta = close.diff(1)
gain = delta.clip(lower=0).rolling(period).mean()
loss = (-delta.clip(upper=0)).rolling(period).mean()
rs = gain / loss.replace(0, np.nan)
df[f"rsi_{period}"] = 100 - (100 / (1 + rs))
# ── MACD (manual) ─────────────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
signal_line = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line
df["macd_signal"] = signal_line
df["macd_hist"] = macd_line - signal_line
df["macd_norm"] = macd_line / close
# ── Bollinger Bands (manual) ──────────────────────────────────────────────
for w in [20]:
mid = close.rolling(w).mean()
std = close.rolling(w).std()
upper = mid + 2 * std
lower = mid - 2 * std
bw = (upper - lower) / mid
pct_b = (close - lower) / (upper - lower).replace(0, np.nan)
df[f"bb_upper_{w}"] = upper
df[f"bb_lower_{w}"] = lower
df[f"bb_width_{w}"] = bw
df[f"bb_pct_{w}"] = pct_b
# ── Stochastic oscillator (manual) ────────────────────────────────────────
for k_period in [14]:
lo_k = low.rolling(k_period).min()
hi_k = high.rolling(k_period).max()
stoch_k = 100 * (close - lo_k) / (hi_k - lo_k).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df[f"stoch_k_{k_period}"] = stoch_k
df[f"stoch_d_{k_period}"] = stoch_d
# ── CCI (manual) ──────────────────────────────────────────────────────────
for w in [14, 20]:
tp = (high + low + close) / 3
tp_ma = tp.rolling(w).mean()
tp_md = tp.rolling(w).apply(lambda x: np.mean(np.abs(x - x.mean())), raw=True)
df[f"cci_{w}"] = (tp - tp_ma) / (0.015 * tp_md.replace(0, np.nan))
# ── Williams %R (manual) ──────────────────────────────────────────────────
for w in [14]:
hi_w = high.rolling(w).max()
lo_w = low.rolling(w).min()
df[f"willr_{w}"] = -100 * (hi_w - close) / (hi_w - lo_w).replace(0, np.nan)
# ── Donchian channel position ──────────────────────────────────────────────
for w in [20, 50]:
hi_d = high.rolling(w).max()
lo_d = low.rolling(w).min()
df[f"donch_pos_{w}"] = (close - lo_d) / (hi_d - lo_d).replace(0, np.nan)
# ── Rolling high / low distances ──────────────────────────────────────────
for w in [8, 20]:
df[f"dist_hi_{w}"] = (high.rolling(w).max() - close) / close
df[f"dist_lo_{w}"] = (close - low.rolling(w).min()) / close
# ── Bar body / wick features ───────────────────────────────────────────────
body = (close - open_).abs()
bar_range = (high - low).replace(0, np.nan)
df["body_ratio"] = body / bar_range
df["upper_wick_ratio"] = (high - close.clip(lower=open_)) / bar_range
df["lower_wick_ratio"] = (close.clip(upper=open_) - low) / bar_range
df["bar_direction"] = np.where(close >= open_, 1.0, -1.0)
# ── Trend regime flags (binary) ────────────────────────────────────────────
df["above_sma20"] = np.where(close > df["sma_20"], 1.0, 0.0)
df["above_sma50"] = np.where(close > df["sma_50"], 1.0, 0.0)
df["above_sma200"] = np.where(close > df["sma_200"], 1.0, 0.0)
df["sma20_above50"] = np.where(df["sma_20"] > df["sma_50"], 1.0, 0.0)
df["sma50_above200"] = np.where(df["sma_50"] > df["sma_200"], 1.0, 0.0)
# ── Lagged returns for autoregressive signal ───────────────────────────────
for lag in [1, 2, 3, 4, 5]:
df[f"close_lag_{lag}"] = close.shift(lag)
df[f"ret_lag_{lag}"] = ret1.shift(lag)
# ── Rolling correlation: price vs SMA distance ─────────────────────────────
for w in [20]:
df[f"autocorr_ret_{w}"] = ret1.rolling(w).apply(
lambda x: pd.Series(x).autocorr(lag=1) if len(x) > 1 else 0.0, raw=False
)
# ── Volume-proxy: bar range z-score ───────────────────────────────────────
for w in [20]:
rng_mean = bar_range.rolling(w).mean()
rng_std = bar_range.rolling(w).std().replace(0, np.nan)
df[f"range_zscore_{w}"] = (bar_range - rng_mean) / rng_std
# ── Fill NaN from warm-up ─────────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD SMA Trend + Multi-Indicator XGBoost",
"model_type": "XGBClassifier",
"model_params": {
"n_estimators": 500,
"max_depth": 4,
"learning_rate": 0.03,
"subsample": 0.8,
"colsample_bytree": 0.7,
"colsample_bylevel": 0.8,
"min_child_weight": 5,
"gamma": 0.1,
"reg_alpha": 0.1,
"reg_lambda": 2.0,
"scale_pos_weight": 1,
"objective": "binary:logistic",
"tree_method": "hist",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.56,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.01,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 18],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) via XGBoost with deep "
"SMA-based trend features (20/50/200), momentum, volatility, RSI, MACD, "
"Bollinger Bands, Stochastics, CCI, Donchian channels, and bar microstructure. "
"Regularised tree ensemble (L1+L2, subsampling) prevents overfit on 15-min FX data. "
"2:1 reward-to-risk with 0.5% SL / 1.0% TP targets consistent positive expectancy. "
"Session filter [6,18] UTC focuses on liquid London+NY overlap. "
"Trend filter sma_50 suppresses counter-trend noise."
),
"notes": (
"n_estimators=500 with low learning_rate=0.03 gives stable generalisation. "
"max_depth=4 limits tree complexity to avoid overfit on 15-min EURUSD. "
"min_child_weight=5 and gamma=0.1 add conservative splitting constraints. "
"reg_lambda=2.0 strong L2 regularisation for stable leaf weights. "
"colsample_bytree=0.7 adds feature bagging diversity. "
"target_horizon=4 (1 hour ahead) balances signal frequency and predictability. "
"signal_threshold=0.56 filters marginal predictions, improving precision."
),
}
|
||||||||||
|
3.97
|
NZD/USD RSI-MACD Gradient Boost Risk-Adjusted
Maximize risk-adjusted return (Sharpe/Calmar) using a deep GradientBoostingClassifier with many slow-learning trees and aggressive regularis…
|
S
@silver-bull-130
|
NZDUSD | 15min | 60.9%0.0% | +18.36%+0.00% | 1.35— | 3.80%3.80% | 7320 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 01:35:33
# Model : Gradient Boosting
# Feature Eng. : RSI 14, MACD (12,26,9) + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/NZDUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# 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(lower=0)
avg_gain = gain.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
df["rsi_14"] = 100 - (100 / (1 + rs))
# RSI derived signals
df["rsi_ob"] = np.where(df["rsi_14"] > 70, 1, 0) # overbought flag
df["rsi_os"] = np.where(df["rsi_14"] < 30, 1, 0) # oversold flag
df["rsi_mid"] = df["rsi_14"] - 50 # centred
df["rsi_slope"] = df["rsi_14"].diff(3) # momentum of RSI
df["rsi_accel"] = df["rsi_slope"].diff(2) # acceleration
# RSI regime: above/below 50
df["rsi_bull"] = np.where(df["rsi_14"] > 50, 1, -1)
# ── MACD (12, 26, 9) ────────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
signal_line = macd_line.ewm(span=9, adjust=False).mean()
macd_hist = macd_line - signal_line
df["macd_line"] = macd_line
df["macd_signal"] = signal_line
df["macd_hist"] = macd_hist
# MACD derived
df["macd_cross"] = np.where(macd_line > signal_line, 1, -1)
df["macd_hist_sign"] = np.where(macd_hist > 0, 1, -1)
df["macd_hist_chg"] = macd_hist.diff(1) # histogram change
df["macd_hist_accel"]= df["macd_hist_chg"].diff(1) # second derivative
df["macd_zero_cross"]= np.where(macd_line > 0, 1, -1)
# ── ATR 14 ──────────────────────────────────────────────────────────────
tr = pd.concat([
high - low,
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs()
], axis=1).max(axis=1)
atr14 = tr.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
df["atr_14"] = atr14
df["natr_14"] = atr14 / close # normalised ATR
df["atr_ratio"]= atr14 / atr14.rolling(50).mean() # current vs recent vol
# ── Volatility regime ───────────────────────────────────────────────────
df["vol_high"] = np.where(df["natr_14"] > df["natr_14"].rolling(100).median(), 1, 0)
# ── Price momentum ──────────────────────────────────────────────────────
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)
# Scaled by ATR so the model sees normalised moves
df["ret_1_atr"] = df["ret_1"] / (atr14 / close).replace(0, np.nan)
df["ret_3_atr"] = df["ret_3"] / (atr14 / close).replace(0, np.nan)
df["ret_8_atr"] = df["ret_8"] / (atr14 / close).replace(0, np.nan)
# ── EMAs & trend structure ───────────────────────────────────────────────
ema8 = close.ewm(span=8, adjust=False).mean()
ema21 = close.ewm(span=21, adjust=False).mean()
ema50 = close.ewm(span=50, adjust=False).mean()
ema100= close.ewm(span=100,adjust=False).mean()
df["ema8_21_spread"] = (ema8 - ema21) / close
df["ema21_50_spread"]= (ema21 - ema50) / close
df["ema50_100_spread"]= (ema50 - ema100) / close
df["price_vs_ema21"] = (close - ema21) / close
df["price_vs_ema50"] = (close - ema50) / close
df["trend_align"] = np.where(
(ema8 > ema21) & (ema21 > ema50), 1,
np.where((ema8 < ema21) & (ema21 < ema50), -1, 0)
)
# ── Bollinger Bands (20, 2) ──────────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std(ddof=0)
bb_up = bb_mid + 2 * bb_std
bb_lo = bb_mid - 2 * bb_std
bb_bw = (bb_up - bb_lo) / bb_mid # bandwidth
bb_pct = (close - bb_lo) / (bb_up - bb_lo) # %B
df["bb_pct"] = bb_pct
df["bb_bw"] = bb_bw
df["bb_bw_ratio"] = bb_bw / bb_bw.rolling(50).mean() # squeeze detector
df["bb_upper_touch"] = np.where(close >= bb_up, 1, 0)
df["bb_lower_touch"] = np.where(close <= bb_lo, 1, 0)
# ── Stochastic %K %D (14, 3) ────────────────────────────────────────────
lo14 = low.rolling(14).min()
hi14 = high.rolling(14).max()
stoch_k = 100 * (close - lo14) / (hi14 - lo14).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_kd_diff"]= stoch_k - stoch_d
df["stoch_ob"] = np.where(stoch_k > 80, 1, 0)
df["stoch_os"] = np.where(stoch_k < 20, 1, 0)
# ── Candle structure ────────────────────────────────────────────────────
body = (close - open_).abs()
candle_rng= (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_rng # body vs full range
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_rng
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_rng
df["candle_dir"] = np.where(close > open_, 1, -1)
df["candle_dir_3"] = df["candle_dir"].rolling(3).sum() # short-term bias
# ── Volume-less momentum oscillator (Williams %R 14) ───────────────────
df["williams_r"] = -100 * (hi14 - close) / (hi14 - lo14).replace(0, np.nan)
# ── RSI x MACD composite signal ─────────────────────────────────────────
df["rsi_macd_bull"] = np.where(
(df["rsi_14"] > 50) & (macd_hist > 0), 1,
np.where((df["rsi_14"] < 50) & (macd_hist < 0), -1, 0)
)
# ── Divergence proxy: price vs RSI direction (3-bar) ────────────────────
price_dir3 = np.sign(close.diff(3))
rsi_dir3 = np.sign(df["rsi_14"].diff(3))
df["rsi_div"] = np.where(price_dir3 != rsi_dir3, 1, 0)
# ── Mean-reversion signal: distance from 50-bar mean normalised by ATR ──
sma50 = close.rolling(50).mean()
df["zscore_50"] = (close - sma50) / (close.rolling(50).std(ddof=0).replace(0, np.nan))
df["mean_rev_long"] = np.where(df["zscore_50"] < -1.5, 1, 0)
df["mean_rev_short"] = np.where(df["zscore_50"] > 1.5, 1, 0)
# ── Interaction features ─────────────────────────────────────────────────
df["rsi_bb_pct"] = df["rsi_14"] * df["bb_pct"]
df["macd_hist_rsi_mid"] = df["macd_hist"] * df["rsi_mid"]
df["stoch_rsi"] = df["stoch_k"] * df["rsi_14"] / 1e4 # normalised product
# ── Lag features (avoid lookahead) ──────────────────────────────────────
for lag in [1, 2, 4, 8]:
df[f"rsi_lag{lag}"] = df["rsi_14"].shift(lag)
df[f"macd_hist_lag{lag}"] = df["macd_hist"].shift(lag)
df[f"ret_lag{lag}"] = df["ret_1"].shift(lag)
# ── Hour-of-day & day-of-week cyclic encoding ───────────────────────────
if hasattr(df.index, "hour"):
hour = df.index.hour
dow = df.index.dayofweek
df["hour_sin"] = np.sin(2 * np.pi * hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * hour / 24)
df["dow_sin"] = np.sin(2 * np.pi * dow / 5)
df["dow_cos"] = np.cos(2 * np.pi * dow / 5)
# ── Final fill ───────────────────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "NZD/USD RSI-MACD Gradient Boost Risk-Adjusted",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 600,
"max_depth": 4,
"learning_rate": 0.03,
"subsample": 0.75,
"max_features": "sqrt",
"min_samples_leaf": 20,
"min_samples_split":40,
"warm_start": False,
},
"signal_threshold": 0.56,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [21, 21],
"min_atr": 0.0002,
"trend_filter": None,
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) using a deep "
"GradientBoostingClassifier with many slow-learning trees and "
"aggressive regularisation (min_samples_leaf=20, subsample=0.75). "
"Feature set deliberately differs from prior RSI+BB+Stoch attempts "
"by adding: ATR-normalised returns, z-score mean-reversion signals, "
"RSI divergence proxy, Williams %R, candle structure ratios, cyclic "
"time encoding, and interaction/lag features to give the model richer "
"multi-timeframe context. SL=0.5%/TP=1% gives 1:2 RR aligned with "
"maximising Sharpe."
),
"notes": (
"Prior PF=1.35 / ret=+18.36% used standard RSI+MACD+BB+Stoch without "
"ATR normalisation or divergence detection. This version adds z-score "
"mean-reversion context, candle structure, and temporal encoding to "
"reduce false positives. session_filter=[21,21] is intentionally "
"narrow — set to None if you want 24h coverage. min_atr=0.0002 "
"avoids dead-market signals."
),
}
|
||||||||||
|
3.50
|
EUR/USD RSI Mean-Reversion + Multi-Feature XGBoost
Maximize Sharpe ratio via RSI-driven mean-reversion signals enhanced with Bollinger Bands, MACD, Stochastic, CCI, and EMA trend context. XGB…
|
T
@theta-crane-902
|
EUR/US | 70.6%— | +1.06%— | 2.33— | 0.30%0.30% | 34— |
|
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-24 01:09:43
# Model : XGBoost
# Feature Eng. : buy EURUSD when RSI < 30 and sell when RSI > 70 + 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 = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2026-04-14"
END_DATE = "2026-05-12"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# 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(alpha=1/14, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
df["rsi_14"] = 100 - (100 / (1 + rs))
# RSI zone flags (core signal)
df["rsi_oversold"] = np.where(df["rsi_14"] < 30, 1, 0)
df["rsi_overbought"] = np.where(df["rsi_14"] > 70, 1, 0)
df["rsi_neutral"] = np.where((df["rsi_14"] >= 30) & (df["rsi_14"] <= 70), 1, 0)
# RSI distance from extremes
df["rsi_dist_30"] = df["rsi_14"] - 30
df["rsi_dist_70"] = 70 - df["rsi_14"]
# --- RSI (7) for faster signal ---
avg_gain7 = gain.ewm(alpha=1/7, min_periods=7, adjust=False).mean()
avg_loss7 = loss.ewm(alpha=1/7, min_periods=7, adjust=False).mean()
rs7 = avg_gain7 / avg_loss7.replace(0, np.nan)
df["rsi_7"] = 100 - (100 / (1 + rs7))
# RSI crossover signals
df["rsi_cross_30_up"] = np.where((df["rsi_7"].shift(1) < 30) & (df["rsi_7"] >= 30), 1, 0)
df["rsi_cross_70_dn"] = np.where((df["rsi_7"].shift(1) > 70) & (df["rsi_7"] <= 70), 1, 0)
# --- Bollinger Bands (20, 2) ---
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std()
bb_upper = bb_mid + 2 * bb_std
bb_lower = bb_mid - 2 * bb_std
df["bb_pct_b"] = (close - bb_lower) / (bb_upper - bb_lower).replace(0, np.nan)
df["bb_width"] = (bb_upper - bb_lower) / bb_mid.replace(0, np.nan)
df["bb_z"] = (close - bb_mid) / bb_std.replace(0, np.nan)
# Price relative to BB bands
df["price_below_bb_lower"] = np.where(close < bb_lower, 1, 0)
df["price_above_bb_upper"] = np.where(close > bb_upper, 1, 0)
# --- MACD ---
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
macd_signal = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line
df["macd_signal_line"] = macd_signal
df["macd_hist"] = macd_line - macd_signal
df["macd_hist_prev"] = df["macd_hist"].shift(1)
df["macd_cross_up"] = np.where((df["macd_hist"] > 0) & (df["macd_hist_prev"] <= 0), 1, 0)
df["macd_cross_dn"] = np.where((df["macd_hist"] < 0) & (df["macd_hist_prev"] >= 0), 1, 0)
# --- ATR (14) ---
tr1 = high - low
tr2 = (high - close.shift(1)).abs()
tr3 = (low - close.shift(1)).abs()
tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
atr14 = tr.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
df["atr_14"] = atr14
df["natr_14"] = atr14 / close.replace(0, np.nan)
# --- Stochastic Oscillator (14, 3) ---
low14 = low.rolling(14).min()
high14 = high.rolling(14).max()
stoch_k = 100 * (close - low14) / (high14 - low14).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_oversold"] = np.where(stoch_k < 20, 1, 0)
df["stoch_overbought"] = np.where(stoch_k > 80, 1, 0)
# Stoch + RSI confluence
df["rsi_stoch_oversold"] = np.where((df["rsi_14"] < 35) & (stoch_k < 25), 1, 0)
df["rsi_stoch_overbought"] = np.where((df["rsi_14"] > 65) & (stoch_k > 75), 1, 0)
# --- EMA trend context ---
ema20 = close.ewm(span=20, adjust=False).mean()
ema50 = close.ewm(span=50, adjust=False).mean()
ema200 = close.ewm(span=200, adjust=False).mean()
df["ema_20"] = ema20
df["ema_50"] = ema50
df["ema_200"] = ema200
df["price_above_ema50"] = np.where(close > ema50, 1, 0)
df["price_above_ema200"] = np.where(close > ema200, 1, 0)
df["ema20_above_ema50"] = np.where(ema20 > ema50, 1, 0)
# Price distance from EMAs (normalised)
df["dist_ema20"] = (close - ema20) / close.replace(0, np.nan)
df["dist_ema50"] = (close - ema50) / close.replace(0, np.nan)
# --- Williams %R (14) ---
df["williams_r"] = -100 * (high14 - close) / (high14 - low14).replace(0, np.nan)
# --- CCI (20) ---
tp = (high + low + close) / 3
tp_sma = tp.rolling(20).mean()
tp_mad = tp.rolling(20).apply(lambda x: np.mean(np.abs(x - x.mean())), raw=True)
df["cci_20"] = (tp - tp_sma) / (0.015 * tp_mad.replace(0, np.nan))
df["cci_oversold"] = np.where(df["cci_20"] < -100, 1, 0)
df["cci_overbought"] = np.where(df["cci_20"] > 100, 1, 0)
# --- Rate of Change ---
df["roc_5"] = close.pct_change(5)
df["roc_10"] = close.pct_change(10)
df["roc_20"] = close.pct_change(20)
# --- Candle features ---
df["body"] = (close - open_) / atr14.replace(0, np.nan)
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / atr14.replace(0, np.nan)
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / atr14.replace(0, np.nan)
df["is_bullish"] = np.where(close > open_, 1, 0)
# --- Volume proxy (rolling std of returns as volatility) ---
ret = close.pct_change()
df["vol_5"] = ret.rolling(5).std()
df["vol_20"] = ret.rolling(20).std()
df["vol_ratio"] = df["vol_5"] / df["vol_20"].replace(0, np.nan)
# --- Lagged RSI values ---
for lag in [1, 2, 3, 4]:
df[f"rsi_14_lag{lag}"] = df["rsi_14"].shift(lag)
# --- Lagged returns ---
for lag in [1, 2, 3, 4, 8]:
df[f"ret_lag{lag}"] = ret.shift(lag)
# --- RSI momentum (slope) ---
df["rsi_slope_3"] = df["rsi_14"] - df["rsi_14"].shift(3)
df["rsi_slope_5"] = df["rsi_14"] - df["rsi_14"].shift(5)
# --- Session hour (UTC) ---
if hasattr(df.index, "hour"):
df["hour_sin"] = np.sin(2 * np.pi * df.index.hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * df.index.hour / 24)
else:
df["hour_sin"] = 0.0
df["hour_cos"] = 1.0
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD RSI Mean-Reversion + Multi-Feature XGBoost",
"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.1,
"reg_alpha": 0.5,
"reg_lambda": 1.5,
"objective": "binary:logistic",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.0030,
"take_profit": 0.0060,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [7, 17],
"min_atr": None,
"trend_filter": None,
"target_horizon": 4,
"objective": (
"Maximize Sharpe ratio via RSI-driven mean-reversion signals enhanced with "
"Bollinger Bands, MACD, Stochastic, CCI, and EMA trend context. "
"XGBoost chosen for its robustness to feature scale and ability to capture "
"non-linear RSI threshold effects. Regularisation (alpha, lambda, min_child_weight) "
"prevents overfitting on the short date range. SL/TP ratio 1:2 improves expectancy. "
"Session filter restricts trading to London/NY overlap for tighter spreads and "
"higher directional conviction."
),
"notes": (
"Core features: RSI-14 oversold/overbought flags and distances, RSI-7 crossovers, "
"BB %B and z-score, MACD histogram crosses, Stochastic K/D, CCI, Williams %R, "
"candle body/wick normalised by ATR, volatility ratio, lagged RSI and returns, "
"RSI slope, and cyclical hour encoding. "
"target_horizon=4 bars (1 hour on 15-min data) aligns with mean-reversion speed. "
"signal_threshold=0.55 balances precision vs. trade frequency for Sharpe optimisation."
),
}
|
||||||||||
|
1.99
|
USD/JPY BB Squeeze Breakout (GBM)
Maximize risk-adjusted return (Sharpe). GradientBoostingClassifier chosen for strong performance on tabular financial data with moderate fea…
|
V
@vol_drifter
|
USDJPY | 15min | 60.7%66.7% | +1.15%+3.55% | 1.062.63 | 3.13%3.13% | 20139 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:57:20
# Model : Gradient Boosting
# Feature Eng. : BB (20,2.0), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# Bollinger Bands Squeeze Breakout Strategy — USD/JPY 15-min
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDJPY_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── Bollinger Bands (20, 2) ──────────────────────────────────────────────
bb_period = 20
bb_std = 2.0
bb_mid = close.rolling(bb_period).mean()
bb_sigma = close.rolling(bb_period).std(ddof=0)
bb_upper = bb_mid + bb_std * bb_sigma
bb_lower = bb_mid - bb_std * bb_sigma
df["bb_mid"] = bb_mid
df["bb_upper"] = bb_upper
df["bb_lower"] = bb_lower
# Band width and %B — required features
df["bb_width"] = (bb_upper - bb_lower) / bb_mid
df["bb_pct"] = (close - bb_lower) / (bb_upper - bb_lower)
# ── ATR 14 & NATR ────────────────────────────────────────────────────────
atr_period = 14
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(span=atr_period, min_periods=atr_period, adjust=False).mean()
natr = atr / close
df["atr"] = atr
df["natr"] = natr
# ── Squeeze detection ────────────────────────────────────────────────────
# Keltner Channel (EMA20 ± 1.5 × ATR) for squeeze comparison
kc_mid = close.ewm(span=20, adjust=False).mean()
kc_upper = kc_mid + 1.5 * atr
kc_lower = kc_mid - 1.5 * atr
df["squeeze"] = np.where(
(bb_upper < kc_upper) & (bb_lower > kc_lower), 1.0, 0.0
)
# Rolling squeeze count (bars in squeeze over last 10 bars)
df["squeeze_count"] = (
df["squeeze"].rolling(10).sum()
)
# Band-width z-score (how compressed is the width vs recent history)
bw_mean = df["bb_width"].rolling(50).mean()
bw_std = df["bb_width"].rolling(50).std(ddof=0)
df["bb_width_zscore"] = (df["bb_width"] - bw_mean) / (bw_std + 1e-10)
# ── Breakout momentum ────────────────────────────────────────────────────
# Price distance from bands, normalised by ATR
df["dist_upper"] = (close - bb_upper) / (atr + 1e-10)
df["dist_lower"] = (close - bb_lower) / (atr + 1e-10)
df["dist_mid"] = (close - bb_mid) / (atr + 1e-10)
# ── Rate of change ────────────────────────────────────────────────────────
for n in [1, 4, 8, 16]:
df[f"roc_{n}"] = close.pct_change(n)
# ── RSI 14 ───────────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_g = gain.ewm(span=14, min_periods=14, adjust=False).mean()
avg_l = loss.ewm(span=14, min_periods=14, adjust=False).mean()
rs = avg_g / (avg_l + 1e-10)
df["rsi_14"] = 100.0 - 100.0 / (1.0 + rs)
# RSI normalised to [-1, 1]
df["rsi_norm"] = (df["rsi_14"] - 50.0) / 50.0
# ── Momentum / trend context ──────────────────────────────────────────────
ema_9 = close.ewm(span=9, adjust=False).mean()
ema_21 = close.ewm(span=21, adjust=False).mean()
ema_50 = close.ewm(span=50, adjust=False).mean()
df["ema_9_21_diff"] = (ema_9 - ema_21) / (atr + 1e-10)
df["ema_21_50_diff"] = (ema_21 - ema_50) / (atr + 1e-10)
# Price position relative to EMAs
df["close_vs_ema9"] = (close - ema_9) / (atr + 1e-10)
df["close_vs_ema50"] = (close - ema_50) / (atr + 1e-10)
# ── Volume-proxy: ATR velocity ────────────────────────────────────────────
df["atr_roc"] = atr.pct_change(4)
# ── MACD-style oscillator ─────────────────────────────────────────────────
macd_line = close.ewm(span=12, adjust=False).mean() - close.ewm(span=26, adjust=False).mean()
macd_signal = macd_line.ewm(span=9, adjust=False).mean()
df["macd_hist"] = (macd_line - macd_signal) / (atr + 1e-10)
# ── Stochastic %K (14) ────────────────────────────────────────────────────
low_14 = low.rolling(14).min()
high_14 = high.rolling(14).max()
df["stoch_k"] = (close - low_14) / (high_14 - low_14 + 1e-10)
# ── Candle body / wick features ───────────────────────────────────────────
body = (close - open_).abs()
candle_range = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_range
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / (candle_range + 1e-10)
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / (candle_range + 1e-10)
df["bull_candle"] = np.where(close > open_, 1.0, 0.0)
# ── Lagged bb_pct and bb_width ────────────────────────────────────────────
for lag in [1, 2, 4]:
df[f"bb_pct_lag{lag}"] = df["bb_pct"].shift(lag)
df[f"bb_width_lag{lag}"] = df["bb_width"].shift(lag)
# ── Band width momentum (is it expanding?) ────────────────────────────────
df["bb_width_chg1"] = df["bb_width"].diff(1)
df["bb_width_chg4"] = df["bb_width"].diff(4)
# ── Hour / session features ───────────────────────────────────────────────
df["hour_sin"] = np.sin(2 * np.pi * df.index.hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * df.index.hour / 24)
df["dow_sin"] = np.sin(2 * np.pi * df.index.dayofweek / 5)
df["dow_cos"] = np.cos(2 * np.pi * df.index.dayofweek / 5)
# ── Fill NaN from warm-up ─────────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/JPY BB Squeeze Breakout (GBM)",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.75,
"min_samples_leaf": 20,
"max_features": "sqrt",
"validation_fraction": 0.1,
"n_iter_no_change": 30,
"tol": 1e-4,
"random_state": 42,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0003,
"trend_filter": None,
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe). "
"GradientBoostingClassifier chosen for strong performance on tabular "
"financial data with moderate feature counts. Deeper ensemble (400 "
"estimators, depth 4) with early stopping captures non-linear BB "
"squeeze patterns. Subsample=0.75 and sqrt features reduce overfitting. "
"SL 0.5% / TP 1.0% gives 1:2 R:R ratio. Session filter 06-20 UTC covers "
"London + NY sessions where USD/JPY liquidity is highest."
),
"notes": (
"Core signal: BB squeeze (narrow band width inside Keltner Channel) "
"followed by band expansion. Features include band width z-score, "
"breakout direction (dist_upper/lower), RSI, MACD histogram, "
"stochastic %K, EMA spreads, candle structure, and lagged BB features. "
"NATR used as min_atr filter to avoid low-volatility noise trades. "
"Horizon=4 bars (1 hour on 15-min data) aligns with typical "
"post-squeeze expansion duration."
),
}
|
||||||||||
|
1.82
|
EUR/USD XGBoost SMA+RSI+MACD+BB Trend Rider
Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min data. XGBoost with moderate depth and regularisation to avoid overfitting on…
|
S
@still-lynx-704
|
EURUSD | 15min | 50.0%50.0% | +9.05%+1.43% | 2.642.67 | 1.05%1.05% | 6622 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-05 09:59:46
# Model : XGBoost
# Feature Eng. : SMA (20,50,200), BB (20,2.0), RSI 14, MACD (12,26,9), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-23"
END_DATE = "2026-04-23"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA 20, 50, 200 + distance from close ──────────────────────────────
for p in [20, 50, 200]:
sma = close.rolling(p).mean()
df[f"sma_{p}"] = sma
df[f"dm_sma_{p}"] = (close - sma) / sma
# ── Bollinger Bands (20, 2.0) ───────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std(ddof=0)
bb_upper = bb_mid + 2.0 * bb_std
bb_lower = bb_mid - 2.0 * bb_std
bb_range = bb_upper - bb_lower
df["bb_mid"] = bb_mid
df["bb_upper"] = bb_upper
df["bb_lower"] = bb_lower
df["bb_width"] = bb_range / bb_mid
df["bb_pct"] = (close - bb_lower) / bb_range.replace(0, np.nan)
# ── RSI 14 ──────────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(com=13, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(com=13, min_periods=14, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
df["rsi_14"] = 100.0 - (100.0 / (1.0 + rs))
# ── MACD (12, 26, 9) ────────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
signal_line = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line
df["macd_signal"] = signal_line
df["macd_hist"] = macd_line - signal_line
# ── ATR 14 + NATR ───────────────────────────────────────────────────────
tr = pd.concat([
high - low,
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs()
], axis=1).max(axis=1)
atr = tr.ewm(com=13, min_periods=14, adjust=False).mean()
df["atr_14"] = atr
df["natr"] = atr / close
# ── Additional derived features ─────────────────────────────────────────
# Price momentum over multiple horizons
for lag in [1, 4, 8, 16]:
df[f"mom_{lag}"] = close.pct_change(lag)
# Log return
df["log_ret_1"] = np.log(close / close.shift(1))
# Candle body and wick ratios
body = (close - open_).abs()
candle_rng = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_rng
df["upper_wick_ratio"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_rng
df["lower_wick_ratio"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_rng
df["candle_dir"] = np.where(close >= open_, 1.0, -1.0)
# Volume / volatility proxy: rolling std of returns
ret = close.pct_change()
df["vol_8"] = ret.rolling(8).std()
df["vol_20"] = ret.rolling(20).std()
# RSI-derived features
df["rsi_dist_50"] = df["rsi_14"] - 50.0
df["rsi_overbought"] = np.where(df["rsi_14"] > 70, 1.0, 0.0)
df["rsi_oversold"] = np.where(df["rsi_14"] < 30, 1.0, 0.0)
# MACD cross signal
df["macd_cross"] = np.where(
(df["macd_hist"] > 0) & (df["macd_hist"].shift(1) <= 0), 1.0,
np.where(
(df["macd_hist"] < 0) & (df["macd_hist"].shift(1) >= 0), -1.0,
0.0
)
)
# BB squeeze: narrow bands relative to recent average
df["bb_squeeze"] = np.where(df["bb_width"] < df["bb_width"].rolling(50).mean(), 1.0, 0.0)
# Price relative to SMA crossovers
df["sma20_above_sma50"] = np.where(df["sma_20"] > df["sma_50"], 1.0, -1.0)
df["sma50_above_sma200"] = np.where(df["sma_50"] > df["sma_200"], 1.0, -1.0)
# High/low channel breakout features
df["high_20"] = high.rolling(20).max()
df["low_20"] = low.rolling(20).min()
df["chan_pos"] = (close - df["low_20"]) / (df["high_20"] - df["low_20"]).replace(0, np.nan)
# Lagged RSI and MACD hist
df["rsi_14_lag1"] = df["rsi_14"].shift(1)
df["rsi_14_lag4"] = df["rsi_14"].shift(4)
df["macd_hist_lag1"] = df["macd_hist"].shift(1)
# ATR trend: expanding vs contracting volatility
df["atr_ratio"] = df["atr_14"] / df["atr_14"].rolling(50).mean()
# Fill NaN from warm-up
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD XGBoost SMA+RSI+MACD+BB Trend Rider",
"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.2,
"reg_alpha": 0.1,
"reg_lambda": 1.5,
"objective": "binary:logistic",
"tree_method": "hist",
"random_state": 42,
},
"signal_threshold": 0.54,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) on EUR/USD 15-min data. "
"XGBoost with moderate depth and regularisation to avoid overfitting on "
"noisy FX data. Conservative SL/TP ratio of 1:2 improves expectancy. "
"Session filter keeps the model active during liquid London/NY overlap. "
"Min ATR filter avoids low-volatility noise. SMA-50 trend filter aligns "
"trades with the prevailing medium-term trend, reducing whipsaw."
),
"notes": (
"Feature set: SMA 20/50/200 distances, BB width/pct, RSI 14, MACD histogram, "
"ATR/NATR, multi-horizon momentum, candle structure, volatility, channel position, "
"lagged indicators, and cross-over binary signals. "
"Hyperparameters tuned for bias-variance balance: shallow trees (depth 4), "
"high n_estimators with low learning rate, stochastic sampling, and L1/L2 "
"regularisation reduce overfitting. Threshold 0.54 slightly above default to "
"filter marginal signals while maintaining trade frequency."
),
}
|
||||||||||
|
1.66
|
USD/CAD BB + ATR Gradient Boosting Mean-Rev
Maximize risk-adjusted return (Sharpe/Calmar) on USD/CAD 15-min data. GradientBoostingClassifier chosen for strong generalisation on noisy F…
|
S
@silver-bull-130
|
USDCAD | 15min | 62.6%68.3% | +2.56%+1.93% | 1.152.20 | 1.75%1.75% | 35641 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 01:50:17
# Model : Gradient Boosting
# Feature Eng. : BB (20,2.0), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── Bollinger Bands (20, 2) ──────────────────────────────────────────────
bb_period = 20
bb_std = 2.0
bb_mid = close.rolling(bb_period).mean()
bb_std_s = close.rolling(bb_period).std(ddof=0)
bb_upper = bb_mid + bb_std * bb_std_s
bb_lower = bb_mid - bb_std * bb_std_s
df["bb_mid"] = bb_mid
df["bb_upper"] = bb_upper
df["bb_lower"] = bb_lower
df["bb_width"] = (bb_upper - bb_lower) / bb_mid
df["bb_pct"] = (close - bb_lower) / (bb_upper - bb_lower)
# ── ATR (14) & Normalised ATR ────────────────────────────────────────────
atr_period = 14
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(span=atr_period, adjust=False).mean()
natr = atr / close
df["atr"] = atr
df["natr"] = natr
# ── RSI (14) ─────────────────────────────────────────────────────────────
rsi_period = 14
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(span=rsi_period, adjust=False).mean()
avg_loss = loss.ewm(span=rsi_period, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
df["rsi"] = 100 - (100 / (1 + rs))
# ── MACD (12, 26, 9) ─────────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
macd_signal = macd_line.ewm(span=9, adjust=False).mean()
df["macd"] = macd_line
df["macd_sig"] = macd_signal
df["macd_hist"]= macd_line - macd_signal
# ── SMA filters (50, 200) ────────────────────────────────────────────────
df["sma_20"] = close.rolling(20).mean()
df["sma_50"] = close.rolling(50).mean()
df["sma_200"] = close.rolling(200).mean()
# Price relative to moving averages
df["close_vs_sma20"] = (close - df["sma_20"]) / df["sma_20"]
df["close_vs_sma50"] = (close - df["sma_50"]) / df["sma_50"]
df["close_vs_sma200"] = (close - df["sma_200"]) / df["sma_200"]
# ── Price momentum / returns ─────────────────────────────────────────────
df["ret_1"] = close.pct_change(1)
df["ret_4"] = close.pct_change(4)
df["ret_8"] = close.pct_change(8)
df["ret_16"] = close.pct_change(16)
df["ret_32"] = close.pct_change(32)
# ── Candle body & wick features ──────────────────────────────────────────
body = (close - open_).abs()
candle_range = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_range
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_range
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_range
df["close_dir"] = np.sign(close - open_)
# ── Volatility regime ────────────────────────────────────────────────────
df["vol_ratio"] = natr / natr.rolling(50).mean() # ATR vs its own average
df["bb_squeeze"] = np.where(df["bb_width"] < df["bb_width"].rolling(50).quantile(0.25), 1.0, 0.0)
# ── Stochastic %K / %D (14, 3) ───────────────────────────────────────────
low14 = low.rolling(14).min()
high14 = high.rolling(14).max()
stoch_k = 100 * (close - low14) / (high14 - low14).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
# ── Rate-of-change ───────────────────────────────────────────────────────
df["roc_10"] = (close - close.shift(10)) / close.shift(10)
# ── Rolling z-score of close (20-bar) ────────────────────────────────────
roll_mean = close.rolling(20).mean()
roll_std = close.rolling(20).std(ddof=0).replace(0, np.nan)
df["zscore_20"] = (close - roll_mean) / roll_std
# ── Volume-related (if volume column exists) ─────────────────────────────
if "volume" in df.columns and df["volume"].sum() > 0:
vol_ma = df["volume"].rolling(20).mean().replace(0, np.nan)
df["vol_ratio_20"] = df["volume"] / vol_ma
# ── Fill NaNs from warm-up ───────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD BB + ATR Gradient Boosting Mean-Rev",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.8,
"min_samples_leaf": 20,
"max_features": "sqrt",
"validation_fraction": 0.1,
"n_iter_no_change": 30,
"tol": 1e-4,
"random_state": 42,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [7, 20],
"min_atr": 0.0002,
"trend_filter": None,
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe/Calmar) on USD/CAD 15-min data. "
"GradientBoostingClassifier chosen for strong generalisation on noisy FX "
"price data; moderate depth (4) and learning rate (0.04) with early stopping "
"prevent overfitting. Features: Bollinger Bands (mean-reversion signal via "
"bb_pct and bb_width), ATR/NATR (volatility filter), RSI, MACD, Stochastic, "
"z-score, momentum returns, and candle-body ratios. 2:1 R:R (SL 0.5%, TP 1.0%) "
"with session filter (07-20 UTC) to avoid illiquid overnight hours."
),
"notes": (
"session_filter [7,20] captures London + NY overlap on USD/CAD. "
"min_atr 0.0002 avoids flat/choppy markets. on_opposite=reverse ensures "
"the model flips direction quickly when sentiment changes. "
"target_horizon=4 bars (1 hour) aligns with typical intraday FX moves."
),
}
|
||||||||||
|
1.43
|
EUR/USD Gradient Boost SMA+RSI+MACD Swing
Maximize risk-adjusted return (Sharpe / Calmar) on EUR/USD 15-min. GradientBoostingClassifier chosen for robustness to noisy FX features and…
|
E
@elastic-moose-350
|
EURUSD | 15min | 47.2%65.2% | +4.52%+1.71% | 1.553.50 | 2.72%2.72% | 7223 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 03:08:55
# Model : Gradient Boosting
# Feature Eng. : SMA (20,50,200), BB (20,2.0), RSI 14, MACD (12,26,9), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA 20, 50, 200 + distance from close ─────────────────────────────
for p in [20, 50, 200]:
sma = close.rolling(p).mean()
df[f"sma_{p}"] = sma
df[f"dm_sma_{p}"] = (close - sma) / sma
# ── Bollinger Bands (20, 2) ────────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std(ddof=0)
bb_upper = bb_mid + 2.0 * bb_std
bb_lower = bb_mid - 2.0 * bb_std
df["bb_width"] = (bb_upper - bb_lower) / bb_mid
denom = bb_upper - bb_lower
df["bb_pct"] = np.where(denom != 0, (close - bb_lower) / denom, 0.5)
# ── RSI 14 ────────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=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.replace(0, np.nan)
df["rsi_14"] = 100 - (100 / (1 + rs))
# ── MACD (12, 26, 9) ──────────────────────────────────────────────────
ema_fast = close.ewm(span=12, adjust=False).mean()
ema_slow = close.ewm(span=26, adjust=False).mean()
macd_line = ema_fast - ema_slow
signal_line = macd_line.ewm(span=9, adjust=False).mean()
df["macd_line"] = macd_line
df["macd_sig"] = signal_line
df["macd_hist"] = macd_line - signal_line
# ── ATR 14 + NATR ─────────────────────────────────────────────────────
hl = high - low
hc = (high - close.shift(1)).abs()
lc = (low - close.shift(1)).abs()
tr = pd.concat([hl, hc, lc], axis=1).max(axis=1)
atr = tr.ewm(com=13, min_periods=14).mean()
df["atr_14"] = atr
df["natr"] = atr / close
# ── Price momentum / rate-of-change ───────────────────────────────────
for p in [4, 8, 16, 32]:
df[f"roc_{p}"] = close.pct_change(p)
# ── Candle body and wick features ─────────────────────────────────────
body = (close - open_).abs()
candle_range = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_range
df["upper_wick"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / candle_range
df["lower_wick"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / candle_range
df["body_dir"] = np.sign(close - open_)
# ── Volume-normalised (uses candle range as proxy if no volume col) ───
# Rolling z-score of close
roll_mean = close.rolling(20).mean()
roll_std = close.rolling(20).std(ddof=0).replace(0, np.nan)
df["close_zscore_20"] = (close - roll_mean) / roll_std
# ── RSI divergence proxy ──────────────────────────────────────────────
df["rsi_delta_4"] = df["rsi_14"].diff(4)
df["price_delta_4"] = close.pct_change(4)
df["rsi_price_div"] = df["rsi_delta_4"] - (df["price_delta_4"] * 100)
# ── MACD histogram slope ──────────────────────────────────────────────
df["macd_hist_slope"] = df["macd_hist"].diff(2)
# ── SMA crossover signals ─────────────────────────────────────────────
df["sma20_vs_50"] = np.where(df["sma_20"] > df["sma_50"], 1.0, -1.0)
df["sma50_vs_200"] = np.where(df["sma_50"] > df["sma_200"], 1.0, -1.0)
# ── Volatility regime (ATR percentile proxy) ──────────────────────────
atr_roll_min = atr.rolling(96).min()
atr_roll_max = atr.rolling(96).max()
atr_range = (atr_roll_max - atr_roll_min).replace(0, np.nan)
df["atr_pctile_96"] = (atr - atr_roll_min) / atr_range
# ── Stochastic oscillator %K, %D ──────────────────────────────────────
low_14 = low.rolling(14).min()
high_14 = high.rolling(14).max()
stoch_k = 100 * (close - low_14) / (high_14 - low_14).replace(0, np.nan)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_diff"] = stoch_k - stoch_d
# ── Rolling high/low breakout distance ────────────────────────────────
df["dist_hi_20"] = (high.rolling(20).max() - close) / close
df["dist_lo_20"] = (close - low.rolling(20).min()) / close
# ── Hour-of-day and day-of-week cyclical features ─────────────────────
hour = pd.Series(df.index.hour, index=df.index, dtype=float)
dow = pd.Series(df.index.dayofweek, index=df.index, dtype=float)
df["hour_sin"] = np.sin(2 * np.pi * hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * hour / 24)
df["dow_sin"] = np.sin(2 * np.pi * dow / 5)
df["dow_cos"] = np.cos(2 * np.pi * dow / 5)
# ── Fill NaN from indicator warm-up ───────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD Gradient Boost SMA+RSI+MACD Swing",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.75,
"min_samples_leaf": 20,
"min_samples_split": 30,
"max_features": "sqrt",
"validation_fraction": 0.1,
"n_iter_no_change": 30,
"tol": 1e-4,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [7, 18],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe / Calmar) on EUR/USD 15-min. "
"GradientBoostingClassifier chosen for robustness to noisy FX features and "
"good probability calibration. Shallow trees (depth 4), high n_estimators with "
"early stopping prevent overfitting. Subsample=0.75 adds stochasticity. "
"SL=0.5%, TP=1.0% gives 1:2 R:R. Session filter 07-18 UTC captures London+NY overlap. "
"min_atr filters out flat/illiquid periods. sma_50 trend filter aligns trades with "
"medium-term momentum. Threshold 0.55 balances precision vs recall."
),
"notes": (
"Features: SMA(20,50,200) with distance ratios, BB(20,2) width+pct, RSI-14, "
"MACD(12,26,9) line/signal/hist + slope, ATR-14 + NATR, ROC(4,8,16,32), "
"candle body/wick ratios, close z-score, RSI-price divergence proxy, "
"stochastic %K/%D, rolling high/low breakout distances, "
"SMA crossover flags, ATR percentile regime, hour/DOW cyclical encodings. "
"on_opposite=reverse means a strong counter-signal immediately flips the position, "
"reducing idle time and capturing reversals within the London-NY session."
),
}
|
||||||||||
|
1.32
|
NZD/USD EMA Cross + ATR Gradient Boosting
Maximize risk-adjusted return (Sharpe / Calmar). GradientBoostingClassifier with moderate depth (4) and low learning rate (0.03) to reduce o…
|
E
@elastic-moose-350
|
NZDUSD | 15min | 63.3%63.7% | +9.88%+4.43% | 1.181.61 | 3.44%3.44% | 712124 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 03:16:00
# Model : Gradient Boosting
# Feature Eng. : EMA (50,200), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/NZDUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── EMA 50 and EMA 200 ──────────────────────────────────────────────────
ema_50 = close.ewm(span=50, adjust=False).mean()
ema_200 = close.ewm(span=200, adjust=False).mean()
df["ema_50"] = ema_50
df["ema_200"] = ema_200
df["dm_ema_50"] = (close - ema_50) / ema_50
df["dm_ema_200"] = (close - ema_200) / ema_200
# EMA cross signal: ema_50 vs ema_200
df["ema_cross"] = df["ema_50"] - df["ema_200"]
# Cross direction: +1 when ema_50 > ema_200, -1 otherwise
df["ema_cross_sign"] = np.where(df["ema_cross"] > 0, 1.0, -1.0)
# Cross event: 1 when cross just happened (sign flip)
prev_cross = df["ema_cross"].shift(1)
df["ema_cross_event"] = np.where(
(df["ema_cross"] * prev_cross) < 0, 1.0, 0.0
)
# ── ATR 14 ──────────────────────────────────────────────────────────────
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(span=14, adjust=False).mean()
df["atr"] = atr
df["natr"] = atr / close
# ── RSI 14 ──────────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(span=14, adjust=False).mean()
avg_loss = loss.ewm(span=14, adjust=False).mean()
rs = avg_gain / (avg_loss + 1e-10)
rsi = 100 - (100 / (1 + rs))
df["rsi_14"] = rsi
df["rsi_norm"] = (rsi - 50) / 50 # centred and scaled
# ── MACD ────────────────────────────────────────────────────────────────
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd = ema_12 - ema_26
signal = macd.ewm(span=9, adjust=False).mean()
df["macd"] = macd
df["macd_signal"] = signal
df["macd_hist"] = macd - signal
df["macd_norm"] = macd / close
df["macd_hist_norm"] = (macd - signal) / close
# ── Bollinger Bands (20, 2) ──────────────────────────────────────────────
sma_20 = close.rolling(20).mean()
std_20 = close.rolling(20).std()
bb_upper = sma_20 + 2 * std_20
bb_lower = sma_20 - 2 * std_20
bb_width = (bb_upper - bb_lower) / (sma_20 + 1e-10)
bb_pos = (close - bb_lower) / (bb_upper - bb_lower + 1e-10)
df["bb_width"] = bb_width
df["bb_pos"] = bb_pos
# ── Momentum & Rate-of-Change ────────────────────────────────────────────
df["mom_4"] = close.pct_change(4)
df["mom_8"] = close.pct_change(8)
df["mom_16"] = close.pct_change(16)
# ── Rolling volatility (realised vol over 20 bars) ──────────────────────
log_ret = np.log(close / close.shift(1))
df["rvol_20"] = log_ret.rolling(20).std()
# ── Stochastic Oscillator (14) ───────────────────────────────────────────
low_14 = low.rolling(14).min()
high_14 = high.rolling(14).max()
stoch_k = 100 * (close - low_14) / (high_14 - low_14 + 1e-10)
stoch_d = stoch_k.rolling(3).mean()
df["stoch_k"] = stoch_k
df["stoch_d"] = stoch_d
df["stoch_diff"] = stoch_k - stoch_d
# ── Candle body / range features ────────────────────────────────────────
df["body"] = (close - open_).abs() / (high - low + 1e-10)
df["upper_wick"] = (high - close.clip(lower=open_)) / (high - low + 1e-10)
df["lower_wick"] = (close.clip(upper=open_) - low) / (high - low + 1e-10)
df["bar_dir"] = np.where(close > open_, 1.0, -1.0)
# ── Price position relative to EMAs ─────────────────────────────────────
df["close_vs_ema50_sign"] = np.where(close > ema_50, 1.0, -1.0)
df["close_vs_ema200_sign"] = np.where(close > ema_200, 1.0, -1.0)
# ── Lagged features (1-bar and 2-bar lags on key signals) ───────────────
for col in ["rsi_norm", "macd_hist_norm", "mom_4", "ema_cross", "natr", "bb_pos"]:
df[f"{col}_lag1"] = df[col].shift(1)
df[f"{col}_lag2"] = df[col].shift(2)
# ── Fill NaN from warm-up ────────────────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "NZD/USD EMA Cross + ATR Gradient Boosting",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.03,
"subsample": 0.8,
"min_samples_leaf": 20,
"max_features": "sqrt",
"validation_fraction": 0.1,
"n_iter_no_change": 30,
"tol": 1e-4,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.01,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": None,
"min_atr": None,
"trend_filter": None,
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe / Calmar). "
"GradientBoostingClassifier with moderate depth (4) and low learning rate (0.03) "
"to reduce overfitting on 15-min NZD/USD. SL=0.5%, TP=1.0% gives 1:2 RR. "
"EMA 50/200 cross is the primary trend feature; ATR normalises volatility context. "
"Supplementary RSI, MACD, Bollinger, Stochastic and candle-body features capture "
"momentum and mean-reversion signals. Early stopping via n_iter_no_change guards "
"against overfit on the training partition."
),
"notes": (
"target_horizon=4 (1 hour) matches typical intraday swing on NZD/USD. "
"reverse on opposite signal keeps the model responsive during trending regimes. "
"No session filter applied — NZD/USD has reasonable liquidity around the clock. "
"min_samples_leaf=20 and subsample=0.8 add regularisation without grid search."
),
}
|
||||||||||
|
1.29
|
EUR/USD EMA Cross + ATR Momentum (XGBoost)
Maximize risk-adjusted return (Sharpe) by combining EMA crossover trend regime with ATR-normalised volatility, RSI, MACD, and Bollinger feat…
|
R
@rapid-shark-854
|
EURUSD | 15min | 44.1%57.9% | +4.76%+1.48% | 1.593.83 | 2.55%2.55% | 6819 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:19:50
# Model : XGBoost
# Feature Eng. : EMA (50,200), ATR 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── EMA 50 / 200 and distance features ──────────────────────────────
ema_50 = close.ewm(span=50, adjust=False).mean()
ema_200 = close.ewm(span=200, adjust=False).mean()
df["ema_50"] = ema_50
df["ema_200"] = ema_200
df["dm_ema_50"] = (close - ema_50) / ema_50
df["dm_ema_200"] = (close - ema_200) / ema_200
# EMA cross signal: +1 when ema_50 > ema_200, -1 otherwise
df["ema_cross"] = np.where(ema_50 > ema_200, 1.0, -1.0)
# Spread between the two EMAs, normalised by price
df["ema_spread"] = (ema_50 - ema_200) / close
# Rate of change of ema_spread (momentum of the cross)
df["ema_spread_roc"] = df["ema_spread"].diff(4)
# ── ATR 14 & NATR ───────────────────────────────────────────────────
prev_close = close.shift(1)
tr = pd.concat([
high - low,
(high - prev_close).abs(),
(low - prev_close).abs()
], axis=1).max(axis=1)
atr = tr.ewm(span=14, adjust=False).mean()
natr = atr / close
df["atr"] = atr
df["natr"] = natr
# ── RSI 14 ───────────────────────────────────────────────────────────
delta = close.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(span=14, adjust=False).mean()
avg_loss = loss.ewm(span=14, adjust=False).mean()
rs = avg_gain / (avg_loss + 1e-12)
rsi = 100.0 - (100.0 / (1.0 + rs))
df["rsi_14"] = rsi
# Normalised RSI centred around 0
df["rsi_norm"] = (rsi - 50.0) / 50.0
# ── MACD (12/26/9) ───────────────────────────────────────────────────
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd = ema_12 - ema_26
signal = macd.ewm(span=9, adjust=False).mean()
df["macd"] = macd / close
df["macd_signal"] = signal / close
df["macd_hist"] = (macd - signal) / close
# ── Bollinger Bands (20, 2σ) ─────────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std(ddof=0)
bb_up = bb_mid + 2.0 * bb_std
bb_lo = bb_mid - 2.0 * bb_std
df["bb_width"] = (bb_up - bb_lo) / (bb_mid + 1e-12)
df["bb_pct"] = (close - bb_lo) / (bb_up - bb_lo + 1e-12)
# ── Price momentum (log-returns at multiple horizons) ────────────────
for lag in [1, 4, 8, 16]:
df[f"logret_{lag}"] = np.log(close / close.shift(lag))
# ── Volume-less volatility proxy: high-low range / ATR ───────────────
df["hl_range_norm"] = (high - low) / (atr + 1e-12)
# ── Candle body and shadow ratios ────────────────────────────────────
body = (close - open_).abs()
range_ = (high - low + 1e-12)
df["body_ratio"] = body / range_
df["upper_shadow_ratio"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / range_
df["lower_shadow_ratio"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / range_
# ── Trend strength: close relative to recent N-bar high/low ──────────
for window in [20, 50]:
roll_hi = high.rolling(window).max()
roll_lo = low.rolling(window).min()
denom = (roll_hi - roll_lo + 1e-12)
df[f"close_rank_{window}"] = (close - roll_lo) / denom
# ── EMA 50 slope (rate of change) ────────────────────────────────────
df["ema_50_slope"] = ema_50.diff(4) / (close + 1e-12)
df["ema_200_slope"] = ema_200.diff(8) / (close + 1e-12)
# ── Hour-of-day and day-of-week as cyclic features ───────────────────
if hasattr(df.index, "hour"):
hour = df.index.hour
dow = df.index.dayofweek
df["hour_sin"] = np.sin(2.0 * np.pi * hour / 24.0)
df["hour_cos"] = np.cos(2.0 * np.pi * hour / 24.0)
df["dow_sin"] = np.sin(2.0 * np.pi * dow / 5.0)
df["dow_cos"] = np.cos(2.0 * np.pi * dow / 5.0)
# ── Fill NaNs from indicator warm-up ────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EUR/USD EMA Cross + ATR Momentum (XGBoost)",
"model_type": "XGBClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 4,
"learning_rate": 0.04,
"subsample": 0.75,
"colsample_bytree": 0.75,
"min_child_weight": 3,
"gamma": 0.1,
"reg_alpha": 0.05,
"reg_lambda": 1.5,
"objective": "binary:logistic",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe) by combining EMA crossover "
"trend regime with ATR-normalised volatility, RSI, MACD, and Bollinger "
"features. XGBoost hyperparameters tuned for bias-variance balance: "
"moderate depth (4), aggressive shrinkage (lr=0.04), column/row "
"subsampling, and L1/L2 regularisation. SL=0.5% / TP=1.0% targets a "
"2:1 reward-risk ratio. Session filter [6,20] UTC focuses on the "
"liquid London/NY overlap. min_atr filters dead markets."
),
"notes": (
"EMA 50/200 cross provides the macro trend regime; distance features "
"capture how far price has stretched from trend. ATR/NATR quantifies "
"volatility regime. RSI, MACD histogram, and BB %b add mean-reversion "
"and momentum context. Candle body ratios encode micro-structure. "
"Cyclic time features allow the model to learn intraday seasonality. "
"target_horizon=4 bars (1 hour on 15-min data) balances trade frequency "
"against predictability. on_opposite=reverse reduces idle time and "
"captures trend continuation efficiently."
),
}
|
||||||||||
|
1.16
|
EMA Cross (9/21) + RSI Confirmation — XGBoost
Maximize risk-adjusted return (Sharpe / Calmar) on EUR/USD 15-min data. XGBoost with moderate depth (4) and heavy regularisation (gamma, alp…
|
S
@still-lynx-704
|
EURUSD | 15min | 43.6%52.6% | +5.16%+1.37% | 1.552.61 | 1.62%1.62% | 9419 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 01:39:22
# Model : XGBoost
# Feature Eng. : EMA (9,21), RSI 14 + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/EURUSD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── EMA 9 and EMA 21 ──────────────────────────────────────────────────────
ema_9 = close.ewm(span=9, adjust=False).mean()
ema_21 = close.ewm(span=21, adjust=False).mean()
df["ema_9"] = ema_9
df["ema_21"] = ema_21
df["dm_ema_9"] = (close - ema_9) / ema_9
df["dm_ema_21"] = (close - ema_21) / ema_21
# EMA cross signal: +1 when ema_9 > ema_21, -1 otherwise
df["ema_cross"] = np.where(ema_9 > ema_21, 1.0, -1.0)
# EMA cross momentum: difference normalised by ema_21
df["ema_spread"] = (ema_9 - ema_21) / ema_21
# Rate of change of EMA spread (1-bar and 3-bar)
df["ema_spread_chg1"] = df["ema_spread"].diff(1)
df["ema_spread_chg3"] = df["ema_spread"].diff(3)
# ── RSI 14 ────────────────────────────────────────────────────────────────
delta = close.diff(1)
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
avg_loss = loss.ewm(alpha=1/14, min_periods=14, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
rsi_14 = 100 - (100 / (1 + rs))
df["rsi_14"] = rsi_14
# RSI normalised to [-1, 1]
df["rsi_norm"] = (rsi_14 - 50) / 50
# RSI momentum
df["rsi_chg1"] = rsi_14.diff(1)
df["rsi_chg3"] = rsi_14.diff(3)
# RSI zone flags (overbought / oversold)
df["rsi_ob"] = np.where(rsi_14 > 70, 1.0, 0.0)
df["rsi_os"] = np.where(rsi_14 < 30, 1.0, 0.0)
# ── ATR 14 (for normalisation & volatility context) ───────────────────────
tr = pd.concat([
high - low,
(high - close.shift(1)).abs(),
(low - close.shift(1)).abs()
], axis=1).max(axis=1)
atr_14 = tr.ewm(span=14, adjust=False).mean()
df["atr_14"] = atr_14
df["natr_14"] = atr_14 / close # normalised ATR
# ── Price momentum features ───────────────────────────────────────────────
for n in [1, 3, 5, 10, 20]:
df[f"ret_{n}"] = close.pct_change(n)
# ── Volatility: rolling std of returns ───────────────────────────────────
ret1 = close.pct_change(1)
df["vol_5"] = ret1.rolling(5).std()
df["vol_20"] = ret1.rolling(20).std()
# ── Bollinger Band features (20, 2) ───────────────────────────────────────
bb_mid = close.rolling(20).mean()
bb_std = close.rolling(20).std()
bb_up = bb_mid + 2 * bb_std
bb_lo = bb_mid - 2 * bb_std
df["bb_pct"] = (close - bb_lo) / (bb_up - bb_lo).replace(0, np.nan)
df["bb_width"] = (bb_up - bb_lo) / bb_mid
# ── MACD-style: difference of EMA12 and EMA26 ────────────────────────────
ema_12 = close.ewm(span=12, adjust=False).mean()
ema_26 = close.ewm(span=26, adjust=False).mean()
macd = ema_12 - ema_26
signal = macd.ewm(span=9, adjust=False).mean()
df["macd"] = macd / close
df["macd_signal"] = signal / close
df["macd_hist"] = (macd - signal) / close
# ── High-Low channel position ─────────────────────────────────────────────
hh20 = high.rolling(20).max()
ll20 = low.rolling(20).min()
df["hl_pos_20"] = (close - ll20) / (hh20 - ll20).replace(0, np.nan)
hh5 = high.rolling(5).max()
ll5 = low.rolling(5).min()
df["hl_pos_5"] = (close - ll5) / (hh5 - ll5).replace(0, np.nan)
# ── Bar body & shadow features ────────────────────────────────────────────
body = (close - open_).abs()
range_ = (high - low).replace(0, np.nan)
df["body_ratio"] = body / range_
df["upper_shadow"] = (high - pd.concat([close, open_], axis=1).max(axis=1)) / range_
df["lower_shadow"] = (pd.concat([close, open_], axis=1).min(axis=1) - low) / range_
df["bull_bar"] = np.where(close > open_, 1.0, 0.0)
# ── Rolling correlation: EMA spread vs RSI (captures confluence) ──────────
df["corr_spread_rsi"] = df["ema_spread"].rolling(10).corr(rsi_14)
# ── Time-of-day features (hour & minute encoded cyclically) ───────────────
if hasattr(df.index, "hour"):
hour = df.index.hour
df["hour_sin"] = np.sin(2 * np.pi * hour / 24)
df["hour_cos"] = np.cos(2 * np.pi * hour / 24)
dow = df.index.dayofweek
df["dow_sin"] = np.sin(2 * np.pi * dow / 5)
df["dow_cos"] = np.cos(2 * np.pi * dow / 5)
# ── Fill NaN from indicator warm-up ──────────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "EMA Cross (9/21) + RSI Confirmation — XGBoost",
"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.10,
"reg_lambda": 1.50,
"objective": "binary:logistic",
"random_state": 42,
"n_jobs": -1,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [6, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximize risk-adjusted return (Sharpe / Calmar) on EUR/USD 15-min data. "
"XGBoost with moderate depth (4) and heavy regularisation (gamma, alpha, lambda) "
"to avoid overfitting on a 1-year window. "
"EMA cross provides trend direction; RSI filters against overbought/oversold entries. "
"Asymmetric TP/SL (2:1) boosts expectancy. Session filter restricts trading to "
"London + NY overlap (06–20 UTC) where EUR/USD liquidity is highest. "
"min_atr removes low-volatility bars where spreads erode edge."
),
"notes": (
"Features: EMA 9/21 cross & spread, RSI 14, MACD histogram, Bollinger Band %B, "
"ATR-normalised volatility, price momentum (1/3/5/10/20 bars), rolling vol, "
"high-low channel position, candlestick body/shadow ratios, cyclical time encoding. "
"Target horizon = 4 bars (1 hour ahead). Train/test split 70/30 (no leakage). "
"Cooldown = 0 because on_opposite='reverse' keeps the model always positioned "
"when high-confidence signals appear."
),
}
|
||||||||||
|
0.92
|
USD/CAD SMA Trend + Momentum XGBoost Scalper
Maximise risk-adjusted return on USD/CAD 15-min bars. XGBoost with deep feature set (multi-period SMA distances and crossovers, RSI, MACD, B…
|
D
@delta-atlas-858
|
USDCAD | 15min | 45.6%62.5% | +3.05%+1.02% | 1.462.88 | 1.99%1.99% | 578 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-05-06 02:13:41
# Model : XGBoost
# Feature Eng. : SMA (20,50,200) + Auto-add features: ON
# Signal / Entry : Enter when model confidence > threshold; exit on opposite signal or SL/TP
# Optimization : Maximize risk-adjusted return
# Risk Mgmt : Stop loss 0.5%, Take profit 1.0%
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_15min.parquet"
START_DATE = "2025-04-24"
END_DATE = "2026-04-24"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# ── SMA features (required) ──────────────────────────────────────────
for p in [20, 50, 200]:
sma = close.rolling(p).mean()
df[f"sma_{p}"] = sma
df[f"dm_sma_{p}"] = (close - sma) / sma
# ── SMA slope (momentum of the moving average itself) ────────────────
for p in [20, 50, 200]:
df[f"sma_{p}_slope"] = df[f"sma_{p}"].diff(5) / df[f"sma_{p}"].shift(5)
# ── SMA crossover signals ────────────────────────────────────────────
df["sma_20_50_cross"] = df["sma_20"] - df["sma_50"]
df["sma_50_200_cross"] = df["sma_50"] - df["sma_200"]
df["sma_20_200_cross"] = df["sma_20"] - df["sma_200"]
# ── Price momentum / rate of change ──────────────────────────────────
for p in [4, 8, 16, 32]:
df[f"roc_{p}"] = close.pct_change(p)
# ── RSI (manual, no external libs) ───────────────────────────────────
def calc_rsi(series, period=14):
delta = series.diff()
gain = delta.clip(lower=0)
loss = (-delta).clip(lower=0)
avg_gain = gain.ewm(alpha=1.0 / period, min_periods=period, adjust=False).mean()
avg_loss = loss.ewm(alpha=1.0 / period, min_periods=period, adjust=False).mean()
rs = avg_gain / avg_loss.replace(0, np.nan)
rsi = 100 - (100 / (1 + rs))
return rsi
for p in [9, 14, 21]:
df[f"rsi_{p}"] = calc_rsi(close, p)
df[f"rsi_{p}_norm"] = (df[f"rsi_{p}"] - 50) / 50 # centre around 0
# ── MACD (manual) ────────────────────────────────────────────────────
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
macd_line = ema12 - ema26
macd_signal = macd_line.ewm(span=9, adjust=False).mean()
df["macd"] = macd_line
df["macd_signal"] = macd_signal
df["macd_hist"] = macd_line - macd_signal
df["macd_hist_chg"] = df["macd_hist"].diff()
# ── Bollinger Bands ───────────────────────────────────────────────────
for p in [20, 50]:
mid = close.rolling(p).mean()
std = close.rolling(p).std()
df[f"bb_upper_{p}"] = mid + 2 * std
df[f"bb_lower_{p}"] = mid - 2 * std
denom = (df[f"bb_upper_{p}"] - df[f"bb_lower_{p}"]).replace(0, np.nan)
df[f"bb_pct_{p}"] = (close - df[f"bb_lower_{p}"]) / denom
df[f"bb_width_{p}"] = denom / mid
# ── ATR (manual) ─────────────────────────────────────────────────────
def calc_atr(h, l, c, period=14):
prev_c = c.shift(1)
tr = pd.concat([
h - l,
(h - prev_c).abs(),
(l - prev_c).abs()
], axis=1).max(axis=1)
return tr.ewm(alpha=1.0 / period, min_periods=period, adjust=False).mean()
for p in [7, 14]:
atr = calc_atr(high, low, close, p)
df[f"atr_{p}"] = atr
df[f"natr_{p}"] = atr / close # normalised ATR
# ── Candle body / wick features ───────────────────────────────────────
body = (close - open_).abs()
candle_rng = (high - low).replace(0, np.nan)
df["body_ratio"] = body / candle_rng
df["upper_wick"] = (high - np.maximum(close, open_)) / candle_rng
df["lower_wick"] = (np.minimum(close, open_) - low) / candle_rng
df["candle_dir"] = np.sign(close - open_)
# ── Rolling volatility ────────────────────────────────────────────────
log_ret = np.log(close / close.shift(1))
for p in [8, 16, 32]:
df[f"vol_{p}"] = log_ret.rolling(p).std()
# ── Volume (if available) — graceful fallback ─────────────────────────
if "volume" in df.columns and df["volume"].sum() > 0:
vol_ma = df["volume"].rolling(20).mean()
df["vol_ratio"] = df["volume"] / vol_ma.replace(0, np.nan)
else:
df["vol_ratio"] = 1.0
# ── Lagged returns ────────────────────────────────────────────────────
for lag in [1, 2, 3, 4, 8]:
df[f"ret_lag_{lag}"] = log_ret.shift(lag)
# ── Higher-timeframe SMA context (4-bar = 1h proxy) ──────────────────
close_1h = close.rolling(4).mean()
for p in [20, 50]:
sma_1h = close_1h.rolling(p).mean()
df[f"1h_dm_sma_{p}"] = (close_1h - sma_1h) / sma_1h
# ── Fill NaN from indicator warm-up ──────────────────────────────────
df = df.bfill().ffill()
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD SMA Trend + Momentum XGBoost Scalper",
"model_type": "XGBClassifier",
"model_params": {
"n_estimators": 600,
"max_depth": 4,
"learning_rate": 0.03,
"subsample": 0.75,
"colsample_bytree": 0.70,
"min_child_weight": 5,
"gamma": 0.2,
"reg_alpha": 0.1,
"reg_lambda": 1.5,
"objective": "binary:logistic",
"tree_method": "hist",
"random_state": 42,
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 0.005,
"take_profit": 0.010,
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [7, 20],
"min_atr": 0.0002,
"trend_filter": "sma_50",
"target_horizon": 4,
"objective": (
"Maximise risk-adjusted return on USD/CAD 15-min bars. "
"XGBoost with deep feature set (multi-period SMA distances and crossovers, "
"RSI, MACD, Bollinger Bands, ATR, candle structure, lagged returns). "
"Regularised tree ensemble (gamma, L1/L2, min_child_weight) prevents "
"overfitting on the ~1-year window. 2:1 TP:SL ratio locks in positive "
"expectancy; session filter restricts trading to liquid London/NY overlap."
),
"notes": (
"SMA-trio (20/50/200) distances are the primary trend-context features. "
"MACD histogram momentum + RSI multi-period confirm entry timing. "
"ATR normalisation makes volatility features scale-invariant. "
"sma_50 trend filter ensures long trades only above 50-SMA and shorts below, "
"aligning ML signals with dominant trend and improving Sharpe ratio."
),
}
|
||||||||||