Enhancing Investment Performance of the Ichimoku Cloud with the XGBoost Machine Learning Algorithm

 XGBoost

Photo from Pexels by Markus Spiske

Introduction

In financial markets, technical analysis has long been a crucial tool for investors to assess market trends and develop trading strategies. Among these techniques, the Ichimoku Kinko Hyo (Ichimoku Cloud) utilizes five moving averages and a cloud structure to analyze stock support, resistance, and trend changes, enabling traders to quickly identify bullish or bearish signals. However, traditional Ichimoku strategies rely on fixed parameters (9-26-52) and visual interpretation, making them inflexible in adapting to different market conditions. Additionally, in choppy market conditions, Ichimoku-based signals can generate false positives, leading to erroneous trades and capital drawdowns.

With the advancement of machine learning, XGBoost (Extreme Gradient Boosting) has become one of the most widely used models in quantitative trading. By leveraging Gradient Boosting Decision Trees (GBDT), XGBoost learns complex high-dimensional relationships between different data points and enhances the filtering and decision-making process of trading signals. Compared to purely relying on technical indicators, XGBoost can integrate various market variables—such as price momentum, volume changes, and market sentiment—to uncover relationships between data and future stock returns. This ultimately improves the accuracy and robustness of trading strategies.

Strategy Overview
The Ichimoku Cloud was developed by Japanese journalist Goichi Hosoda as a comprehensive technical indicator that evaluates market trends through five key lines. By analyzing the shape and interactions of these lines, traders can make informed investment decisions. The five components of the Ichimoku Cloud are:

  • Chikou Span (Lagging Line, 26-period): This line represents the current closing price, but it is shifted backward by 26 periods to help traders compare past and present price levels, acting as a measure of market strength.
  • Tenkan-sen (Conversion Line, 9-period): This is a short-term trend indicator, determined by the average of the highest and lowest prices over the past nine periods. A rising line suggests upward momentum, while a falling line indicates downward movement.
  • Kijun-sen (Base Line, 26-period): This serves as a medium-term trend indicator, reflecting the average price range over the past 26 periods. It provides a more stable trend direction compared to the Tenkan-sen and can be used as a support or resistance level.
  • Senkou Span A (Leading Span A): This line represents the midpoint between the short-term (Tenkan-sen) and medium-term (Kijun-sen) trends. It is projected 26 periods forward, forming one boundary of the Ichimoku Cloud, which helps traders anticipate future support and resistance levels.
  • Senkou Span B (Leading Span B): This is a long-term trend indicator, based on the average of the highest and lowest prices over the past 52 periods. Like Senkou Span A, it is also projected 26 periods forward, forming the other boundary of the Ichimoku Cloud.

Together, these five components create a cloud-like structure that provides traders with a clear view of market trends, potential reversals, and key support or resistance zones. The relative position of the price and the cloud helps determine whether the market is in a bullish, bearish, or neutral phase.

Ichimoku Cloud Calculation Formula and Code Demonstration

 XGBoost
This chart illustrates the Ichimoku Cloud for stock 6446 during the backtesting period, based on 20% of the overall data

Ichimoku Cloud Entry and Exit Signals

The Ichimoku Cloud provides a trading signal interpretation method known as “Three Confirmations” :

  • Three Confirmations Bullish : A strong buy signal, indicating an upward trend when specific conditions align.
  • Three Confirmations Bearish : A strong sell signal, suggesting a downward trend when the opposite conditions are met.

Generally, when the price moves outside of a consolidation range, a valid Three Confirmations Bullish signal suggests a strong uptrend, while a Three Confirmations Bearish signal indicates a downtrend.

In this study, the traditional Three Confirmations Bullish signal is slightly adjusted to generate optimized buy signals for enhanced trading performance.

Three Confirmations Bullish – Buy Signal:

bullish signal occurs when the following three conditions are met:

  1. Conversion Line (Tenkan-sen) crosses above the Base Line (Kijun-sen).
  2. Lagging Span (Chikou Span) is above the past price.
  3. Price is above the Cloud (Senkou Span A & B).

Three Confirmations Bearish – Sell Signal:

bearish signal occurs when the following conditions are satisfied:

  1. Conversion Line (Tenkan-sen) crosses below the Base Line (Kijun-sen).
  2. Lagging Span (Chikou Span) is below the past price.
  3. Price is below the Cloud (Senkou Span A & B).

When a Three Confirmations Bullish signal appears, it is considered a buy signal based on the Ichimoku strategy. Conversely, a Three Confirmations Bearish signal is treated as a sell signal.

In this study, these signals will be combined with machine learning model outputs to generate optimized trading decisions.

 For more details on the Ichimoku Cloud strategy, refer to: Click Here

Using XGBoost Machine Learning Algorithm for Signal Prediction

XGBoost (eXtreme Gradient Boosting) is a machine learning algorithm based on Gradient Boosting Decision Trees (GBDT). It learns patterns in data by combining multiple weak Decision Trees, gradually improving their predictive accuracy to form a strong forecasting model. Due to its high efficiency, interpretability, and strong generalization ability, XGBoost is widely applied in financial markets and quantitative trading strategies.

In this study, we utilize Ichimoku Cloud data along with fundamental trading data such as open, high, low, close, and volume (OHLCV) to train the XGBoost model. The goal is to enable the model to learn effective trading signals and potentially enhance investment performance.

Data Preparation & Model Training

  1. Dataset Split:
    • 80% of the data is used for training, and 20% is allocated for testing.
  2. Prediction Target:
    • The model predicts trading signals based on future price movements.
    • buy signal is generated if the stock price increases by more than 3% within the next five days.
    • sell signal is assigned otherwise.

By training the XGBoost model on these signals, we aim to identify the hidden relationships between Ichimoku Cloud patterns and future price movements. The expectation is that the model will discover profitable trading opportunities, ultimately improving overall investment performance.

Trading Target

This study focuses on a single stock6446 , as the trading target. The strategy involves adjusting capital allocation dynamically based on entry and exit signals.

The objective is to outperform the buy-and-hold strategy by optimizing trading decisions through the Ichimoku Cloud and XGBoost model, aiming for better investment performance.

Order Execution Logic

This study implements five trading strategies, each with a distinct logic:

  1. Buy-and-Hold Strategy (Benchmark) – Holding the stock without active trading.
  2. Basic Ichimoku Cloud Strategy – Trades based solely on Ichimoku Cloud signals.
  3. Hybrid Strategy (Technical Indicator Focused) – Ichimoku Cloud as the primary signal, with XGBoost as a secondary confirmation.
  4. Hybrid Strategy (Machine Learning Focused) – XGBoost as the primary signal, with Ichimoku Cloud as a secondary confirmation.
  5. Machine Learning Model Strategy – Trades based solely on XGBoost model predictions.

Each strategy generates buy and sell signals based on either Ichimoku Cloud or XGBoost predictions, forming two sets of trading signals during backtesting.

General Strategy (Basic Ichimoku Kinko Hyo Strategy):

This strategy executes trades based on the Ichimoku Kinko Hyo technical indicator. Upon the first occurrence of a buy signal, 50% of the capital position is allocated (to prevent the cash level from remaining too low and to dilute the overall strategy return). Each subsequent buy signal increases the position by 20%, while each sell signal reduces the position by 20% (adjusting the position size based on subsequent signals). Additionally, leverage usage is restricted within the trading logic, with a leverage cap of 100%, ensuring that the strategy does not exceed the principal amount (no leverage is applied) and that short selling is not allowed.

Machine Learning Model Strategy:

This strategy executes trades based on the output of the XGBoost model. The position sizing logic follows the same rules as the general strategy (pure Ichimoku Kinko Hyo strategy).

Hybrid Strategy (Primarily Technical Indicators):

Upon the first occurrence of a technical indicator buy signal, 50% of the capital position is allocated (to prevent the cash level from remaining too low and to dilute the overall strategy return). For subsequent trades, a dual-signal confirmation is required:

  • If both the technical indicator and machine learning model generate a buy signal, the position is increased by 30% (as the presence of both signals boosts investor confidence, leading to a larger position increase).
  • If only the technical indicator generates a buy signal, but the machine learning model does not, the position is increased by only 10% (indicating lower investor confidence).

Similarly, leverage is not allowed, and short selling is prohibited in this strategy.

Hybrid Strategy (Primarily Machine Learning Model):

The position sizing logic is similar to the hybrid strategy based on technical indicators, except that the primary signal for decision-making is derived from the machine learning model instead.

Machine Learning Model Results Presentation

 XGBoost
XGBoost Signal Generation Chart (Test Set) “0: Hold, 1: Buy, 2: Sell”

From the chart, it can be observed that the machine learning model’s signal generation tends to fluctuate frequently, leading to inconsistent signals. As a result, placing trades strictly based on the model’s signals may incur higher transaction costs. Additionally, it is noticeable that after September 2024, the predicted signals are consistently Sellsignals. This phenomenon will be further discussed in the following sections.

 XGBoost

This chart represents the frequency of data features used during the training of the XGBoost model. Features that are used more frequently are considered more important. From the results, it can be observed that the top-ranked features are primarily technical indicators, indicating that incorporating these features, in addition to basic open-high-low-close-volume (OHLCV) data, enhances the model’s predictive performance.

 XGBoost

This chart represents the prediction confusion matrix for the XGBoost model, where:

  • The X-axis represents the model’s predicted signals.
  • The Y-axis represents the actual signals in the test set.
  • The numerical values indicate the frequency of occurrences for each classification.

The most important cells to analyze are:

  • (Predicted Label = 1, True Label = 2) → (1,2)
  • (Predicted Label = 2, True Label = 1) → (2,1)

These two cells indicate cases where the model’s predictions are completely opposite to the actual signals.

Starting with (1,2), this represents situations where the actual signal indicates a sell, but the model predicts a buy. The data shows that this scenario never occurred (0 times), suggesting that the model is less prone to this type of misclassification.

On the other hand, (2,1) represents cases where the actual signal indicates a buy, but the model predicts a sell. This occurred 36 times. However, since the trading strategy prohibits short selling, this misclassification only results in reducing positions or staying out of the market, rather than incurring actual losses due to shorting. Hence, while this prediction error might cause missed opportunities for gains, it does not directly lead to financial losses.

Performance Chart

The first chart represents the cumulative return of different strategies. Looking at the final cumulative returns:

  • The Benchmark (Buy-and-Hold Strategy) achieved a cumulative return of 61.24%.
  • The Raw Strategy (Pure Technical Indicator Strategy) had a cumulative return of only 15.44%, clearly underperforming the Buy-and-Hold approach.

Performance of Hybrid and Machine Learning Strategies

Examining the remaining strategies:

  • The Hybrid Strategy (Technical Indicator Primary) [Mix Strategy 1] achieved a cumulative return of 17%, slightly outperforming the Raw Strategy. This suggests that the machine learning model helped reinforce confidence in trade execution, leading to a slight improvement in returns. This demonstrates that machine learning contributes to strategy optimization.
  • The final two strategies, Machine Learning Strategy (ML Strategy) and Hybrid Strategy (Machine Learning Primary), significantly outperformed the others. Their cumulative returns were 141.81% and 137.52%, respectively. This highlights that the buy and sell signals generated by the machine learning model were far superior to those from technical indicators. The outstanding returns suggest that the XGBoost algorithm effectively captured patterns in the stock’s price movements, enabling the strategy to substantially outperform the Benchmark.

Observing Capital Utilization (Third Chart)

Next, we analyze the capital utilization rate. Since leverage restrictions were imposed in the trading conditions, none of the four strategies employed leverage.

Notably, during the stock’s uptrend from April 2024 to July 2024, the two machine learning-driven strategies built their positions earlier than the two technical indicator-driven strategies. This provides evidence that the machine learning algorithm was able to anticipate future price increases earlier, reinforcing the credibility of its predictive capability and the effectiveness of the strategy.

Stock Condition Analysis

 XGBoost

This chart represents the trading data for stock 6446, covering both the backtesting period and the model training period.

  • The first chart displays the stock’s moving volatility, which helps assess price fluctuations. From the volatility chart, there is no significant structural change between the volatility in the test set and the volatility in the training set.
  • The second chart shows the 50-day moving average trend slope, which provides insight into short-term trends. The trend values did not exceed the highest point observed in the training set by a large margin; instead, they fluctuated within a certain range.
  • However, the third chart (price chart) reveals that the stock price in the test set surpassed the highest price in the training set. This resulted in a scenario where the machine learning model encountered price levels it had not learned from during training, leading to less reliable signal generation.

This explains why, in the previous signal chart, the model continuously generated sell signals at the end of the test set—the model had never encountered such price levels before. This highlights a key limitation of relying solely on machine learning models for signal generation, as they may struggle in unseen market conditions.

Therefore, it is recommended to combine technical indicators or other analytical methods to form a more comprehensive strategy for trade execution.

Discussion & Future Research Directions

This study evaluates the effectiveness of trading strategies using only a single stock. However, whether similar results hold across other stocks or industries requires further analysis and research.

Additionally, when the stock price in the test set surpasses its historical high, it may indicate that the current model is no longer suitable for making predictions. A potential improvement for future research could be designing alert thresholds that signal when the price level has exceeded the model’s applicable range. Once the threshold is triggered, adjustments to the model or trading strategy logic may be necessary to reduce investment risk.

For future research, readers may consider training the model with a broader set of features, such as incorporating different types of data attributes (volatility, 50-day moving average trend slope, and other technical indicators). These additional features could help the model capture higher-dimensional price patterns and variations, potentially improving predictive performance.

Important Reminder: This analysis is for reference only and does not constitute any product or investment advice.

We welcome readers interested in various trading strategies to consider purchasing relevant solutions from Quantitative Finance Solution. With our high-quality databases, you can construct a trading strategy that suits your needs.

“Taiwan stock market data, TEJ collect it all

The characteristics of the Taiwan stock market differ from those of other European and American markets. Especially in the first quarter of 2024, with the Taiwan Stock Exchange reaching a new high of 20,000 points due to the rise in TSMC’s stock price, global institutional investors are paying more attention to the performance of the Taiwan stock market. 

Taiwan Economical Journal (TEJ), a financial database established in Taiwan for over 30 years, serves local financial institutions and academic institutions, and has long-term cooperation with internationally renowned data providers, providing high-quality financial data for five financial markets in Asia. 

  • Complete Coverage: Includes all listed companies on stock markets in Taiwan, China, Hong Kong, Japan, Korea, etc. 
  • Comprehensive Analysis of Enterprises: Operational aspects, financial aspects, securities market performance, ESG sustainability, etc. 
  • High-Quality Database: TEJ data is cleaned, checked, enhanced, and integrated to ensure it meets the information needs of financial and market analysis. 

With TEJ’s assistance, you can access relevant information about major stock markets in Asia, such as securities market, financials data, enterprise operations, board of directors, sustainability data, etc., providing investors with timely and high-quality content. Additionally, TEJ offers advisory services to help solve problems in theoretical practice and financial management!

Full Code Link:Click Here

Further Reading

TQuant Lab Ichimoku Kinko Hyo Strategy, A Self-contained Technical Analysis Indicator

Michael Sivy’s 4 Key Income Investing Principles Unveiled

Related Links

Back
Procesing