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 | ||
|---|---|---|---|---|---|---|---|---|---|---|
|
🥇
|
USD/CAD Trend Pullback: EMA 20/50 (RandomForest, 5m)
Trend Pullback strategy on USD/CAD 5min. Buy dips / sell rallies inside an established trend when the fast RSI resets. Features: EMA 20/50 c…
|
V
@vega-puma-338
|
USDCAD | 5min | 60.0%72.7% | +9.22%+12.03% | 3.474.32 | 1.32%1.32% | 1011 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:14:19
# Model : Random Forest
# Feature Eng. : EMA 20/50 cross, SMA 200, RSI 7, ATR 14, Keltner (20,2.0), EMA ribbon 8-55, Session/time features
# Signal / Entry : Buy dips / sell rallies inside an established trend when the fast RSI resets
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : session [7, 20] UTC, trend ema_50
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA 20/50 crossover ---
_ea = close.ewm(span=20, adjust=False).mean()
_eb = close.ewm(span=50, adjust=False).mean()
df["ema_20_50_diff"] = (_ea - _eb) / close * 1e4
df["ema_20_50_diff_chg"] = df["ema_20_50_diff"].diff(1)
df["ema_20_50_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_20_50_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_20"] = close / _ea - 1.0
# --- SMA(200) distance & slope ---
_s = close.rolling(200).mean()
df["sma_200_dist"] = close / _s - 1.0
df["sma_200_slope"] = _s.pct_change(3)
# --- RSI(7) with zone flags and slope ---
_d = close.diff()
_g = _d.clip(lower=0).ewm(com=6, min_periods=7, adjust=False).mean()
_l = (-_d.clip(upper=0)).ewm(com=6, min_periods=7, adjust=False).mean()
_rsi = 100.0 - 100.0 / (1.0 + _g / (_l + 1e-10))
df["rsi_7"] = _rsi
df["rsi_7_os"] = (_rsi < 30).astype(float)
df["rsi_7_ob"] = (_rsi > 70).astype(float)
df["rsi_7_slope"] = _rsi.diff(2)
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- Keltner channel(20,2.0) position ---
_kmid = close.ewm(span=20, adjust=False).mean()
_ktr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_katr = _ktr.ewm(alpha=1.0/20, adjust=False).mean()
df["kelt_20_pos"] = (close - _kmid) / (2.0 * _katr + 1e-12)
# --- EMA ribbon alignment (8/13/21/34/55) ---
_es = [close.ewm(span=_n, adjust=False).mean() for _n in (8, 13, 21, 34, 55)]
df["ribbon_align"] = sum(((_es[_i] > _es[_i + 1]).astype(float) * 2 - 1) for _i in range(4))
df["ribbon_spread"] = (_es[0] - _es[-1]) / close * 1e4
# --- Time-of-day / day-of-week (UTC) ---
_h = df.index.hour + df.index.minute / 60.0
df["hour_sin"] = np.sin(2 * np.pi * _h / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * _h / 24.0)
df["dow"] = df.index.dayofweek.astype(float)
df["london_open"] = ((df.index.hour >= 7) & (df.index.hour < 10)).astype(float)
df["ny_open"] = ((df.index.hour >= 13) & (df.index.hour < 16)).astype(float)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Trend Pullback Random Forest 5min",
"model_type": "RandomForestClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 5,
"min_samples_leaf": 5,
"max_features": "sqrt",
"random_state": 42,
"n_jobs": 1
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [
7,
20
],
"min_atr": None,
"trend_filter": "ema_50",
"target_horizon": 5,
"objective": "Trend Pullback strategy on USD/CAD 5min: Buy dips / sell rallies inside an established trend when the fast RSI resets. Features: EMA 20/50 cross, SMA 200, RSI 7, ATR 14, Keltner (20,2.0), EMA ribbon 8-55, Session/time features. Model: Random Forest. Label horizon 5 bars, confidence threshold 0.55, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
🥈
|
USD/CAD Trend: EMA 12/26 + ADX 20 (LogReg, 5m)
Trend strategy on USD/CAD 5min. Enter with the EMA crossover when ADX confirms a trend; the model gates each entry. Features: EMA 12/26 cros…
|
D
@delta-atlas-858
|
USDCAD | 5min | 50.0%60.0% | +6.81%+8.17% | 2.162.74 | 2.53%2.53% | 1210 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:33:05
# Model : Logistic Regression
# Feature Eng. : EMA 12/26 cross, ADX 20, ATR 14, ROC 20, EMA ribbon 8-55, Session/time features
# Signal / Entry : Enter in the direction of the EMA crossover when ADX confirms trend; model gates each entry
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : —, trend ema_50
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA 12/26 crossover ---
_ea = close.ewm(span=12, adjust=False).mean()
_eb = close.ewm(span=26, adjust=False).mean()
df["ema_12_26_diff"] = (_ea - _eb) / close * 1e4
df["ema_12_26_diff_chg"] = df["ema_12_26_diff"].diff(1)
df["ema_12_26_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_12_26_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_12"] = close / _ea - 1.0
# --- ADX(20) with +DI/-DI ---
_up = high.diff()
_dn = -low.diff()
_pdm = pd.Series(np.where((_up > _dn) & (_up > 0), _up, 0.0), index=df.index)
_ndm = pd.Series(np.where((_dn > _up) & (_dn > 0), _dn, 0.0), index=df.index)
_tr2 = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr2 = _tr2.ewm(alpha=1.0/20, adjust=False).mean()
_pdi = 100.0 * _pdm.ewm(alpha=1.0/20, adjust=False).mean() / (_atr2 + 1e-12)
_ndi = 100.0 * _ndm.ewm(alpha=1.0/20, adjust=False).mean() / (_atr2 + 1e-12)
_dx = 100.0 * (_pdi - _ndi).abs() / (_pdi + _ndi + 1e-12)
df["adx_20"] = _dx.ewm(alpha=1.0/20, adjust=False).mean()
df["di_diff_20"] = _pdi - _ndi
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- Rate of change(20) ---
df["roc_20"] = close.pct_change(20) * 1e4
# --- EMA ribbon alignment (8/13/21/34/55) ---
_es = [close.ewm(span=_n, adjust=False).mean() for _n in (8, 13, 21, 34, 55)]
df["ribbon_align"] = sum(((_es[_i] > _es[_i + 1]).astype(float) * 2 - 1) for _i in range(4))
df["ribbon_spread"] = (_es[0] - _es[-1]) / close * 1e4
# --- Time-of-day / day-of-week (UTC) ---
_h = df.index.hour + df.index.minute / 60.0
df["hour_sin"] = np.sin(2 * np.pi * _h / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * _h / 24.0)
df["dow"] = df.index.dayofweek.astype(float)
df["london_open"] = ((df.index.hour >= 7) & (df.index.hour < 10)).astype(float)
df["ny_open"] = ((df.index.hour >= 13) & (df.index.hour < 16)).astype(float)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Trend Logistic Regression 5min",
"model_type": "LogisticRegression",
"model_params": {
"C": 1.0,
"max_iter": 2000,
"random_state": 42
},
"signal_threshold": 0.55,
"direction": "short",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 1,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": None,
"min_atr": None,
"trend_filter": "ema_50",
"target_horizon": 4,
"objective": "Trend strategy on USD/CAD 5min: Enter in the direction of the EMA crossover when ADX confirms trend; model gates each entry. Features: EMA 12/26 cross, ADX 20, ATR 14, ROC 20, EMA ribbon 8-55, Session/time features. Model: Logistic Regression. Label horizon 4 bars, confidence threshold 0.55, direction short. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
🥉
|
USD/CAD Signal Mix: EMA ribbon 8-55 (Extra Trees, 5m)
Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: EMA ribbon 8-55, K…
|
D
@delta-atlas-858
|
USDCAD | 5min | 55.6%55.6% | +10.42%+10.42% | 2.242.24 | 2.53%2.53% | 1818 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-09 01:03:05
# Model : Extra Trees
# Feature Eng. : EMA ribbon 8-55, Keltner (20,1.5), MACD (12,26,9), Donchian 20, CCI 14, ROC 3
# Signal / Entry : API-default style: randomly composed indicator set, model learns the rule
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : session [7, 17] UTC
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-31"
END_DATE = "2026-09-09"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA ribbon alignment (8/13/21/34/55) ---
_es = [close.ewm(span=_n, adjust=False).mean() for _n in (8, 13, 21, 34, 55)]
df["ribbon_align"] = sum(((_es[_i] > _es[_i + 1]).astype(float) * 2 - 1) for _i in range(4))
df["ribbon_spread"] = (_es[0] - _es[-1]) / close * 1e4
# --- Keltner channel(20,1.5) position ---
_kmid = close.ewm(span=20, adjust=False).mean()
_ktr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_katr = _ktr.ewm(alpha=1.0/20, adjust=False).mean()
df["kelt_20_pos"] = (close - _kmid) / (1.5 * _katr + 1e-12)
# --- MACD(12,26,9) ---
_m = close.ewm(span=12, adjust=False).mean() - close.ewm(span=26, adjust=False).mean()
_sig = _m.ewm(span=9, adjust=False).mean()
df["macd_12_26"] = _m / close * 1e4
df["macd_12_26_sig"] = _sig / close * 1e4
df["macd_12_26_hist"] = (_m - _sig) / close * 1e4
df["macd_12_26_hist_chg"] = df["macd_12_26_hist"].diff(1)
# --- Donchian channel(20) position & breakout ---
_dh = high.rolling(20).max().shift(1)
_dl = low.rolling(20).min().shift(1)
df["donch_20_pos"] = (close - _dl) / (_dh - _dl + 1e-10)
df["donch_20_break_up"] = (close > _dh).astype(float)
df["donch_20_break_dn"] = (close < _dl).astype(float)
# --- CCI(14) ---
_tp = (high + low + close) / 3.0
_tpm = _tp.rolling(14).mean()
_md = (_tp - _tpm).abs().rolling(14).mean()
df["cci_14"] = (_tp - _tpm) / (0.015 * _md + 1e-12)
# --- Rate of change(3) ---
df["roc_3"] = close.pct_change(3) * 1e4
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Random Mix Extra Trees 5min",
"model_type": "ExtraTreesClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 8,
"min_samples_leaf": 5,
"max_features": "sqrt",
"random_state": 42,
"n_jobs": 1
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 2,
"max_positions": 1,
"on_opposite": "close_only",
"session_filter": [
7,
17
],
"min_atr": None,
"trend_filter": None,
"target_horizon": 4,
"objective": "Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: EMA ribbon 8-55, Keltner (20,1.5), MACD (12,26,9), Donchian 20, CCI 14, ROC 3. Model: Extra Trees. Label horizon 4 bars, confidence threshold 0.55, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
4.42
|
USD/CAD Signal Mix: ADX 14 + BB (10,2.0) (LightGBM, 5m)
Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: ADX 14, Return lag…
|
R
@rapid-shark-854
|
USDCAD | 5min | 48.4%48.4% | +14.32%+14.32% | 2.282.28 | 3.58%3.58% | 3131 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-09 01:03:13
# Model : LightGBM
# Feature Eng. : ADX 14, Return lags 1-8, BB (10,2.0), ATR 14, Volatility 50
# Signal / Entry : API-default style: randomly composed indicator set, model learns the rule
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : session [7, 17] UTC, trend sma_100
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-31"
END_DATE = "2026-09-09"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- ADX(14) with +DI/-DI ---
_up = high.diff()
_dn = -low.diff()
_pdm = pd.Series(np.where((_up > _dn) & (_up > 0), _up, 0.0), index=df.index)
_ndm = pd.Series(np.where((_dn > _up) & (_dn > 0), _dn, 0.0), index=df.index)
_tr2 = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr2 = _tr2.ewm(alpha=1.0/14, adjust=False).mean()
_pdi = 100.0 * _pdm.ewm(alpha=1.0/14, adjust=False).mean() / (_atr2 + 1e-12)
_ndi = 100.0 * _ndm.ewm(alpha=1.0/14, adjust=False).mean() / (_atr2 + 1e-12)
_dx = 100.0 * (_pdi - _ndi).abs() / (_pdi + _ndi + 1e-12)
df["adx_14"] = _dx.ewm(alpha=1.0/14, adjust=False).mean()
df["di_diff_14"] = _pdi - _ndi
# --- Return lags 1..8 ---
_r = close.pct_change() * 1e4
for _i in range(1, 9):
df[f"ret_lag_{_i}"] = _r.shift(_i - 1)
df["ret_sum_8"] = _r.rolling(8).sum()
# --- Bollinger Bands(10,2.0) ---
_mid = close.rolling(10).mean()
_sd = close.rolling(10).std()
df["bb_10_2p0_pctb"] = (close - (_mid - 2.0 * _sd)) / (2 * 2.0 * _sd + 1e-10)
df["bb_10_2p0_width"] = (2 * 2.0 * _sd) / (_mid + 1e-10)
df["bb_10_2p0_width_chg"] = df["bb_10_2p0_width"].pct_change(3)
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- Realised volatility(50) ---
_r2 = close.pct_change()
df["vol_50"] = _r2.rolling(50).std() * 1e4
df["vol_50_ratio"] = df["vol_50"] / (_r2.rolling(200).std() * 1e4 + 1e-9)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Random Mix LightGBM 5min",
"model_type": "LGBMClassifier",
"model_params": {
"n_estimators": 200,
"num_leaves": 31,
"learning_rate": 0.05,
"subsample": 0.8,
"subsample_freq": 1,
"colsample_bytree": 0.8,
"min_child_samples": 40,
"reg_lambda": 1.0,
"random_state": 42,
"n_jobs": 1,
"verbose": -1
},
"signal_threshold": 0.58,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [
7,
17
],
"min_atr": None,
"trend_filter": "sma_100",
"target_horizon": 6,
"objective": "Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: ADX 14, Return lags 1-8, BB (10,2.0), ATR 14, Volatility 50. Model: LightGBM. Label horizon 6 bars, confidence threshold 0.58, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
2.35
|
USD/CAD Trend Pullback: EMA 20/50 + SMA 200 (XGBoost, 5m)
Trend Pullback strategy on USD/CAD 5min. Buy dips / sell rallies inside an established trend when the fast RSI resets. Features: EMA 20/50 c…
|
C
@candle_owl
|
USDCAD | 5min | 52.9%44.7% | +14.12%+11.73% | 2.241.85 | 2.30%2.30% | 3438 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:33:05
# Model : XGBoost
# Feature Eng. : EMA 20/50 cross, SMA 200, RSI 7, ATR 14, Keltner (20,2.0), EMA ribbon 8-55, Session/time features
# Signal / Entry : Buy dips / sell rallies inside an established trend when the fast RSI resets
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : —, trend sma_200
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA 20/50 crossover ---
_ea = close.ewm(span=20, adjust=False).mean()
_eb = close.ewm(span=50, adjust=False).mean()
df["ema_20_50_diff"] = (_ea - _eb) / close * 1e4
df["ema_20_50_diff_chg"] = df["ema_20_50_diff"].diff(1)
df["ema_20_50_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_20_50_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_20"] = close / _ea - 1.0
# --- SMA(200) distance & slope ---
_s = close.rolling(200).mean()
df["sma_200_dist"] = close / _s - 1.0
df["sma_200_slope"] = _s.pct_change(3)
# --- RSI(7) with zone flags and slope ---
_d = close.diff()
_g = _d.clip(lower=0).ewm(com=6, min_periods=7, adjust=False).mean()
_l = (-_d.clip(upper=0)).ewm(com=6, min_periods=7, adjust=False).mean()
_rsi = 100.0 - 100.0 / (1.0 + _g / (_l + 1e-10))
df["rsi_7"] = _rsi
df["rsi_7_os"] = (_rsi < 30).astype(float)
df["rsi_7_ob"] = (_rsi > 70).astype(float)
df["rsi_7_slope"] = _rsi.diff(2)
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- Keltner channel(20,2.0) position ---
_kmid = close.ewm(span=20, adjust=False).mean()
_ktr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_katr = _ktr.ewm(alpha=1.0/20, adjust=False).mean()
df["kelt_20_pos"] = (close - _kmid) / (2.0 * _katr + 1e-12)
# --- EMA ribbon alignment (8/13/21/34/55) ---
_es = [close.ewm(span=_n, adjust=False).mean() for _n in (8, 13, 21, 34, 55)]
df["ribbon_align"] = sum(((_es[_i] > _es[_i + 1]).astype(float) * 2 - 1) for _i in range(4))
df["ribbon_spread"] = (_es[0] - _es[-1]) / close * 1e4
# --- Time-of-day / day-of-week (UTC) ---
_h = df.index.hour + df.index.minute / 60.0
df["hour_sin"] = np.sin(2 * np.pi * _h / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * _h / 24.0)
df["dow"] = df.index.dayofweek.astype(float)
df["london_open"] = ((df.index.hour >= 7) & (df.index.hour < 10)).astype(float)
df["ny_open"] = ((df.index.hour >= 13) & (df.index.hour < 16)).astype(float)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Trend Pullback XGBoost 5min",
"model_type": "XGBClassifier",
"model_params": {
"n_estimators": 150,
"max_depth": 5,
"learning_rate": 0.03,
"subsample": 0.9,
"colsample_bytree": 0.6,
"min_child_weight": 3,
"reg_lambda": 1.0,
"gamma": 0.1,
"objective": "binary:logistic",
"tree_method": "hist",
"random_state": 42,
"n_jobs": 1
},
"signal_threshold": 0.55,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 1,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": None,
"min_atr": None,
"trend_filter": "sma_200",
"target_horizon": 10,
"objective": "Trend Pullback strategy on USD/CAD 5min: Buy dips / sell rallies inside an established trend when the fast RSI resets. Features: EMA 20/50 cross, SMA 200, RSI 7, ATR 14, Keltner (20,2.0), EMA ribbon 8-55, Session/time features. Model: XGBoost. Label horizon 10 bars, confidence threshold 0.55, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
2.03
|
USD/CAD Signal Mix: EMA 12/26 (RandomForest, 5m)
Signal Mix strategy on USD/CAD 5min. A compact, machine-selected indicator set; the classifier learns the entry rule directly from the featu…
|
V
@vol_drifter
|
USDCAD | 5min | 63.6%54.5% | +10.41%+4.71% | 3.191.82 | 2.29%2.29% | 1111 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:14:19
# Model : Random Forest
# Feature Eng. : EMA 12/26 cross, Donchian 20, Return lags 1-3, EMA ribbon 8-55, Candle structure
# Signal / Entry : API-default style: randomly composed indicator set, model learns the rule
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : session [7, 20] UTC, trend sma_100
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- EMA 12/26 crossover ---
_ea = close.ewm(span=12, adjust=False).mean()
_eb = close.ewm(span=26, adjust=False).mean()
df["ema_12_26_diff"] = (_ea - _eb) / close * 1e4
df["ema_12_26_diff_chg"] = df["ema_12_26_diff"].diff(1)
df["ema_12_26_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_12_26_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_12"] = close / _ea - 1.0
# --- Donchian channel(20) position & breakout ---
_dh = high.rolling(20).max().shift(1)
_dl = low.rolling(20).min().shift(1)
df["donch_20_pos"] = (close - _dl) / (_dh - _dl + 1e-10)
df["donch_20_break_up"] = (close > _dh).astype(float)
df["donch_20_break_dn"] = (close < _dl).astype(float)
# --- Return lags 1..3 ---
_r = close.pct_change() * 1e4
for _i in range(1, 4):
df[f"ret_lag_{_i}"] = _r.shift(_i - 1)
df["ret_sum_3"] = _r.rolling(3).sum()
# --- EMA ribbon alignment (8/13/21/34/55) ---
_es = [close.ewm(span=_n, adjust=False).mean() for _n in (8, 13, 21, 34, 55)]
df["ribbon_align"] = sum(((_es[_i] > _es[_i + 1]).astype(float) * 2 - 1) for _i in range(4))
df["ribbon_spread"] = (_es[0] - _es[-1]) / close * 1e4
# --- Candle structure ---
_rng = (high - low) + 1e-12
df["body"] = (close - open_) / _rng
df["upper_wick"] = (high - np.maximum(close, open_)) / _rng
df["lower_wick"] = (np.minimum(close, open_) - low) / _rng
df["range_pct"] = _rng / close
df["range_rel"] = _rng / (_rng.rolling(20).mean() + 1e-12)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Random Mix Random Forest 5min",
"model_type": "RandomForestClassifier",
"model_params": {
"n_estimators": 200,
"max_depth": 5,
"min_samples_leaf": 10,
"max_features": "sqrt",
"random_state": 42,
"n_jobs": 1
},
"signal_threshold": 0.58,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": [
7,
20
],
"min_atr": None,
"trend_filter": "sma_100",
"target_horizon": 18,
"objective": "Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: EMA 12/26 cross, Donchian 20, Return lags 1-3, EMA ribbon 8-55, Candle structure. Model: Random Forest. Label horizon 18 bars, confidence threshold 0.58, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
0.46
|
USD/CAD Multi-Indicator: RSI 14 + MACD (GradBoost, 5m)
Multi-Indicator strategy on USD/CAD 5min. Broad indicator set; the gradient-boosted model learns the entry rule. Features: RSI 14, MACD (12,…
|
P
@pivot_kid
|
USDCAD | 5min | 50.0%46.2% | +3.50%+2.59% | 1.511.33 | 2.31%2.31% | 1213 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:14:19
# Model : Gradient Boosting
# Feature Eng. : RSI 14, MACD (12,26,9), BB (20,2.0), Stochastic (14,3), ATR 14, ADX 14, EMA 9/21 cross, Candle structure, Return lags 1-3, Session/time features
# Signal / Entry : Broad indicator set; gradient-boosted model learns the entry rule
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : —
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- RSI(14) with zone flags and slope ---
_d = close.diff()
_g = _d.clip(lower=0).ewm(com=13, min_periods=14, adjust=False).mean()
_l = (-_d.clip(upper=0)).ewm(com=13, min_periods=14, adjust=False).mean()
_rsi = 100.0 - 100.0 / (1.0 + _g / (_l + 1e-10))
df["rsi_14"] = _rsi
df["rsi_14_os"] = (_rsi < 30).astype(float)
df["rsi_14_ob"] = (_rsi > 70).astype(float)
df["rsi_14_slope"] = _rsi.diff(2)
# --- MACD(12,26,9) ---
_m = close.ewm(span=12, adjust=False).mean() - close.ewm(span=26, adjust=False).mean()
_sig = _m.ewm(span=9, adjust=False).mean()
df["macd_12_26"] = _m / close * 1e4
df["macd_12_26_sig"] = _sig / close * 1e4
df["macd_12_26_hist"] = (_m - _sig) / close * 1e4
df["macd_12_26_hist_chg"] = df["macd_12_26_hist"].diff(1)
# --- Bollinger Bands(20,2.0) ---
_mid = close.rolling(20).mean()
_sd = close.rolling(20).std()
df["bb_20_2p0_pctb"] = (close - (_mid - 2.0 * _sd)) / (2 * 2.0 * _sd + 1e-10)
df["bb_20_2p0_width"] = (2 * 2.0 * _sd) / (_mid + 1e-10)
df["bb_20_2p0_width_chg"] = df["bb_20_2p0_width"].pct_change(3)
# --- Stochastic(14,3) ---
_ll = low.rolling(14).min()
_hh = high.rolling(14).max()
_k = 100.0 * (close - _ll) / (_hh - _ll + 1e-10)
df["stoch_k_14"] = _k
df["stoch_d_14"] = _k.rolling(3).mean()
df["stoch_14_diff"] = df["stoch_k_14"] - df["stoch_d_14"]
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- ADX(14) with +DI/-DI ---
_up = high.diff()
_dn = -low.diff()
_pdm = pd.Series(np.where((_up > _dn) & (_up > 0), _up, 0.0), index=df.index)
_ndm = pd.Series(np.where((_dn > _up) & (_dn > 0), _dn, 0.0), index=df.index)
_tr2 = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr2 = _tr2.ewm(alpha=1.0/14, adjust=False).mean()
_pdi = 100.0 * _pdm.ewm(alpha=1.0/14, adjust=False).mean() / (_atr2 + 1e-12)
_ndi = 100.0 * _ndm.ewm(alpha=1.0/14, adjust=False).mean() / (_atr2 + 1e-12)
_dx = 100.0 * (_pdi - _ndi).abs() / (_pdi + _ndi + 1e-12)
df["adx_14"] = _dx.ewm(alpha=1.0/14, adjust=False).mean()
df["di_diff_14"] = _pdi - _ndi
# --- EMA 9/21 crossover ---
_ea = close.ewm(span=9, adjust=False).mean()
_eb = close.ewm(span=21, adjust=False).mean()
df["ema_9_21_diff"] = (_ea - _eb) / close * 1e4
df["ema_9_21_diff_chg"] = df["ema_9_21_diff"].diff(1)
df["ema_9_21_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_9_21_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_9"] = close / _ea - 1.0
# --- Candle structure ---
_rng = (high - low) + 1e-12
df["body"] = (close - open_) / _rng
df["upper_wick"] = (high - np.maximum(close, open_)) / _rng
df["lower_wick"] = (np.minimum(close, open_) - low) / _rng
df["range_pct"] = _rng / close
df["range_rel"] = _rng / (_rng.rolling(20).mean() + 1e-12)
# --- Return lags 1..3 ---
_r = close.pct_change() * 1e4
for _i in range(1, 4):
df[f"ret_lag_{_i}"] = _r.shift(_i - 1)
df["ret_sum_3"] = _r.rolling(3).sum()
# --- Time-of-day / day-of-week (UTC) ---
_h = df.index.hour + df.index.minute / 60.0
df["hour_sin"] = np.sin(2 * np.pi * _h / 24.0)
df["hour_cos"] = np.cos(2 * np.pi * _h / 24.0)
df["dow"] = df.index.dayofweek.astype(float)
df["london_open"] = ((df.index.hour >= 7) & (df.index.hour < 10)).astype(float)
df["ny_open"] = ((df.index.hour >= 13) & (df.index.hour < 16)).astype(float)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Multi-Indicator Gradient Boosting 5min",
"model_type": "GradientBoostingClassifier",
"model_params": {
"n_estimators": 150,
"max_depth": 3,
"learning_rate": 0.03,
"subsample": 0.8,
"random_state": 42
},
"signal_threshold": 0.6,
"direction": "long",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 0,
"max_positions": 1,
"on_opposite": "reverse",
"session_filter": None,
"min_atr": None,
"trend_filter": None,
"target_horizon": 6,
"objective": "Multi-Indicator strategy on USD/CAD 5min: Broad indicator set; gradient-boosted model learns the entry rule. Features: RSI 14, MACD (12,26,9), BB (20,2.0), Stochastic (14,3), ATR 14, ADX 14, EMA 9/21 cross, Candle structure, Return lags 1-3, Session/time features. Model: Gradient Boosting. Label horizon 6 bars, confidence threshold 0.60, direction long. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
0.45
|
USD/CAD Signal Mix: Volatility 20 + RetLags3 (LogReg, 5m)
Signal Mix strategy on USD/CAD 5min. A compact, machine-selected indicator set; the classifier learns the entry rule directly from the featu…
|
S
@silver-bull-130
|
USDCAD | 5min | 50.0%39.1% | +8.29%+4.06% | 1.951.33 | 3.41%3.41% | 1623 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:33:05
# Model : Logistic Regression
# Feature Eng. : Volatility 20, Return lags 1-3, CCI 14, ATR 20
# Signal / Entry : API-default style: randomly composed indicator set, model learns the rule
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : session [7, 20] UTC, trend sma_100
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- Realised volatility(20) ---
_r2 = close.pct_change()
df["vol_20"] = _r2.rolling(20).std() * 1e4
df["vol_20_ratio"] = df["vol_20"] / (_r2.rolling(80).std() * 1e4 + 1e-9)
# --- Return lags 1..3 ---
_r = close.pct_change() * 1e4
for _i in range(1, 4):
df[f"ret_lag_{_i}"] = _r.shift(_i - 1)
df["ret_sum_3"] = _r.rolling(3).sum()
# --- CCI(14) ---
_tp = (high + low + close) / 3.0
_tpm = _tp.rolling(14).mean()
_md = (_tp - _tpm).abs().rolling(14).mean()
df["cci_14"] = (_tp - _tpm) / (0.015 * _md + 1e-12)
# --- ATR(20) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/20, adjust=False).mean()
df["atr_20_pct"] = _atr / close
df["atr_20_ratio"] = _atr / (_atr.rolling(80).mean() + 1e-12)
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD Random Mix Logistic Regression 5min",
"model_type": "LogisticRegression",
"model_params": {
"C": 0.3,
"max_iter": 2000,
"random_state": 42
},
"signal_threshold": 0.52,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 2,
"max_positions": 1,
"on_opposite": "close_only",
"session_filter": [
7,
20
],
"min_atr": None,
"trend_filter": "sma_100",
"target_horizon": 18,
"objective": "Random Mix strategy on USD/CAD 5min: API-default style: randomly composed indicator set, model learns the rule. Features: Volatility 20, Return lags 1-3, CCI 14, ATR 20. Model: Logistic Regression. Label horizon 18 bars, confidence threshold 0.52, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||
|
0.23
|
USD/CAD MACD Momentum: MACD + RSI 14 (ExtraTrees, 5m)
MACD Momentum strategy on USD/CAD 5min. MACD histogram turns with RSI confirmation; a long-term EMA gives regime context. Features: MACD (8,…
|
R
@ratio_witch
|
USDCAD | 5min | 47.1%37.5% | +9.82%+3.10% | 2.331.23 | 3.83%3.83% | 1724 |
|
# ╔══════════════════════════════════════════════════════════════╗
# ║ STRATEGY REQUEST LOG ║
# ╚══════════════════════════════════════════════════════════════╝
# Generated : 2026-09-06 15:33:05
# Model : Extra Trees
# Feature Eng. : MACD (8,21,5), RSI 14, ATR 14, EMA 50/200 cross, Return lags 1-4
# Signal / Entry : MACD histogram turn with RSI confirmation; long-term EMA gives regime context
# Optimization : Maximize out-of-sample return with a 70/30 holdout
# Risk Mgmt : Stop loss 15 pips, Take profit 30 pips
# Risk Filter : —, trend ema_200
# ══════════════════════════════════════════════════════════════
# ============================================================
# SECTION 0 — IMPORTS & CONSTANTS
import numpy as np
import pandas as pd
DATA_PATH = "/root/Desktop/QuantifyMe/data/ohlc/USDCAD_5min.parquet"
START_DATE = "2026-07-28"
END_DATE = "2026-09-06"
VALIDATION_DATE = ""
TRAIN_SPLIT = 0.7
LEVERAGE = 30.0
LOTS = 1.0
BALANCE = 10000.0
RISK_UNIT = 'pips'
STOP_LOSS = 15.0
TAKE_PROFIT = 30.0
AUX_FEEDS = []
# SECTION 1 — FEATURE ENGINEERING
def feature_engineering(df, close, open_, high, low):
# --- MACD(8,21,5) ---
_m = close.ewm(span=8, adjust=False).mean() - close.ewm(span=21, adjust=False).mean()
_sig = _m.ewm(span=5, adjust=False).mean()
df["macd_8_21"] = _m / close * 1e4
df["macd_8_21_sig"] = _sig / close * 1e4
df["macd_8_21_hist"] = (_m - _sig) / close * 1e4
df["macd_8_21_hist_chg"] = df["macd_8_21_hist"].diff(1)
# --- RSI(14) with zone flags and slope ---
_d = close.diff()
_g = _d.clip(lower=0).ewm(com=13, min_periods=14, adjust=False).mean()
_l = (-_d.clip(upper=0)).ewm(com=13, min_periods=14, adjust=False).mean()
_rsi = 100.0 - 100.0 / (1.0 + _g / (_l + 1e-10))
df["rsi_14"] = _rsi
df["rsi_14_os"] = (_rsi < 30).astype(float)
df["rsi_14_ob"] = (_rsi > 70).astype(float)
df["rsi_14_slope"] = _rsi.diff(2)
# --- ATR(14) normalised ---
_tr = pd.concat([high - low, (high - close.shift(1)).abs(), (low - close.shift(1)).abs()], axis=1).max(axis=1)
_atr = _tr.ewm(alpha=1.0/14, adjust=False).mean()
df["atr_14_pct"] = _atr / close
df["atr_14_ratio"] = _atr / (_atr.rolling(56).mean() + 1e-12)
# --- EMA 50/200 crossover ---
_ea = close.ewm(span=50, adjust=False).mean()
_eb = close.ewm(span=200, adjust=False).mean()
df["ema_50_200_diff"] = (_ea - _eb) / close * 1e4
df["ema_50_200_diff_chg"] = df["ema_50_200_diff"].diff(1)
df["ema_50_200_cross_up"] = ((_ea > _eb) & (_ea.shift(1) <= _eb.shift(1))).astype(float)
df["ema_50_200_cross_dn"] = ((_ea < _eb) & (_ea.shift(1) >= _eb.shift(1))).astype(float)
df["close_vs_ema_50"] = close / _ea - 1.0
# --- Return lags 1..4 ---
_r = close.pct_change() * 1e4
for _i in range(1, 5):
df[f"ret_lag_{_i}"] = _r.shift(_i - 1)
df["ret_sum_4"] = _r.rolling(4).sum()
# Fill indicator warm-up gaps without looking ahead
df = df.ffill().fillna(0.0)
return df
# SECTION 2 — STRATEGY CONFIG
def strategy_config():
return {
"title": "USD/CAD MACD Momentum Extra Trees 5min",
"model_type": "ExtraTreesClassifier",
"model_params": {
"n_estimators": 400,
"max_depth": 10,
"min_samples_leaf": 5,
"max_features": "sqrt",
"random_state": 42,
"n_jobs": 1
},
"signal_threshold": 0.52,
"direction": "both",
"stop_loss": 15.0,
"take_profit": 30.0,
"risk_unit": "pips",
"cooldown": 0,
"max_positions": 1,
"on_opposite": "close_only",
"session_filter": None,
"min_atr": None,
"trend_filter": "ema_200",
"target_horizon": 6,
"objective": "MACD Momentum strategy on USD/CAD 5min: MACD histogram turn with RSI confirmation; long-term EMA gives regime context. Features: MACD (8,21,5), RSI 14, ATR 14, EMA 50/200 cross, Return lags 1-4. Model: Extra Trees. Label horizon 6 bars, confidence threshold 0.52, direction both. Risk: 15 pip stop / 30 pip target (1:2 R/R), 1.0 lot on $10k, $6 round-trip commission.",
"notes": "Generated by the QuantifyMe strategy forge. SL/TP are in pips and match the dashboard defaults, so pasting this code into the Code tab reproduces the published backtest on the same window."
}
|
||||||||||