Discussing the article: "Combining 3D Bars, Quantum Computing, and Machine Learning into a Unified Trading System"

 

Check out the new article: Combining 3D Bars, Quantum Computing, and Machine Learning into a Unified Trading System.

The article presents the full integration of the 3D-bar module into a quantum-enhanced trading system for forecasting the movement of currency pairs. The system combines stationary four-dimensional features, an 8-qubit quantum encoder, and CatBoost gradient boosting with 52+ features. The system is implemented in Python using MetaTrader 5, Qiskit, CatBoost, and optional integration with the Llama 3.2 LLM for interpreting forecasts.

In previous articles, we explored the use of quantum computing to extract nonlinear correlations from market data, as well as the integration of language models with the CatBoost model. The forecast accuracy was 62.4% in cross-validation, which yielded a return of +27.39% over the one-month backtesting period on a USD 140 micro account.

However, the analysis showed that the system overlooks critically important information — the multidimensional structure of the interplay between price, time, and volume. Classic indicators operate on market projections onto two-dimensional charts, losing the broader multidimensional view of market activity. This article describes the full integration of the 3D-bar module into a quantum-enhanced trading system.


Author: Yevgeniy Koshtenko

 


bar3d_yellow_cluster is in last place. What’s gone wrong?

 

By trialling different parameters for the CatBoost model and spending many hours on it, the best result we managed to achieve was

================================================================================

Average accuracy: 55.66% ± 4.34%


Training the final model on all the data...


✓ Model saved: models/catboost_quantum_3d.cbm


TOP 10 MOST IMPORTANT FEATURES:

feature importance

bar3d_trend_strength 30.591319

EMA_200 22.086104

EMA_50 14.959278

MACD 4.816617

volatility_20 4.555638

ATR 3.050433

bar3d_volume_volatility 2.690818

bar3d_price_volatility 2.354294

vol_ratio 2.308871

price_change_21 2.308647


TOP 3D BARS (5 characteristics):

feature importance

bar3d_trend_strength 30.591319

bar3d_volume_volatility 2.690818

bar3d_price_volatility 2.354294

bar3d_reversal_prob 0.735604

bar3d_yellow_cluster 0.215698


I don’t understand how bar3d_yellow_cluster ended up being the most important one

 

An analysis of the code provided has revealed that, in the current version , the training data and backtest data are not clearly distinguished.

This leads to data leakage , creating a situation where the backtesting results appear significantly better than the actual results.

I will explain the reason for this in detail by analysing the logic of the code.

1. Problem Analysis

A. Training Stage (Mode 1)

When Mode 1 is selected in the `main()` function, `load_mt5_data(180)` is called.

Python

if choice == "1": data = load_mt5_data(180) # All data for the last 180 days is loaded # ... model = train_catboost_model(data, quantum_encoder, bars_3d)

Next, if we look inside the function, we can see that whilst cross-validation is performed by `train_catboost_model`, retraining is ultimately carried out using the entire dataset .

Python
                       # Inside `train_catboost_model`
    print("\nTraining the final model on the full dataset...")
    model.fit(X, y,verbose=500) # Here, `X` is the full dataset covering the last 180 days

In other words, the model is trained using all the data up to ‘today’.

B. Backtesting stage (Mode 4)

The `backtest()` function performs testing over a period set to `BACKTEST_DAYS = 30` (the last 30 days).

Python

end = datetime.now().replace(second=0,microsecond=0) start = end - timedelta(days=BACKTEST_DAYS) # The last 30 days

2. Conclusion: Cases of data leaks

  • Training data: [ 180 days ago] to [today]

  • Test data: [ Today – 30 days] to [Today]

The period to be tested (the last 30 days) is already included in the training data. This is equivalent to the model taking the test whilst having already ‘seen’ the correct answers, so the backtest win rate is unrealistically high.

3. Solution (Code Modification Guide)

To ensure accurate backtesting, the test period must be excluded from the training process .

Solution 1: Exclude the most recent data from the training function (recommended).

You must trim the data by the length of the back-test period either within the `train_catboost_model` function or during the data loading stage.

Python
                   # Suggested fix: change within the `train_catboost_model` function
def train_catboost_model(data_dict, quantum_encoder,bars_3d=None):
    # ... (omitted) ...
    
   # [Correction] Do not create X directly from all the data; it must be split by date.
    # Alternatively, simply exclude data from the last BACKTEST_DAYS before training.
    
    cutoff_index = len(df_features) - (BACKTEST_DAYS * 96) # Approximately 96 bars per day for M15
    
   # Use only data up to the cutoff point for training
    train_features = df_features.iloc[:cutoff_index] 
    
    # ... then use train_features for training ...

Solution 2: Separate the data from the core logic.

The simplest method is to set different time periods when loading data in the `main()` function.

  • Mode 1 (Training): load_mt5_data (start_days=210, end_days=30) (e.g. data from 210 days ago to 30 days ago)

  • Mode 4 (Test): backtest (days=30) (e.g. data from 30 days ago to today)

To summarise, the current code contains a prediction bias , meaning the backtest results cannot be trusted. It is essential to split the time period, retrain the model and then retest it before actual use.

 

Hello, yes, without delving into or examining the code, it looks very tempting. BUT, having read the previous commenter’s post – I took a look inside.

Indeed, the backtest is run on data that CatBoost has already seen.

Just for the sake of interest, I disabled this line in the code:


print("\nTraining the final model ON ALL THE DATA...")

# model.fit(X, y, verbose=500)


and voilà, on the 30-day backtest, mode 4, there isn’t a single trade (

CatBoost: barely over 50%


...ah, and happiness was so close..)


You’ve put in a huge amount of work... and it’s a disappointment

 
djgagarin CatBoost has already seen.

Just for the sake of interest, I disabled this line of code:


print("\nTraining the final model ON ALL THE DATA...")

# model.fit(X, y, verbose=500)


and voilà, on a 30-day backtest, mode 4, there isn’t a single trade (

CatBoost: barely over 50 per cent


...ah, and happiness was so close..)


You’ve put in a huge amount of work... and it’s disappointing

Well, this chap churns out two articles a week. The code was most likely generated by AI.