A powerful, production-ready machine learning system for forecasting Forex prices using a stacked ensemble of Prophet, XGBoost, and LSTM models — with an auto-selected meta-model based on performance — deployed via a Flask web application that supports forecasting, plotting, trading (MT5), and trade log updates.
- Advanced Feature Engineering: Technical indicators, lag-based features, volatility, momentum, etc.
- Triple-Model Forecasting: Prophet (time-series), XGBoost (gradient boosting), LSTM (deep learning).
- Meta-Model Stacking: Best out of Ridge, Lasso, Random Forest, Gradient Boost selected via performance benchmarking.
- Quantile Prediction: Median, lower (10%), and upper (90%) quantile forecasts.
- Flask API: Routes for forecast, plotting, trading, and trade logging.
- Live Trading Enabled: Connected to MetaTrader5 for executing trades.
- OANDA Support: API integrated and secured via
.env.
Raw Data ──▶ FeatureEngineer ──▶ Train Prophet/XGBoost/LSTM ──▶ Stack with Meta-Model ──▶ Save Quantile Models ──▶ Forecast + Trade
| Model | Purpose |
|---|---|
| Prophet | Trend + Seasonality |
| XGBoost | Non-linear patterns |
| LSTM | Temporal dependencies |
Python,Pandas,NumPy,Scikit-learn,MatplotlibProphet,XGBoost,TensorFlow/KerasFlask,MetaTrader5,oandapyV20.envfor environment secretsjoblibfor saving models
├── run.py
├── models/
│ ├── prophet.pkl
│ ├── xgb.pkl
│ ├── lstm.h5
│ └── meta_model_rf.pkl
├── src/
│ ├── forecast.py
│ ├── features.py
│ ├── evaluate.py
│ ├── mt5.py
│ ├── utils.py
│ └── logger.py
├── templates/
├── .env
└── README.md
| Route | Method | Description |
|---|---|---|
/ |
GET | Health check. |
/forecast |
GET | Returns next 7-day forecast as JSON. |
/forecast/plot |
GET | Renders HTML plot with prediction & confidence. |
/trade |
GET/POST | Auto-trades based on model signals. |
/update-trades |
GET | Updates log of closed trades. |
Create a .env file with:
OANDA_API_KEY=your_oanda_api_key
MT5_LOGIN=your_mt5_login
MT5_PASSWORD=your_mt5_password
MT5_SERVER=your_mt5_server_name-
Clone the repo
git clone https://github.com/SteveParadox/TF_Analysis.git
-
Install dependencies
pip install -r requirements.txt
-
Create
.envfile (see above) -
Run Flask app
python run.py
{
"forecast": [
{
"Date": "2025-07-23",
"Predicted_Close": 1.0965,
"Lower_Band": 1.0930,
"Upper_Band": 1.0999
},
...
]
}-
Feature Engineering
- Technical indicators (RSI, MACD, Bollinger Bands)
- Lag features, rolling statistics
- Candlestick patterns
-
Base Models
- Trained independently on engineered features.
-
Meta-Model Selection
- Models: Ridge, Lasso, Random Forest, Gradient Boost
- Best model selected based on lowest validation MAE.
-
Quantile Stacking
- Three meta-models trained for 10%, 50%, 90% quantiles for confidence bands.
- Uses
MetaTrader5API. - Trades only on
EURUSDsymbol. - Uses forecast quantiles to place cautious limit orders.
- Can be extended for more strategies & risk management.
You can easily extend the system to:
- Add more base models (LightGBM, CatBoost)
- Use alternative data (news, sentiment)
- Deploy via Docker / AWS / Streamlit
- Enable backtesting or Telegram alerts
MIT License © SteveParadox