MT5 Trading के लिए 5 ONNX Models: LSTM, XGBoost, CNN, Random Forest, Transformer
Trading के लिए पाँच machine learning architectures, पाँच real use cases, सभी ONNX में export किए जा सकते हैं और MT5 Expert Advisor में उपयोग किए जा सकते हैं।
⚠️ ईमानदार disclaimer: कोई भी model, कितना भी sophisticated हो, profit की guarantee नहीं देता। Professional और amateur trader के बीच का अंतर model में नहीं है — यह feature engineering, सख्त validation, risk management और discipline में है।
त्वरित तुलना
| Model | कब उपयोग | जटिलता | ONNX export |
|---|---|---|---|
| Random Forest | Baseline | कम | skl2onnx |
| XGBoost | Rich tabular features | मध्यम | onnxmltools |
| CNN 1D | Series में patterns | मध्यम | torch.onnx.export |
| LSTM/GRU | लंबी temporal dependencies | उच्च | torch.onnx.export |
| Transformer | Multi-asset, multi-feature | बहुत उच्च | torch.onnx.export |
1. Random Forest — ईमानदार baseline
Framework: Sklearn · Training: मिनट · Inference: < 1 ms
Binary direction classification या multi-class। पहला model जो हर AI-in-trading project को try करना चाहिए — यदि 200 trees वाला RF random (50%) से beat नहीं करता, problem features में है, model में नहीं। 1 मिनट में train।
from sklearn.ensemble import RandomForestClassifier
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
model = RandomForestClassifier(n_estimators=200, max_depth=8)
model.fit(X_train, y_train)
initial_type = [('input', FloatTensorType([None, n_features]))]
onnx_model = convert_sklearn(model, initial_types=initial_type, target_opset=15)
with open("rf.onnx", "wb") as f:
f.write(onnx_model.SerializeToString())
2. XGBoost — markets पर लागू Kaggle विजेता
Framework: XGBoost · Inference: ~1-3 ms
RF के समान लेकिन typically tabular problems पर 2-5% अधिक accurate। बहुत सारी features (50+ indicators, orderbook, sentiment) के साथ चमकता है। सावधान: time series पर overfit अधिक prone — early_stopping_rounds उपयोग करें।
import xgboost as xgb
from onnxmltools.convert import convert_xgboost
from onnxconverter_common.data_types import FloatTensorType
model = xgb.XGBClassifier(n_estimators=300, max_depth=6,
learning_rate=0.05, early_stopping_rounds=20)
model.fit(X_train, y_train, eval_set=[(X_val, y_val)])
3. CNN 1D — series में visual patterns खोजता है
Framework: PyTorch/TF · Inference: ~1-5 ms
Time series में local patterns identify करता है — ‘candle formations खोजने वाले scanner’ की तरह लेकिन patterns खुद सीखता है। 5-30 candle short-term patterns में अच्छा काम करता है, विशेषकर synthetic indices (Deriv V75) पर। LSTM से तेज़ train होता है।
import torch.nn as nn
class CNN1D(nn.Module):
def __init__(self, in_channels=4, seq_len=30, n_classes=2):
super().__init__()
self.conv1 = nn.Conv1d(in_channels, 32, kernel_size=5, padding=2)
self.conv2 = nn.Conv1d(32, 64, kernel_size=3, padding=1)
self.pool = nn.MaxPool1d(2)
self.fc = nn.Linear(64 * (seq_len // 4), n_classes)
def forward(self, x):
x = self.pool(torch.relu(self.conv1(x)))
x = self.pool(torch.relu(self.conv2(x)))
return self.fc(x.flatten(1))
4. LSTM / GRU — लंबी dependencies के लिए memory
Framework: PyTorch/TF · Inference: ~2-10 ms
Transformer से पहले time series के लिए ‘standard’ architecture। LSTM internal state (memory) रखता है, दर्जनों/सैकड़ों timesteps में information carry करता है। Swing trading H1/H4/D1 के लिए, धीरे बदलते volatility regimes के लिए useful। सावधान: data leakage आसानी से हो जाता है — हमेशा strict temporal split, कभी shuffle नहीं। GRU LSTM का सरल चचेरा भाई है।
5. Transformer — जब आपको और चाहिए
Framework: PyTorch · Inference: ~10-50 ms
NLP को dominate करने वाली architecture, time series के लिए adapt की गई (Informer, Autoformer, PatchTST)। सभी timesteps में simultaneously ‘attention’ relations सीखता है। Multi-asset में चमकता है (EURUSD predict करने के लिए EURUSD + DXY + gold + bonds + VIX एक साथ)।
⚠️ Reality check: Paper ‘Are Transformers Effective for Time Series Forecasting?’ (Zeng et al., AAAI 2023) ने दिखाया कि simple linear MLPs कभी-कभी Transformers को beat करते हैं। Hype के लिए Transformer उपयोग न करें।
अपने project के लिए कौन सा चुनें?
| आपकी स्थिति | शुरू करें |
|---|---|
| कभी AI train नहीं किया | Random Forest |
| RF है, improvement चाहिए | XGBoost |
| Visual patterns का संदेह | CNN 1D |
| Swing trading, लंबा context | LSTM या GRU |
| Multi-asset, complex features | Transformer |
| संदेह में | Random Forest (हमेशा) |
किसी भी model के लिए मानक pipeline
mt5.copy_rates_from_pos()के माध्यम से data collection- Feature engineering — lagged returns, indicators, context
- Temporal split 80/20 — कभी shuffle नहीं
- Train पर train, test holdout पर validate
- Framework exporter के साथ ONNX में export
- Python में onnxruntime से validate
- EA में #resource + OnnxCreateFromBuffer के माध्यम से embed
- MT5 Strategy Tester में backtest
- Risk management के साथ 30+ दिन demo trade
- Minimal stake के साथ live, gradual scaling
Universal सिद्धांत:
1. काम करने वाला simple model > काम कर सकने वाला complex model
2. Feature engineering architecture को 9/10 बार हराता है
3. Temporal validation पवित्र है — कभी shuffle नहीं
4. Professional backtest 6+ महीने out-of-sample उपयोग करता है
5. Risk management bad models से अधिक bots को मारता है
🚀 ONNX EA परीक्षण के लिए, मुफ्त Deriv MT5 डेमो ($10,000 वर्चुअल):
