XGBoost Mini Strategy [The Quant Science] by thequantscience

By thequantscience

Performance Metrics

Description

This strategy implements a predictive XGBoost machine learning system using our proprietary XGBoostMini library. It's a simple test to demonstrate how to use the library within a strategic framework. Notably, with just a few lines of Pine Script, it was possible to develop an algorithm that learns in real time from recent historical data to decide when to enter the market.πŸ‘‰ XGBoostMini: https://www.tradingview.com/script/SQ2QIdN6-XGBoostMini/πŸ”· Key Features ExtractionBefore making decisions, the system calculates six normalized features metrics to describe the current market state:14-period RSI on a scale from zero to onePercentage distance between the price and the 50-period Exponential Moving Average (EMA)5-period Rate of Change (ROC)Normalized ATR relative to the price to estimate volatilityVolume variation compared to its 20-period moving averageCurrent price position relative to the highs and lows of the last 14 barsπŸ”· Dynamic Model TrainingStarting from bar 300 onwards, every 50 bars the code collects a historical sample consisting of 50 past observations. For each observation, the system checks whether the price increased or decreased two bars later, generating a binary target variable. Based on this recent data, a mini decision tree is trained using the XGBoost model.πŸ”· Real-Time PredictionOn every bar following the training, the model analyzes the 6 current indicators and calculates a numerical probability between 0 and 1, representing the estimated likelihood of a future bullish market movement.πŸ”· Order and Risk ManagementA Long position entry is triggered if the model's estimated probability exceeds the configured reference threshold, set by default to 51%. The position is closed as soon as the probability falls below the opposite threshold. Finally, for capital protection, a safety exit system based on a percentage-based dynamic trailing stop is activated.πŸ”· Key Stats & ProfitabilityTotal PnL: +2,010 USDT (+20.10%). A positive return, though it must be evaluated relative to the time horizon visible in the charts (2018 to 2026).Profit Factor: 1.36. This is a solid value above 1, indicating that gross profits exceed gross losses.Profitable Trades Percentage: Approximately 54.88%. Over half of the operations close in profit, a robust percentage for a medium-to-high frequency algorithmic trading system.πŸ”· Risk Management and DrawdownMax Drawdown: 361.87 USDT, equal to 3.34%. This is an exceptionally positive metric. A drawdown of less than 3.50% over such an extensive historical dataset demonstrates outstanding capital protection and very tight risk management driven by the dynamic trailing stop.πŸ”· Trades Analysis & DistributionExpectancy: +0.20% per trade. This means that, on average, each operation has a positive expected return of 0.20%.πŸ”· Risk/Reward Ratio:Average loss: -0.78%.Average profit: +1.21%.Positive Note: The average profit exceeds the average loss, which helps keep the strategy profitable even with a win rate of around 55%.πŸ”· Outliers and ExtremesLargest loss: 94.60 USDT.Largest profit:169.25 USDT.It's worth noting that the maximum single loss exceeds the maximum single profit, which means that the strategy's profitability does not rely on isolated "lucky shots," but rather on the consistency of many small profits.πŸ”· Equity Curve AnalysisCumulative PnL Curve: Observing the cumulative PnL chart, a steady and gradual growth phase is visible, especially from 2020 onwards, accompanied by strong stability during sideways or bear market phases (such as in 2022).Commission Load: The commission load is very low at 0.08%, indicating that transaction costs have a minimal impact on the final result.πŸ”· Overall AssessmentThe strategy demonstrates solid quantitative metrics: a low drawdown, a good profit factor and a favorable risk/reward ratio. However, as this strategy was developed to test the features of the XGBoost library, it should be considered exclusively for research purposes. Do not treat this strategy as ready for live deployment, but rather as a starting point for your experiments.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView