Auron logoAURON
Back to BlogEA Showcase

Building Aurum: A Deep Learning Trading System for Gold

A technical deep dive into LSTM-CNN neural networks for XAUUSD price forecasting

AT

Auron Trading

Trading Experts

January 16, 2026
5 min read

Expert Advisor Details

Auron AI

1.3.0


Figure 1: Appearance of Aurum AI on a live XAUUSD H1 Chart

Uploaded image

Get a free demo of Aurum AI on the MQL5 marketplace

Introduction: Why Deep Learning for Gold Trading?

Traditional technical analysis relies on hand-crafted indicators and rigid rules. Moving average crossovers, RSI overbought/oversold levels, MACD divergences - these tools have served traders for decades. But they share a fundamental limitation: they cannot adapt to changing market regimes or capture complex non-linear relationships in price data.

Deep learning offers a different approach. Instead of defining rules, we let the model discover patterns from historical data. Long Short-Term Memory (LSTM) networks excel at learning temporal dependencies in sequential data. Convolutional Neural Networks (CNN) extract local patterns and features. By combining both architectures, we can build a system that understands both the rhythm of price movement and the structure of market microstructure.

This article documents the complete technical implementation of Aurum, our deep learning trading system for XAUUSD (gold) on MetaTrader 5.


System Architecture Overview

Aurum consists of three main components:

  1. Data Pipeline - MQL5 scripts that export OHLCV data with 62 engineered features

  2. Training Pipeline - Python/TensorFlow code that trains dual neural networks

  3. Inference Engine - MQL5 Expert Advisor that runs ONNX models in real-time

The system operates on the H1 (hourly) timeframe, processing 30 bars of history to generate predictions. Two models work in parallel: a price predictor that forecasts the next price level, and a profitability classifier that estimates the probability of a profitable trade in each direction.

Uploaded image

Figure 2: Price prediction model performance on test data.


Feature Engineering: The 51-Feature Vector

Raw OHLCV data is insufficient for deep learning. The model needs meaningful features that capture different aspects of market behavior. Aurum extracts 51 features from each bar, organized into eight categories.

1. Price Dynamics (7 features)

Standard technical indicators form the foundation:

const string g_feature_names[NUM_FEATURES] = {
   "Volume", "BB_Upper", "RSI", "MACD", "MACD_Signal", 
   "MACD_Histogram", "OBV", ...
};

2. Advanced Volatility (3 features)

Beyond simple ATR, we compute Yang-Zhang, Parkinson, and Garman-Klass volatility estimators.

3. Candlestick Geometry (5 features)

Body_Range_Ratio, Upper_Wick_Ratio, Lower_Wick_Ratio, Relative_Body, Engulfing_Mag

4. Statistical Regime Detection (2 features)

// Hurst Exponent - measures persistence
// H > 0.5: trending | H < 0.5: mean-reverting | H = 0.5: random walk
double CalculateHurstExponent(int bar_index);

// Approximate Entropy - measures predictability
double CalculateApproxEntropy(int bar_index);

5. Cyclical Time Encoding (6 features)

// Sine/cosine encoding preserves cyclical continuity
features[FEAT_HOUR_SIN] = MathSin(2 * M_PI * hour / 24.0);
features[FEAT_HOUR_COS] = MathCos(2 * M_PI * hour / 24.0);

6. Cross-Asset Correlation (2 features)

Rolling correlation with XAGUSD (silver) and DXY (dollar index).

7. Order Flow Approximation (6 features)

Bar_Delta, Cum_Delta, Delta_Divergence, Tick_VWAP_Dist, Tick_Vol_Delta, Tick_Vol_Ratio

8. Price Level Memory (4 features)

Swing_High_Dist, Swing_Low_Dist, Bars_Since_High, Bars_Since_Low


Neural Network Architecture

Aurum uses a hybrid LSTM-CNN architecture:

def build_model(self):
    inputs = Input(shape=(30, 51), name='input')
    
    # LSTM Branch - temporal patterns
    lstm_out = LSTM(units=128, dropout=0.2)(inputs)
    
    # CNN Branch - spatial patterns  
    cnn_out = Conv1D(filters=128, kernel_size=3, activation='relu')(inputs)
    cnn_out = GlobalMaxPooling1D()(cnn_out)
    
    # Fusion Layer
    fused = Concatenate()([lstm_out, cnn_out])
    fused = Dense(64, activation='relu')(fused)
    fused = Dropout(0.2)(fused)
    
    outputs = Dense(1, activation='linear')(fused)
    
    return Model(inputs=inputs, outputs=outputs)
Uploaded image

Figure 3: Loss convergence showing no overfitting.


Training Results

MetricValue R-squared0.7845 MAPE5.15% RMSE (normalized)0.0141 Directional Accuracy52%

Backtest Results (2018-2025)

Profit Factor1.58 Max Drawdown8.35% Recovery Factor3.70 Total Trades48


ONNX Export for MetaTrader 5

TensorFlow models cannot run directly in MQL5. We export to ONNX format:

def export_onnx(self, output_path):
    # Create PyTorch equivalent and transfer weights
    pytorch_model = self._create_pytorch_model()
    self._transfer_weights_to_pytorch(pytorch_model)
    
    # Export with dynamic batch size
    torch.onnx.export(
        pytorch_model,
        torch.randn(1, 30, 51),
        output_path,
        input_names=['input'],
        output_names=['output'],
        opset_version=14,
        dynamic_axes={'input': {0: 'batch'}, 'output': {0: 'batch'}}
    )

Real-Time Inference in MQL5

The Expert Advisor loads ONNX models as embedded resources:

#resource "\\Models\\lstm_cnn_xauusd.onnx" as uchar PriceModelBuffer[]
#resource "\\Models\\profitability_classifier.onnx" as uchar ProfitModelBuffer[]
#resource "\\Models\\scalers.csv" as string ScalersCSV

int OnInit()
{
   g_price_model = OnnxCreateFromBuffer(PriceModelBuffer, ONNX_DEFAULT);
   g_profit_model = OnnxCreateFromBuffer(ProfitModelBuffer, ONNX_DEFAULT);
   
   ulong input_shape[] = {1, 30, 51};
   OnnxSetInputShape(g_price_model, 0, input_shape);
   
   return INIT_SUCCEEDED;
}

Feature Caching Optimization

Computing 51 features for 30 bars every tick would be expensive. Aurum uses a rolling cache:

float g_feature_cache[30][51];  // Rolling cache
int   g_cache_head = 0;         // Circular buffer head

void UpdateCache()
{
   // Only compute features for the NEW bar
   g_cache_head = (g_cache_head + 1) % 30;
   ComputeAndCacheBar(1, g_cache_head);  // O(1) instead of O(30)
}

Risk Management

input double InpRiskPercent = 1.0;      // Risk per trade (%)
input double InpMaxDailyLoss = 4.0;    // Max daily loss (%)
input double InpMaxDrawdown = 8.0;     // Max total drawdown (%)
input double InpATRMultiplierSL = 3.0; // Stop loss = 3x ATR
input double InpATRMultiplierTP = 6.0; // Take profit = 6x ATR

Aurum does NOT use martingale, grid, or averaging strategies. Each trade has defined risk.


Technical Requirements

  • Platform: MetaTrader 5

  • Symbol: XAUUSD

  • Timeframe: H1 (locked)

  • Minimum Deposit: $1,000 recommended


Conclusion

Aurum demonstrates that deep learning can be practically applied to algorithmic trading. The combination of LSTM for temporal patterns and CNN for feature extraction, trained on 59,000+ hours of gold price data, produces a system capable of identifying trading opportunities invisible to traditional technical analysis.

The system is not a guarantee of profits. Markets change, and past performance does not ensure future results. But for traders seeking a data-driven, machine learning approach to gold trading, Aurum provides a solid foundation.

Related Product

Aurum AI

Dual neural network gold trading system trained on 59,000+ hours of XAUUSD price action.

$599.00

View Product
Share this article

Auron Trading

Expert analysis and trading insights for quantitative traders.

⚠️ Trading involves risk. Past performance does not guarantee future results.