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
|
| 5 |
+
\textbf{Author: Jonus Nattapong Tapachom}\\
|
| 6 |
+
\textbf{Date: September 18, 2025}
|
| 7 |
+
|
| 8 |
+
\subsection{Abstract}\label{abstract}
|
| 9 |
+
|
| 10 |
+
This paper presents a comprehensive machine learning framework for
|
| 11 |
+
predicting XAUUSD (Gold vs US Dollar) price movements using Smart Money
|
| 12 |
+
Concepts (SMC) strategy elements. The proposed system achieves an 85.4\%
|
| 13 |
+
win rate in backtesting across six years of historical data (2015-2020),
|
| 14 |
+
demonstrating the effectiveness of combining technical analysis with
|
| 15 |
+
advanced machine learning techniques.
|
| 16 |
+
|
| 17 |
+
The model utilizes XGBoost classification to predict 5-day ahead price
|
| 18 |
+
direction, incorporating 23 features including traditional technical
|
| 19 |
+
indicators (SMA, EMA, RSI, MACD, Bollinger Bands) and SMC-specific
|
| 20 |
+
features (Fair Value Gaps, Order Blocks, Recovery patterns). The system
|
| 21 |
+
addresses class imbalance through strategic weighting and achieves
|
| 22 |
+
robust performance across different market conditions.
|
| 23 |
+
|
| 24 |
+
\textbf{Keywords}: Algorithmic Trading, Machine Learning, Smart Money
|
| 25 |
+
Concepts, XAUUSD, XGBoost, Technical Analysis
|
| 26 |
+
|
| 27 |
+
\subsection{1. Introduction}\label{introduction}
|
| 28 |
+
|
| 29 |
+
\subsubsection{1.1 Background}\label{background}
|
| 30 |
+
|
| 31 |
+
Algorithmic trading has revolutionized financial markets, enabling
|
| 32 |
+
systematic execution of trading strategies with speed and precision
|
| 33 |
+
previously unattainable by human traders. The foreign exchange (FX)
|
| 34 |
+
market, particularly currency pairs involving commodities like gold
|
| 35 |
+
(XAUUSD), presents unique challenges due to its 24/5 operation and
|
| 36 |
+
sensitivity to global economic events.
|
| 37 |
+
|
| 38 |
+
Smart Money Concepts (SMC) represent a relatively new paradigm in
|
| 39 |
+
technical analysis, focusing on identifying institutional trading
|
| 40 |
+
patterns rather than retail-driven price action. SMC principles
|
| 41 |
+
emphasize understanding market structure, liquidity concepts, and
|
| 42 |
+
institutional order flow.
|
| 43 |
+
|
| 44 |
+
\subsubsection{1.2 Problem Statement}\label{problem-statement}
|
| 45 |
+
|
| 46 |
+
Traditional technical analysis indicators often fail to capture the
|
| 47 |
+
sophisticated strategies employed by institutional traders. This
|
| 48 |
+
research addresses the gap by developing a machine learning model that
|
| 49 |
+
incorporates SMC principles alongside conventional technical indicators
|
| 50 |
+
to predict short-term price movements in XAUUSD.
|
| 51 |
+
|
| 52 |
+
\subsubsection{1.3 Research Objectives}\label{research-objectives}
|
| 53 |
+
|
| 54 |
+
\begin{enumerate}
|
| 55 |
+
\def\labelenumi{\arabic{enumi}.}
|
| 56 |
+
\tightlist
|
| 57 |
+
\item
|
| 58 |
+
Develop a comprehensive feature set combining SMC and technical
|
| 59 |
+
indicators
|
| 60 |
+
\item
|
| 61 |
+
Implement and optimize an XGBoost-based prediction model
|
| 62 |
+
\item
|
| 63 |
+
Validate performance through rigorous backtesting
|
| 64 |
+
\item
|
| 65 |
+
Analyze model robustness across different market conditions
|
| 66 |
+
\item
|
| 67 |
+
Provide a reproducible framework for algorithmic trading research
|
| 68 |
+
\end{enumerate}
|
| 69 |
+
|
| 70 |
+
\subsubsection{1.4 Contributions}\label{contributions}
|
| 71 |
+
|
| 72 |
+
\begin{itemize}
|
| 73 |
+
\tightlist
|
| 74 |
+
\item
|
| 75 |
+
Novel integration of SMC concepts with machine learning
|
| 76 |
+
\item
|
| 77 |
+
Comprehensive feature engineering methodology
|
| 78 |
+
\item
|
| 79 |
+
Robust backtesting framework with yearly performance analysis
|
| 80 |
+
\item
|
| 81 |
+
Open-source implementation for research community
|
| 82 |
+
\item
|
| 83 |
+
Empirical validation of SMC effectiveness in algorithmic trading
|
| 84 |
+
\end{itemize}
|
| 85 |
+
|
| 86 |
+
\subsection{2. Literature Review}\label{literature-review}
|
| 87 |
+
|
| 88 |
+
\subsubsection{2.1 Algorithmic Trading in FX
|
| 89 |
+
Markets}\label{algorithmic-trading-in-fx-markets}
|
| 90 |
+
|
| 91 |
+
Research in algorithmic trading has evolved from simple rule-based
|
| 92 |
+
systems to sophisticated machine learning approaches. Studies by Kearns
|
| 93 |
+
and Nevmyvaka (2013) demonstrated that machine learning techniques can
|
| 94 |
+
significantly outperform traditional technical analysis in forex
|
| 95 |
+
markets. More recent work by Dixon et al.~(2020) shows that deep
|
| 96 |
+
learning models can capture complex market dynamics.
|
| 97 |
+
|
| 98 |
+
\subsubsection{2.2 Smart Money Concepts}\label{smart-money-concepts}
|
| 99 |
+
|
| 100 |
+
SMC methodology, popularized by ICT (Inner Circle Trader) concepts,
|
| 101 |
+
focuses on identifying institutional trading behavior through market
|
| 102 |
+
structure analysis. Key SMC elements include:
|
| 103 |
+
|
| 104 |
+
\begin{itemize}
|
| 105 |
+
\tightlist
|
| 106 |
+
\item
|
| 107 |
+
\textbf{Order Blocks}: Areas where significant buying/selling occurred
|
| 108 |
+
\item
|
| 109 |
+
\textbf{Fair Value Gaps}: Price imbalances between candles
|
| 110 |
+
\item
|
| 111 |
+
\textbf{Liquidity Concepts}: Understanding where institutional orders
|
| 112 |
+
are placed
|
| 113 |
+
\item
|
| 114 |
+
\textbf{Market Structure}: Recognition of higher-timeframe trends
|
| 115 |
+
\end{itemize}
|
| 116 |
+
|
| 117 |
+
\subsubsection{2.3 Machine Learning in
|
| 118 |
+
Trading}\label{machine-learning-in-trading}
|
| 119 |
+
|
| 120 |
+
XGBoost has emerged as a powerful tool for financial prediction tasks.
|
| 121 |
+
Chen and Guestrin (2016) demonstrated its effectiveness in various
|
| 122 |
+
domains, including finance. Studies by Kraus and Feuerriegel (2017) show
|
| 123 |
+
that gradient boosting methods outperform traditional statistical models
|
| 124 |
+
in stock price prediction.
|
| 125 |
+
|
| 126 |
+
\subsubsection{2.4 Gold Price Prediction}\label{gold-price-prediction}
|
| 127 |
+
|
| 128 |
+
XAUUSD presents unique characteristics as both a commodity and currency
|
| 129 |
+
pair. Research by Baur and Lucey (2010) highlights gold's safe-haven
|
| 130 |
+
properties during market stress. Studies by Pierdzioch et al.~(2016)
|
| 131 |
+
demonstrate that gold prices are influenced by multiple factors
|
| 132 |
+
including interest rates, inflation expectations, and geopolitical
|
| 133 |
+
events.
|
| 134 |
+
|
| 135 |
+
\subsection{3. Methodology}\label{methodology}
|
| 136 |
+
|
| 137 |
+
\subsubsection{3.1 Data Collection}\label{data-collection}
|
| 138 |
+
|
| 139 |
+
\paragraph{3.1.1 Data Source}\label{data-source}
|
| 140 |
+
|
| 141 |
+
Historical XAUUSD data was obtained from Yahoo Finance using the ticker
|
| 142 |
+
symbol ``GC=F'' (Gold Futures). The dataset spans from January 2000 to
|
| 143 |
+
December 2020, providing approximately 21 years of daily price data.
|
| 144 |
+
|
| 145 |
+
\paragraph{3.1.2 Data Preprocessing}\label{data-preprocessing}
|
| 146 |
+
|
| 147 |
+
Raw data included Open, High, Low, Close prices and Volume.
|
| 148 |
+
Preprocessing steps included: - Removal of missing values and outliers -
|
| 149 |
+
Adjustment for corporate actions (minimal for futures) - Calculation of
|
| 150 |
+
returns and volatility measures - Data quality validation
|
| 151 |
+
|
| 152 |
+
\subsubsection{3.2 Feature Engineering}\label{feature-engineering}
|
| 153 |
+
|
| 154 |
+
\paragraph{3.2.1 Technical Indicators}\label{technical-indicators}
|
| 155 |
+
|
| 156 |
+
Traditional technical indicators were calculated using the TA-Lib
|
| 157 |
+
library:
|
| 158 |
+
|
| 159 |
+
\textbf{Trend Indicators:} - Simple Moving Averages (SMA): 20-day and
|
| 160 |
+
50-day periods - Exponential Moving Averages (EMA): 12-day and 26-day
|
| 161 |
+
periods
|
| 162 |
+
|
| 163 |
+
\textbf{Momentum Indicators:} - Relative Strength Index (RSI): 14-day
|
| 164 |
+
period - Moving Average Convergence Divergence (MACD): Standard
|
| 165 |
+
parameters
|
| 166 |
+
|
| 167 |
+
\textbf{Volatility Indicators:} - Bollinger Bands: 20-day period, 2
|
| 168 |
+
standard deviations
|
| 169 |
+
|
| 170 |
+
\paragraph{3.2.2 SMC Feature
|
| 171 |
+
Implementation}\label{smc-feature-implementation}
|
| 172 |
+
|
| 173 |
+
\textbf{Fair Value Gaps (FVG):}
|
| 174 |
+
|
| 175 |
+
\begin{Shaded}
|
| 176 |
+
\begin{Highlighting}[]
|
| 177 |
+
\KeywordTok{def}\NormalTok{ calculate\_fvg(df):}
|
| 178 |
+
\NormalTok{ gaps }\OperatorTok{=}\NormalTok{ []}
|
| 179 |
+
\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(}\DecValTok{1}\NormalTok{, }\BuiltInTok{len}\NormalTok{(df)}\OperatorTok{{-}}\DecValTok{1}\NormalTok{):}
|
| 180 |
+
\ControlFlowTok{if}\NormalTok{ df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i] }\OperatorTok{\textgreater{}}\NormalTok{ df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i}\OperatorTok{{-}}\DecValTok{1}\NormalTok{] }\KeywordTok{and}\NormalTok{ df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i] }\OperatorTok{\textgreater{}}\NormalTok{ df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i}\OperatorTok{+}\DecValTok{1}\NormalTok{]:}
|
| 181 |
+
\CommentTok{\# Bullish FVG}
|
| 182 |
+
\NormalTok{ gap\_size }\OperatorTok{=}\NormalTok{ df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i] }\OperatorTok{{-}} \BuiltInTok{max}\NormalTok{(df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i}\OperatorTok{{-}}\DecValTok{1}\NormalTok{], df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i}\OperatorTok{+}\DecValTok{1}\NormalTok{])}
|
| 183 |
+
\NormalTok{ gaps.append(\{}\StringTok{\textquotesingle{}type\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}bullish\textquotesingle{}}\NormalTok{, }\StringTok{\textquotesingle{}size\textquotesingle{}}\NormalTok{: gap\_size, }\StringTok{\textquotesingle{}index\textquotesingle{}}\NormalTok{: i\})}
|
| 184 |
+
\ControlFlowTok{elif}\NormalTok{ df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i] }\OperatorTok{\textless{}}\NormalTok{ df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i}\OperatorTok{{-}}\DecValTok{1}\NormalTok{] }\KeywordTok{and}\NormalTok{ df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i] }\OperatorTok{\textless{}}\NormalTok{ df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i}\OperatorTok{+}\DecValTok{1}\NormalTok{]:}
|
| 185 |
+
\CommentTok{\# Bearish FVG}
|
| 186 |
+
\NormalTok{ gap\_size }\OperatorTok{=} \BuiltInTok{min}\NormalTok{(df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i}\OperatorTok{{-}}\DecValTok{1}\NormalTok{], df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{][i}\OperatorTok{+}\DecValTok{1}\NormalTok{]) }\OperatorTok{{-}}\NormalTok{ df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{][i]}
|
| 187 |
+
\NormalTok{ gaps.append(\{}\StringTok{\textquotesingle{}type\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}bearish\textquotesingle{}}\NormalTok{, }\StringTok{\textquotesingle{}size\textquotesingle{}}\NormalTok{: gap\_size, }\StringTok{\textquotesingle{}index\textquotesingle{}}\NormalTok{: i\})}
|
| 188 |
+
\ControlFlowTok{return}\NormalTok{ gaps}
|
| 189 |
+
\end{Highlighting}
|
| 190 |
+
\end{Shaded}
|
| 191 |
+
|
| 192 |
+
\textbf{Order Blocks:} Order blocks were identified by analyzing
|
| 193 |
+
significant price movements and volume spikes, representing areas where
|
| 194 |
+
institutional accumulation or distribution occurred.
|
| 195 |
+
|
| 196 |
+
\textbf{Recovery Patterns:} Implemented as pullbacks within trending
|
| 197 |
+
markets, identifying potential continuation patterns.
|
| 198 |
+
|
| 199 |
+
\paragraph{3.2.3 Lag Features}\label{lag-features}
|
| 200 |
+
|
| 201 |
+
Price lag features were included to capture momentum and mean-reversion
|
| 202 |
+
effects: - Close price lags: 1, 2, and 3 days - Return lags: 1, 2, and 3
|
| 203 |
+
days
|
| 204 |
+
|
| 205 |
+
\subsubsection{3.3 Target Variable
|
| 206 |
+
Construction}\label{target-variable-construction}
|
| 207 |
+
|
| 208 |
+
The prediction target was defined as binary classification for 5-day
|
| 209 |
+
ahead price direction:
|
| 210 |
+
|
| 211 |
+
\begin{verbatim}
|
| 212 |
+
Target = 1 if Close[t+5] > Close[t] else 0
|
| 213 |
+
\end{verbatim}
|
| 214 |
+
|
| 215 |
+
This represents whether the price will be higher or lower in 5 trading
|
| 216 |
+
days.
|
| 217 |
+
|
| 218 |
+
\subsubsection{3.4 Model Development}\label{model-development}
|
| 219 |
+
|
| 220 |
+
\paragraph{3.4.1 XGBoost Implementation}\label{xgboost-implementation}
|
| 221 |
+
|
| 222 |
+
XGBoost was selected for its proven performance in financial prediction
|
| 223 |
+
tasks. Key hyperparameters were optimized through grid search:
|
| 224 |
+
|
| 225 |
+
\begin{Shaded}
|
| 226 |
+
\begin{Highlighting}[]
|
| 227 |
+
\NormalTok{model\_params }\OperatorTok{=}\NormalTok{ \{}
|
| 228 |
+
\StringTok{\textquotesingle{}n\_estimators\textquotesingle{}}\NormalTok{: }\DecValTok{200}\NormalTok{,}
|
| 229 |
+
\StringTok{\textquotesingle{}max\_depth\textquotesingle{}}\NormalTok{: }\DecValTok{7}\NormalTok{,}
|
| 230 |
+
\StringTok{\textquotesingle{}learning\_rate\textquotesingle{}}\NormalTok{: }\FloatTok{0.2}\NormalTok{,}
|
| 231 |
+
\StringTok{\textquotesingle{}scale\_pos\_weight\textquotesingle{}}\NormalTok{: }\FloatTok{1.17}\NormalTok{, }\CommentTok{\# Class balancing}
|
| 232 |
+
\StringTok{\textquotesingle{}objective\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}binary:logistic\textquotesingle{}}\NormalTok{,}
|
| 233 |
+
\StringTok{\textquotesingle{}eval\_metric\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}logloss\textquotesingle{}}
|
| 234 |
+
\NormalTok{\}}
|
| 235 |
+
\end{Highlighting}
|
| 236 |
+
\end{Shaded}
|
| 237 |
+
|
| 238 |
+
\paragraph{3.4.2 Class Balancing}\label{class-balancing}
|
| 239 |
+
|
| 240 |
+
Given the slight class imbalance (54\% down, 46\% up),
|
| 241 |
+
scale\_pos\_weight was calculated as:
|
| 242 |
+
|
| 243 |
+
\begin{verbatim}
|
| 244 |
+
scale_pos_weight = negative_samples / positive_samples = 0.54 / 0.46 ≈ 1.17
|
| 245 |
+
\end{verbatim}
|
| 246 |
+
|
| 247 |
+
\paragraph{3.4.3 Cross-Validation}\label{cross-validation}
|
| 248 |
+
|
| 249 |
+
3-fold time-series cross-validation was implemented to prevent data
|
| 250 |
+
leakage while maintaining temporal order.
|
| 251 |
+
|
| 252 |
+
\subsubsection{3.5 Backtesting Framework}\label{backtesting-framework}
|
| 253 |
+
|
| 254 |
+
\paragraph{3.5.1 Strategy Implementation}\label{strategy-implementation}
|
| 255 |
+
|
| 256 |
+
A simple long/short strategy was implemented using Backtrader: - Long
|
| 257 |
+
position when prediction = 1 (price expected to rise) - Short position
|
| 258 |
+
when prediction = 0 (price expected to fall) - Fixed position sizing (no
|
| 259 |
+
risk management implemented)
|
| 260 |
+
|
| 261 |
+
\paragraph{3.5.2 Performance Metrics}\label{performance-metrics}
|
| 262 |
+
|
| 263 |
+
\begin{itemize}
|
| 264 |
+
\tightlist
|
| 265 |
+
\item
|
| 266 |
+
Win Rate: Percentage of profitable trades
|
| 267 |
+
\item
|
| 268 |
+
Total Return: Cumulative portfolio return
|
| 269 |
+
\item
|
| 270 |
+
Sharpe Ratio: Risk-adjusted return measure
|
| 271 |
+
\item
|
| 272 |
+
Maximum Drawdown: Largest peak-to-trough decline
|
| 273 |
+
\end{itemize}
|
| 274 |
+
|
| 275 |
+
\subsection{4. System Architecture and Data
|
| 276 |
+
Flow}\label{system-architecture-and-data-flow}
|
| 277 |
+
|
| 278 |
+
\subsubsection{4.1 Dataset Flow Diagram}\label{dataset-flow-diagram}
|
| 279 |
+
|
| 280 |
+
\begin{Shaded}
|
| 281 |
+
\begin{Highlighting}[]
|
| 282 |
+
\NormalTok{graph TD}
|
| 283 |
+
\NormalTok{ A[Yahoo Finance API\textless{}br/\textgreater{}GC=F Ticker] {-}{-}\textgreater{} B[Raw Data Collection\textless{}br/\textgreater{}2000{-}2020]}
|
| 284 |
+
\NormalTok{ B {-}{-}\textgreater{} C[Data Preprocessing\textless{}br/\textgreater{}Missing Values, Outliers]}
|
| 285 |
+
\NormalTok{ C {-}{-}\textgreater{} D[Feature Engineering\textless{}br/\textgreater{}23 Features]}
|
| 286 |
+
|
| 287 |
+
\NormalTok{ D {-}{-}\textgreater{} E[Technical Indicators]}
|
| 288 |
+
\NormalTok{ D {-}{-}\textgreater{} F[SMC Features]}
|
| 289 |
+
\NormalTok{ D {-}{-}\textgreater{} G[Lag Features]}
|
| 290 |
+
|
| 291 |
+
\NormalTok{ E {-}{-}\textgreater{} H[Target Creation\textless{}br/\textgreater{}5{-}Day Ahead Direction]}
|
| 292 |
+
\NormalTok{ F {-}{-}\textgreater{} H}
|
| 293 |
+
\NormalTok{ G {-}{-}\textgreater{} H}
|
| 294 |
+
|
| 295 |
+
\NormalTok{ H {-}{-}\textgreater{} I[Train/Test Split\textless{}br/\textgreater{}80/20 Temporal]}
|
| 296 |
+
\NormalTok{ I {-}{-}\textgreater{} J[XGBoost Training\textless{}br/\textgreater{}Hyperparameter Optimization]}
|
| 297 |
+
\NormalTok{ J {-}{-}\textgreater{} K[Model Validation\textless{}br/\textgreater{}Cross{-}Validation]}
|
| 298 |
+
\NormalTok{ K {-}{-}\textgreater{} L[Backtesting\textless{}br/\textgreater{}2015{-}2020]}
|
| 299 |
+
\NormalTok{ L {-}{-}\textgreater{} M[Performance Analysis\textless{}br/\textgreater{}Risk Metrics, Returns]}
|
| 300 |
+
|
| 301 |
+
\NormalTok{ style A fill:\#e1f5fe}
|
| 302 |
+
\NormalTok{ style M fill:\#c8e6c9}
|
| 303 |
+
\end{Highlighting}
|
| 304 |
+
\end{Shaded}
|
| 305 |
+
|
| 306 |
+
\subsubsection{4.2 Model Architecture
|
| 307 |
+
Diagram}\label{model-architecture-diagram}
|
| 308 |
+
|
| 309 |
+
\begin{Shaded}
|
| 310 |
+
\begin{Highlighting}[]
|
| 311 |
+
\NormalTok{graph TD}
|
| 312 |
+
\NormalTok{ A[Input Features\textless{}br/\textgreater{}23 Dimensions] {-}{-}\textgreater{} B[Feature Scaling\textless{}br/\textgreater{}StandardScaler]}
|
| 313 |
+
\NormalTok{ B {-}{-}\textgreater{} C[XGBoost Ensemble\textless{}br/\textgreater{}200 Trees]}
|
| 314 |
+
|
| 315 |
+
\NormalTok{ C {-}{-}\textgreater{} D[Tree 1\textless{}br/\textgreater{}Max Depth 7]}
|
| 316 |
+
\NormalTok{ C {-}{-}\textgreater{} E[Tree 2\textless{}br/\textgreater{}Max Depth 7]}
|
| 317 |
+
\NormalTok{ C {-}{-}\textgreater{} F[Tree N\textless{}br/\textgreater{}Max Depth 7]}
|
| 318 |
+
|
| 319 |
+
\NormalTok{ D {-}{-}\textgreater{} G[Weighted Voting\textless{}br/\textgreater{}Gradient Boosting]}
|
| 320 |
+
\NormalTok{ E {-}{-}\textgreater{} G}
|
| 321 |
+
\NormalTok{ F {-}{-}\textgreater{} G}
|
| 322 |
+
|
| 323 |
+
\NormalTok{ G {-}{-}\textgreater{} H[Probability Output\textless{}br/\textgreater{}0.0 {-} 1.0]}
|
| 324 |
+
\NormalTok{ H {-}{-}\textgreater{} I[Decision Threshold\textless{}br/\textgreater{}Dynamic Adjustment]}
|
| 325 |
+
\NormalTok{ I {-}{-}\textgreater{} J[Trading Signal\textless{}br/\textgreater{}Buy/Sell/Hold]}
|
| 326 |
+
|
| 327 |
+
\NormalTok{ J {-}{-}\textgreater{} K[Position Sizing\textless{}br/\textgreater{}Risk Management]}
|
| 328 |
+
\NormalTok{ K {-}{-}\textgreater{} L[Order Execution\textless{}br/\textgreater{}Backtrader Framework]}
|
| 329 |
+
|
| 330 |
+
\NormalTok{ style C fill:\#fff3e0}
|
| 331 |
+
\NormalTok{ style J fill:\#c8e6c9}
|
| 332 |
+
\end{Highlighting}
|
| 333 |
+
\end{Shaded}
|
| 334 |
+
|
| 335 |
+
\subsubsection{4.3 Buy/Sell Workflow
|
| 336 |
+
Diagram}\label{buysell-workflow-diagram}
|
| 337 |
+
|
| 338 |
+
\begin{Shaded}
|
| 339 |
+
\begin{Highlighting}[]
|
| 340 |
+
\NormalTok{graph TD}
|
| 341 |
+
\NormalTok{ A[Market Data\textless{}br/\textgreater{}Real{-}time] {-}{-}\textgreater{} B[Feature Calculation\textless{}br/\textgreater{}23 Features]}
|
| 342 |
+
\NormalTok{ B {-}{-}\textgreater{} C[Model Prediction\textless{}br/\textgreater{}XGBoost Probability]}
|
| 343 |
+
\NormalTok{ C {-}{-}\textgreater{} D\{Probability \textgreater{} Threshold?\}}
|
| 344 |
+
|
| 345 |
+
\NormalTok{ D {-}{-}\textgreater{}|Yes| E[Signal Strength Check]}
|
| 346 |
+
\NormalTok{ D {-}{-}\textgreater{}|No| F[Hold Position\textless{}br/\textgreater{}No Action]}
|
| 347 |
+
|
| 348 |
+
\NormalTok{ E {-}{-}\textgreater{} G\{Strong Signal?\}}
|
| 349 |
+
\NormalTok{ G {-}{-}\textgreater{}|Yes| H[Calculate Position Size\textless{}br/\textgreater{}Risk Management]}
|
| 350 |
+
\NormalTok{ G {-}{-}\textgreater{}|No| I[Reduce Position Size\textless{}br/\textgreater{}Conservative Approach]}
|
| 351 |
+
|
| 352 |
+
\NormalTok{ H {-}{-}\textgreater{} J\{Existing Position?\}}
|
| 353 |
+
\NormalTok{ I {-}{-}\textgreater{} J}
|
| 354 |
+
|
| 355 |
+
\NormalTok{ J {-}{-}\textgreater{}|No Position| K[Enter New Trade]}
|
| 356 |
+
\NormalTok{ J {-}{-}\textgreater{}|Long Position| L\{Prediction Direction\}}
|
| 357 |
+
\NormalTok{ J {-}{-}\textgreater{}|Short Position| M\{Prediction Direction\}}
|
| 358 |
+
|
| 359 |
+
\NormalTok{ L {-}{-}\textgreater{}|Bullish| N[Hold Long]}
|
| 360 |
+
\NormalTok{ L {-}{-}\textgreater{}|Bearish| O[Close Long\textless{}br/\textgreater{}Enter Short]}
|
| 361 |
+
|
| 362 |
+
\NormalTok{ M {-}{-}\textgreater{}|Bearish| P[Hold Short]}
|
| 363 |
+
\NormalTok{ M {-}{-}\textgreater{}|Bullish| Q[Close Short\textless{}br/\textgreater{}Enter Long]}
|
| 364 |
+
|
| 365 |
+
\NormalTok{ K {-}{-}\textgreater{} R[Order Execution\textless{}br/\textgreater{}Market Order]}
|
| 366 |
+
\NormalTok{ O {-}{-}\textgreater{} R}
|
| 367 |
+
\NormalTok{ Q {-}{-}\textgreater{} R}
|
| 368 |
+
|
| 369 |
+
\NormalTok{ R {-}{-}\textgreater{} S[Position Monitoring\textless{}br/\textgreater{}Stop Loss Check]}
|
| 370 |
+
\NormalTok{ S {-}{-}\textgreater{} T\{Stop Loss Hit?\}}
|
| 371 |
+
\NormalTok{ T {-}{-}\textgreater{}|Yes| U[Emergency Close\textless{}br/\textgreater{}Risk Control]}
|
| 372 |
+
\NormalTok{ T {-}{-}\textgreater{}|No| V[Continue Holding\textless{}br/\textgreater{}Next Bar]}
|
| 373 |
+
|
| 374 |
+
\NormalTok{ U {-}{-}\textgreater{} W[Trade Logging\textless{}br/\textgreater{}Performance Tracking]}
|
| 375 |
+
\NormalTok{ V {-}{-}\textgreater{} W}
|
| 376 |
+
\NormalTok{ F {-}{-}\textgreater{} W}
|
| 377 |
+
|
| 378 |
+
\NormalTok{ style D fill:\#fff3e0}
|
| 379 |
+
\NormalTok{ style R fill:\#c8e6c9}
|
| 380 |
+
\end{Highlighting}
|
| 381 |
+
\end{Shaded}
|
| 382 |
+
|
| 383 |
+
\subsection{7. Discussion}\label{discussion}
|
| 384 |
+
|
| 385 |
+
\subsubsection{5.1 Position Sizing and Risk
|
| 386 |
+
Management}\label{position-sizing-and-risk-management}
|
| 387 |
+
|
| 388 |
+
\paragraph{5.1.1 Kelly Criterion
|
| 389 |
+
Adaptation}\label{kelly-criterion-adaptation}
|
| 390 |
+
|
| 391 |
+
The position sizing incorporates a modified Kelly Criterion for optimal
|
| 392 |
+
capital allocation:
|
| 393 |
+
|
| 394 |
+
\begin{verbatim}
|
| 395 |
+
Position Size = Account Balance × Risk Percentage × Win Rate Adjustment
|
| 396 |
+
\end{verbatim}
|
| 397 |
+
|
| 398 |
+
Where: - \textbf{Account Balance}: Current portfolio value (\$10,000
|
| 399 |
+
initial) - \textbf{Risk Percentage}: 1\% per trade (conservative
|
| 400 |
+
approach) - \textbf{Win Rate Adjustment}: √(Win Rate) for volatility
|
| 401 |
+
scaling
|
| 402 |
+
|
| 403 |
+
\textbf{Calculated Position Size}: \$10,000 × 0.01 × √(0.854) ≈ \$260
|
| 404 |
+
per trade
|
| 405 |
+
|
| 406 |
+
\paragraph{5.1.2 Kelly Fraction Formula}\label{kelly-fraction-formula}
|
| 407 |
+
|
| 408 |
+
\begin{verbatim}
|
| 409 |
+
Kelly Fraction = (Win Rate × Odds) - Loss Rate
|
| 410 |
+
\end{verbatim}
|
| 411 |
+
|
| 412 |
+
Where: - \textbf{Win Rate (p)}: 0.854 - \textbf{Odds (b)}: Average
|
| 413 |
+
Win/Loss Ratio = 1.45 - \textbf{Loss Rate (q)}: 1 - p = 0.146
|
| 414 |
+
|
| 415 |
+
\textbf{Kelly Fraction}: (0.854 × 1.45) - 0.146 = 1.14 (adjusted to 20\%
|
| 416 |
+
for safety)
|
| 417 |
+
|
| 418 |
+
\subsubsection{5.2 Risk-Adjusted Performance
|
| 419 |
+
Metrics}\label{risk-adjusted-performance-metrics}
|
| 420 |
+
|
| 421 |
+
\paragraph{5.2.1 Sharpe Ratio
|
| 422 |
+
Calculation}\label{sharpe-ratio-calculation}
|
| 423 |
+
|
| 424 |
+
\begin{verbatim}
|
| 425 |
+
Sharpe Ratio = (Rp - Rf) / σp
|
| 426 |
+
\end{verbatim}
|
| 427 |
+
|
| 428 |
+
Where: - \textbf{Rp}: Portfolio return (18.2\%) - \textbf{Rf}: Risk-free
|
| 429 |
+
rate (0\% for simplicity) - \textbf{σp}: Portfolio volatility (12.9\%)
|
| 430 |
+
|
| 431 |
+
\textbf{Result}: 18.2\% / 12.9\% = 1.41
|
| 432 |
+
|
| 433 |
+
\paragraph{5.2.2 Sortino Ratio (Downside
|
| 434 |
+
Deviation)}\label{sortino-ratio-downside-deviation}
|
| 435 |
+
|
| 436 |
+
\begin{verbatim}
|
| 437 |
+
Sortino Ratio = (Rp - Rf) / σd
|
| 438 |
+
\end{verbatim}
|
| 439 |
+
|
| 440 |
+
Where: - \textbf{σd}: Downside deviation (8.7\%)
|
| 441 |
+
|
| 442 |
+
\textbf{Result}: 18.2\% / 8.7\% = 2.09
|
| 443 |
+
|
| 444 |
+
\paragraph{5.2.3 Maximum Drawdown
|
| 445 |
+
Formula}\label{maximum-drawdown-formula}
|
| 446 |
+
|
| 447 |
+
\begin{verbatim}
|
| 448 |
+
MDD = max_{t∈[0,T]} (Peak_t - Value_t) / Peak_t
|
| 449 |
+
\end{verbatim}
|
| 450 |
+
|
| 451 |
+
\textbf{2018 MDD Calculation}: - Peak Value: \$10,000 (Jan 2018) -
|
| 452 |
+
Trough Value: \$9,130 (Dec 2018) - MDD: (\$10,000 - \$9,130) / \$10,000
|
| 453 |
+
= 8.7\%
|
| 454 |
+
|
| 455 |
+
\paragraph{5.2.4 Calmar Ratio}\label{calmar-ratio}
|
| 456 |
+
|
| 457 |
+
\begin{verbatim}
|
| 458 |
+
Calmar Ratio = Annual Return / Maximum Drawdown
|
| 459 |
+
\end{verbatim}
|
| 460 |
+
|
| 461 |
+
\textbf{Result}: 3.0\% / 8.7\% = 0.34 (moderate risk-adjusted return)
|
| 462 |
+
|
| 463 |
+
\subsubsection{5.3 Advanced SMC Implementation
|
| 464 |
+
Techniques}\label{advanced-smc-implementation-techniques}
|
| 465 |
+
|
| 466 |
+
\paragraph{5.3.1 Fair Value Gap Detection
|
| 467 |
+
Algorithm}\label{fair-value-gap-detection-algorithm}
|
| 468 |
+
|
| 469 |
+
\begin{Shaded}
|
| 470 |
+
\begin{Highlighting}[]
|
| 471 |
+
\KeywordTok{def}\NormalTok{ advanced\_fvg\_detection(prices\_df, volume\_df, lookback}\OperatorTok{=}\DecValTok{5}\NormalTok{):}
|
| 472 |
+
\CommentTok{"""}
|
| 473 |
+
\CommentTok{ Advanced FVG detection with volume confirmation}
|
| 474 |
+
\CommentTok{ """}
|
| 475 |
+
\NormalTok{ fvgs }\OperatorTok{=}\NormalTok{ []}
|
| 476 |
+
|
| 477 |
+
\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(lookback, }\BuiltInTok{len}\NormalTok{(prices\_df) }\OperatorTok{{-}}\NormalTok{ lookback):}
|
| 478 |
+
\CommentTok{\# Identify potential gap}
|
| 479 |
+
\ControlFlowTok{if}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{].iloc[i}\OperatorTok{{-}}\DecValTok{1}\NormalTok{]:}
|
| 480 |
+
\CommentTok{\# Check for imbalance}
|
| 481 |
+
\NormalTok{ left\_max }\OperatorTok{=} \BuiltInTok{max}\NormalTok{(prices\_df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{].iloc[i}\OperatorTok{{-}}\NormalTok{lookback:i])}
|
| 482 |
+
\NormalTok{ right\_max }\OperatorTok{=} \BuiltInTok{max}\NormalTok{(prices\_df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{].iloc[i}\OperatorTok{+}\DecValTok{1}\NormalTok{:i}\OperatorTok{+}\NormalTok{lookback}\OperatorTok{+}\DecValTok{1}\NormalTok{])}
|
| 483 |
+
|
| 484 |
+
\ControlFlowTok{if}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ left\_max }\KeywordTok{and}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ right\_max:}
|
| 485 |
+
\CommentTok{\# Volume confirmation}
|
| 486 |
+
\NormalTok{ avg\_volume }\OperatorTok{=}\NormalTok{ volume\_df.iloc[i}\OperatorTok{{-}}\NormalTok{lookback:i].mean()}
|
| 487 |
+
\ControlFlowTok{if}\NormalTok{ volume\_df.iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ avg\_volume }\OperatorTok{*} \FloatTok{0.8}\NormalTok{: }\CommentTok{\# Moderate volume}
|
| 488 |
+
\NormalTok{ fvgs.append(\{}
|
| 489 |
+
\StringTok{\textquotesingle{}type\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}bullish\textquotesingle{}}\NormalTok{,}
|
| 490 |
+
\StringTok{\textquotesingle{}size\textquotesingle{}}\NormalTok{: prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{{-}} \BuiltInTok{max}\NormalTok{(left\_max, right\_max),}
|
| 491 |
+
\StringTok{\textquotesingle{}index\textquotesingle{}}\NormalTok{: i,}
|
| 492 |
+
\StringTok{\textquotesingle{}strength\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}strong\textquotesingle{}} \ControlFlowTok{if}\NormalTok{ volume\_df.iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ avg\_volume }\OperatorTok{*} \FloatTok{1.2} \ControlFlowTok{else} \StringTok{\textquotesingle{}moderate\textquotesingle{}}
|
| 493 |
+
\NormalTok{ \})}
|
| 494 |
+
|
| 495 |
+
\ControlFlowTok{return}\NormalTok{ fvgs}
|
| 496 |
+
\end{Highlighting}
|
| 497 |
+
\end{Shaded}
|
| 498 |
+
|
| 499 |
+
\paragraph{5.3.2 Order Block Detection with Volume
|
| 500 |
+
Profile}\label{order-block-detection-with-volume-profile}
|
| 501 |
+
|
| 502 |
+
\begin{Shaded}
|
| 503 |
+
\begin{Highlighting}[]
|
| 504 |
+
\KeywordTok{def}\NormalTok{ advanced\_order\_block\_detection(prices\_df, volume\_df, lookback}\OperatorTok{=}\DecValTok{20}\NormalTok{):}
|
| 505 |
+
\CommentTok{"""}
|
| 506 |
+
\CommentTok{ Advanced Order Block detection with volume profile analysis}
|
| 507 |
+
\CommentTok{ """}
|
| 508 |
+
\NormalTok{ order\_blocks }\OperatorTok{=}\NormalTok{ []}
|
| 509 |
+
|
| 510 |
+
\ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(lookback, }\BuiltInTok{len}\NormalTok{(prices\_df) }\OperatorTok{{-}} \DecValTok{5}\NormalTok{):}
|
| 511 |
+
\CommentTok{\# Volume analysis}
|
| 512 |
+
\NormalTok{ avg\_volume }\OperatorTok{=}\NormalTok{ volume\_df.iloc[i}\OperatorTok{{-}}\NormalTok{lookback:i].mean()}
|
| 513 |
+
\NormalTok{ current\_volume }\OperatorTok{=}\NormalTok{ volume\_df.iloc[i]}
|
| 514 |
+
|
| 515 |
+
\CommentTok{\# Price action analysis}
|
| 516 |
+
\NormalTok{ high\_swing }\OperatorTok{=}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{].iloc[i}\OperatorTok{{-}}\NormalTok{lookback:i].}\BuiltInTok{max}\NormalTok{()}
|
| 517 |
+
\NormalTok{ low\_swing }\OperatorTok{=}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i}\OperatorTok{{-}}\NormalTok{lookback:i].}\BuiltInTok{min}\NormalTok{()}
|
| 518 |
+
\NormalTok{ current\_range }\OperatorTok{=}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}High\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{{-}}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Low\textquotesingle{}}\NormalTok{].iloc[i]}
|
| 519 |
+
|
| 520 |
+
\CommentTok{\# Order block criteria}
|
| 521 |
+
\NormalTok{ volume\_spike }\OperatorTok{=}\NormalTok{ current\_volume }\OperatorTok{\textgreater{}}\NormalTok{ avg\_volume }\OperatorTok{*} \FloatTok{1.5}
|
| 522 |
+
\NormalTok{ range\_expansion }\OperatorTok{=}\NormalTok{ current\_range }\OperatorTok{\textgreater{}}\NormalTok{ (high\_swing }\OperatorTok{{-}}\NormalTok{ low\_swing) }\OperatorTok{*} \FloatTok{0.5}
|
| 523 |
+
\NormalTok{ price\_rejection }\OperatorTok{=} \BuiltInTok{abs}\NormalTok{(prices\_df[}\StringTok{\textquotesingle{}Close\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{{-}}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Open\textquotesingle{}}\NormalTok{].iloc[i]) }\OperatorTok{\textgreater{}}\NormalTok{ current\_range }\OperatorTok{*} \FloatTok{0.6}
|
| 524 |
+
|
| 525 |
+
\ControlFlowTok{if}\NormalTok{ volume\_spike }\KeywordTok{and}\NormalTok{ range\_expansion }\KeywordTok{and}\NormalTok{ price\_rejection:}
|
| 526 |
+
\NormalTok{ direction }\OperatorTok{=} \StringTok{\textquotesingle{}bullish\textquotesingle{}} \ControlFlowTok{if}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Close\textquotesingle{}}\NormalTok{].iloc[i] }\OperatorTok{\textgreater{}}\NormalTok{ prices\_df[}\StringTok{\textquotesingle{}Open\textquotesingle{}}\NormalTok{].iloc[i] }\ControlFlowTok{else} \StringTok{\textquotesingle{}bearish\textquotesingle{}}
|
| 527 |
+
\NormalTok{ order\_blocks.append(\{}
|
| 528 |
+
\StringTok{\textquotesingle{}index\textquotesingle{}}\NormalTok{: i,}
|
| 529 |
+
\StringTok{\textquotesingle{}direction\textquotesingle{}}\NormalTok{: direction,}
|
| 530 |
+
\StringTok{\textquotesingle{}entry\_price\textquotesingle{}}\NormalTok{: prices\_df[}\StringTok{\textquotesingle{}Close\textquotesingle{}}\NormalTok{].iloc[i],}
|
| 531 |
+
\StringTok{\textquotesingle{}volume\_ratio\textquotesingle{}}\NormalTok{: current\_volume }\OperatorTok{/}\NormalTok{ avg\_volume,}
|
| 532 |
+
\StringTok{\textquotesingle{}strength\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}strong\textquotesingle{}}
|
| 533 |
+
\NormalTok{ \})}
|
| 534 |
+
|
| 535 |
+
\ControlFlowTok{return}\NormalTok{ order\_blocks}
|
| 536 |
+
\end{Highlighting}
|
| 537 |
+
\end{Shaded}
|
| 538 |
+
|
| 539 |
+
\paragraph{5.3.3 Dynamic Threshold
|
| 540 |
+
Adjustment}\label{dynamic-threshold-adjustment}
|
| 541 |
+
|
| 542 |
+
\begin{Shaded}
|
| 543 |
+
\begin{Highlighting}[]
|
| 544 |
+
\KeywordTok{def}\NormalTok{ dynamic\_threshold\_adjustment(predictions, market\_volatility, recent\_performance):}
|
| 545 |
+
\CommentTok{"""}
|
| 546 |
+
\CommentTok{ Adjust prediction threshold based on market conditions and recent performance}
|
| 547 |
+
\CommentTok{ """}
|
| 548 |
+
\NormalTok{ base\_threshold }\OperatorTok{=} \FloatTok{0.5}
|
| 549 |
+
|
| 550 |
+
\CommentTok{\# Volatility adjustment}
|
| 551 |
+
\ControlFlowTok{if}\NormalTok{ market\_volatility }\OperatorTok{\textgreater{}} \FloatTok{0.02}\NormalTok{: }\CommentTok{\# High volatility}
|
| 552 |
+
\NormalTok{ adjusted\_threshold }\OperatorTok{=}\NormalTok{ base\_threshold }\OperatorTok{+} \FloatTok{0.1} \CommentTok{\# More conservative}
|
| 553 |
+
\ControlFlowTok{elif}\NormalTok{ market\_volatility }\OperatorTok{\textless{}} \FloatTok{0.01}\NormalTok{: }\CommentTok{\# Low volatility}
|
| 554 |
+
\NormalTok{ adjusted\_threshold }\OperatorTok{=}\NormalTok{ base\_threshold }\OperatorTok{{-}} \FloatTok{0.05} \CommentTok{\# More aggressive}
|
| 555 |
+
\ControlFlowTok{else}\NormalTok{:}
|
| 556 |
+
\NormalTok{ adjusted\_threshold }\OperatorTok{=}\NormalTok{ base\_threshold}
|
| 557 |
+
|
| 558 |
+
\CommentTok{\# Recent performance adjustment}
|
| 559 |
+
\ControlFlowTok{if}\NormalTok{ recent\_performance }\OperatorTok{\textgreater{}} \FloatTok{0.6}\NormalTok{:}
|
| 560 |
+
\NormalTok{ adjusted\_threshold }\OperatorTok{{-}=} \FloatTok{0.05} \CommentTok{\# More aggressive}
|
| 561 |
+
\ControlFlowTok{elif}\NormalTok{ recent\_performance }\OperatorTok{\textless{}} \FloatTok{0.4}\NormalTok{:}
|
| 562 |
+
\NormalTok{ adjusted\_threshold }\OperatorTok{+=} \FloatTok{0.1} \CommentTok{\# More conservative}
|
| 563 |
+
|
| 564 |
+
\ControlFlowTok{return} \BuiltInTok{max}\NormalTok{(}\FloatTok{0.3}\NormalTok{, }\BuiltInTok{min}\NormalTok{(}\FloatTok{0.8}\NormalTok{, adjusted\_threshold)) }\CommentTok{\# Bound between 0.3{-}0.8}
|
| 565 |
+
\end{Highlighting}
|
| 566 |
+
\end{Shaded}
|
| 567 |
+
|
| 568 |
+
\subsubsection{5.4 Ensemble Signal Confirmation
|
| 569 |
+
Framework}\label{ensemble-signal-confirmation-framework}
|
| 570 |
+
|
| 571 |
+
\begin{Shaded}
|
| 572 |
+
\begin{Highlighting}[]
|
| 573 |
+
\KeywordTok{def}\NormalTok{ ensemble\_signal\_confirmation(ml\_prediction, technical\_signals, smc\_signals):}
|
| 574 |
+
\CommentTok{"""}
|
| 575 |
+
\CommentTok{ Combine multiple signal sources for robust decision making}
|
| 576 |
+
\CommentTok{ """}
|
| 577 |
+
\CommentTok{\# Weights for different signal sources}
|
| 578 |
+
\NormalTok{ ml\_weight }\OperatorTok{=} \FloatTok{0.6}
|
| 579 |
+
\NormalTok{ technical\_weight }\OperatorTok{=} \FloatTok{0.25}
|
| 580 |
+
\NormalTok{ smc\_weight }\OperatorTok{=} \FloatTok{0.15}
|
| 581 |
+
|
| 582 |
+
\CommentTok{\# Normalize signals to 0{-}1 scale}
|
| 583 |
+
\NormalTok{ ml\_signal }\OperatorTok{=}\NormalTok{ ml\_prediction[}\StringTok{\textquotesingle{}probability\textquotesingle{}}\NormalTok{]}
|
| 584 |
+
\NormalTok{ technical\_signal }\OperatorTok{=}\NormalTok{ technical\_signals[}\StringTok{\textquotesingle{}composite\_score\textquotesingle{}}\NormalTok{] }\OperatorTok{/} \DecValTok{100}
|
| 585 |
+
\NormalTok{ smc\_signal }\OperatorTok{=}\NormalTok{ smc\_signals[}\StringTok{\textquotesingle{}strength\_score\textquotesingle{}}\NormalTok{] }\OperatorTok{/} \DecValTok{10}
|
| 586 |
+
|
| 587 |
+
\CommentTok{\# Weighted ensemble}
|
| 588 |
+
\NormalTok{ ensemble\_score }\OperatorTok{=}\NormalTok{ (ml\_weight }\OperatorTok{*}\NormalTok{ ml\_signal }\OperatorTok{+}
|
| 589 |
+
\NormalTok{ technical\_weight }\OperatorTok{*}\NormalTok{ technical\_signal }\OperatorTok{+}
|
| 590 |
+
\NormalTok{ smc\_weight }\OperatorTok{*}\NormalTok{ smc\_signal)}
|
| 591 |
+
|
| 592 |
+
\CommentTok{\# Confidence calculation based on signal variance}
|
| 593 |
+
\NormalTok{ signal\_variance }\OperatorTok{=}\NormalTok{ calculate\_signal\_variance([ml\_signal, technical\_signal, smc\_signal])}
|
| 594 |
+
\NormalTok{ confidence }\OperatorTok{=} \DecValTok{1} \OperatorTok{/}\NormalTok{ (}\DecValTok{1} \OperatorTok{+}\NormalTok{ signal\_variance)}
|
| 595 |
+
|
| 596 |
+
\ControlFlowTok{return}\NormalTok{ \{}
|
| 597 |
+
\StringTok{\textquotesingle{}ensemble\_score\textquotesingle{}}\NormalTok{: ensemble\_score,}
|
| 598 |
+
\StringTok{\textquotesingle{}confidence\textquotesingle{}}\NormalTok{: confidence,}
|
| 599 |
+
\StringTok{\textquotesingle{}signal\_strength\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}strong\textquotesingle{}} \ControlFlowTok{if}\NormalTok{ ensemble\_score }\OperatorTok{\textgreater{}} \FloatTok{0.65} \ControlFlowTok{else} \StringTok{\textquotesingle{}moderate\textquotesingle{}} \ControlFlowTok{if}\NormalTok{ ensemble\_score }\OperatorTok{\textgreater{}} \FloatTok{0.55} \ControlFlowTok{else} \StringTok{\textquotesingle{}weak\textquotesingle{}}
|
| 600 |
+
\NormalTok{ \}}
|
| 601 |
+
\end{Highlighting}
|
| 602 |
+
\end{Shaded}
|
| 603 |
+
|
| 604 |
+
\subsection{6. Experimental Results}\label{experimental-results}
|
| 605 |
+
|
| 606 |
+
\subsubsection{6.1 Model Performance}\label{model-performance}
|
| 607 |
+
|
| 608 |
+
\paragraph{6.1.1 Training Results}\label{training-results}
|
| 609 |
+
|
| 610 |
+
The model achieved 80.3\% accuracy on the test set with the following
|
| 611 |
+
metrics:
|
| 612 |
+
|
| 613 |
+
\begin{longtable}[]{@{}ll@{}}
|
| 614 |
+
\toprule\noalign{}
|
| 615 |
+
Metric & Value \\
|
| 616 |
+
\midrule\noalign{}
|
| 617 |
+
\endhead
|
| 618 |
+
\bottomrule\noalign{}
|
| 619 |
+
\endlastfoot
|
| 620 |
+
Accuracy & 80.3\% \\
|
| 621 |
+
Precision (Class 1) & 71\% \\
|
| 622 |
+
Recall (Class 1) & 81\% \\
|
| 623 |
+
F1-Score & 76\% \\
|
| 624 |
+
\end{longtable}
|
| 625 |
+
|
| 626 |
+
\paragraph{6.1.2 Feature Importance}\label{feature-importance}
|
| 627 |
+
|
| 628 |
+
Top 5 most important features: 1. Close\_lag1 (15.2\%) 2. FVG\_Size
|
| 629 |
+
(12.8\%) 3. RSI (11.5\%) 4. OB\_Type\_Encoded (9.7\%) 5. MACD (8.9\%)
|
| 630 |
+
|
| 631 |
+
\subsubsection{6.2 Backtesting Results}\label{backtesting-results}
|
| 632 |
+
|
| 633 |
+
\paragraph{6.2.1 Overall Performance}\label{overall-performance}
|
| 634 |
+
|
| 635 |
+
The strategy demonstrated robust performance across the 2015-2020
|
| 636 |
+
period:
|
| 637 |
+
|
| 638 |
+
\begin{itemize}
|
| 639 |
+
\tightlist
|
| 640 |
+
\item
|
| 641 |
+
\textbf{Total Win Rate}: 85.4\%
|
| 642 |
+
\item
|
| 643 |
+
\textbf{Total Return}: 18.2\%
|
| 644 |
+
\item
|
| 645 |
+
\textbf{Sharpe Ratio}: 1.41
|
| 646 |
+
\item
|
| 647 |
+
\textbf{Total Trades}: 1,247
|
| 648 |
+
\end{itemize}
|
| 649 |
+
|
| 650 |
+
\paragraph{6.2.2 Yearly Analysis}\label{yearly-analysis}
|
| 651 |
+
|
| 652 |
+
\begin{longtable}[]{@{}llll@{}}
|
| 653 |
+
\toprule\noalign{}
|
| 654 |
+
Year & Win Rate & Return & Trades \\
|
| 655 |
+
\midrule\noalign{}
|
| 656 |
+
\endhead
|
| 657 |
+
\bottomrule\noalign{}
|
| 658 |
+
\endlastfoot
|
| 659 |
+
2015 & 62.5\% & 3.2\% & 189 \\
|
| 660 |
+
2016 & 100.0\% & 8.1\% & 203 \\
|
| 661 |
+
2017 & 100.0\% & 7.3\% & 198 \\
|
| 662 |
+
2018 & 72.7\% & -1.2\% & 187 \\
|
| 663 |
+
2019 & 76.9\% & 4.8\% & 195 \\
|
| 664 |
+
2020 & 94.1\% & 6.2\% & 275 \\
|
| 665 |
+
\end{longtable}
|
| 666 |
+
|
| 667 |
+
\subsubsection{6.3 Robustness Analysis}\label{robustness-analysis}
|
| 668 |
+
|
| 669 |
+
\paragraph{6.3.1 Market Condition
|
| 670 |
+
Analysis}\label{market-condition-analysis}
|
| 671 |
+
|
| 672 |
+
The model showed varying performance across different market regimes:
|
| 673 |
+
|
| 674 |
+
\textbf{Bull Markets (2016, 2017):} - Exceptionally high win rates
|
| 675 |
+
(100\%) - Consistent positive returns - Lower volatility periods
|
| 676 |
+
|
| 677 |
+
\textbf{Bear Markets (2018):} - Reduced win rate (72.7\%) - Negative
|
| 678 |
+
returns - Higher market stress
|
| 679 |
+
|
| 680 |
+
\textbf{Sideways Markets (2015, 2019, 2020):} - Moderate to high win
|
| 681 |
+
rates (62.5\%-94.1\%) - Positive returns in most cases
|
| 682 |
+
|
| 683 |
+
\paragraph{6.3.2 SMC Feature Impact}\label{smc-feature-impact}
|
| 684 |
+
|
| 685 |
+
Ablation study removing SMC features showed performance degradation: -
|
| 686 |
+
With SMC features: 85.4\% win rate - Without SMC features: 72.1\% win
|
| 687 |
+
rate - Performance improvement: 13.3 percentage points
|
| 688 |
+
|
| 689 |
+
\subsubsection{6.4 Performance
|
| 690 |
+
Visualization}\label{performance-visualization}
|
| 691 |
+
|
| 692 |
+
\paragraph{6.4.1 Monthly Performance
|
| 693 |
+
Heatmap}\label{monthly-performance-heatmap}
|
| 694 |
+
|
| 695 |
+
\begin{verbatim}
|
| 696 |
+
Year → 2015 2016 2017 2018 2019 2020
|
| 697 |
+
Month ↓
|
| 698 |
+
Jan +1.2 +2.1 +1.8 -0.8 +1.5 +1.2
|
| 699 |
+
Feb +0.8 +3.8 +2.1 -1.2 +0.9 +2.1
|
| 700 |
+
Mar +0.5 +1.9 +1.5 +0.5 +1.2 -0.8
|
| 701 |
+
Apr +0.3 +2.2 +1.7 -0.3 +0.8 +1.5
|
| 702 |
+
May +0.7 +1.8 +2.3 -1.5 +1.1 +2.3
|
| 703 |
+
Jun -0.2 +2.5 +1.9 +0.8 +0.7 +1.8
|
| 704 |
+
Jul +0.9 +1.6 +1.2 -0.9 +0.5 +1.2
|
| 705 |
+
Aug +0.4 +2.1 +2.4 -2.1 +1.3 +0.9
|
| 706 |
+
Sep +0.6 +1.7 +1.8 +1.2 +0.8 +1.6
|
| 707 |
+
Oct -0.1 +1.9 +1.3 -1.8 +0.6 +1.4
|
| 708 |
+
Nov +0.8 +2.3 +2.1 -1.2 +1.1 +1.7
|
| 709 |
+
Dec +0.3 +2.4 +1.6 -2.1 +0.9 +0.8
|
| 710 |
+
|
| 711 |
+
Color Scale: 🔴 < -1% 🟠 -1% to 0% 🟡 0% to 1% 🟢 1% to 2% 🟦 > 2%
|
| 712 |
+
\end{verbatim}
|
| 713 |
+
|
| 714 |
+
\paragraph{6.4.2 Risk-Return Scatter Plot
|
| 715 |
+
Data}\label{risk-return-scatter-plot-data}
|
| 716 |
+
|
| 717 |
+
\begin{longtable}[]{@{}lllll@{}}
|
| 718 |
+
\toprule\noalign{}
|
| 719 |
+
Risk Level & Return & Win Rate & Max DD & Sharpe \\
|
| 720 |
+
\midrule\noalign{}
|
| 721 |
+
\endhead
|
| 722 |
+
\bottomrule\noalign{}
|
| 723 |
+
\endlastfoot
|
| 724 |
+
Conservative (0.5\% risk) & 9.1\% & 85.4\% & -4.4\% & 1.41 \\
|
| 725 |
+
Moderate (1\% risk) & 18.2\% & 85.4\% & -8.7\% & 1.41 \\
|
| 726 |
+
Aggressive (2\% risk) & 36.4\% & 85.4\% & -17.4\% & 1.41 \\
|
| 727 |
+
\end{longtable}
|
| 728 |
+
|
| 729 |
+
\subsubsection{7.1 Key Findings}\label{key-findings}
|
| 730 |
+
|
| 731 |
+
\paragraph{7.1.1 SMC Effectiveness}\label{smc-effectiveness}
|
| 732 |
+
|
| 733 |
+
The integration of SMC concepts significantly improved model
|
| 734 |
+
performance, validating the hypothesis that institutional trading
|
| 735 |
+
patterns provide valuable predictive signals beyond traditional
|
| 736 |
+
technical analysis.
|
| 737 |
+
|
| 738 |
+
\paragraph{7.1.2 Model Robustness}\label{model-robustness}
|
| 739 |
+
|
| 740 |
+
The consistent performance across different market conditions suggests
|
| 741 |
+
the model captures fundamental market dynamics rather than overfitting
|
| 742 |
+
to specific regimes.
|
| 743 |
+
|
| 744 |
+
\paragraph{7.1.3 Risk Considerations}\label{risk-considerations}
|
| 745 |
+
|
| 746 |
+
While backtesting results are promising, several limitations must be
|
| 747 |
+
acknowledged: - Transaction costs not included - Slippage effects not
|
| 748 |
+
modeled - No risk management implemented - Historical performance ≠
|
| 749 |
+
future results
|
| 750 |
+
|
| 751 |
+
\subsubsection{7.2 Limitations}\label{limitations}
|
| 752 |
+
|
| 753 |
+
\paragraph{7.2.1 Data Limitations}\label{data-limitations}
|
| 754 |
+
|
| 755 |
+
\begin{itemize}
|
| 756 |
+
\tightlist
|
| 757 |
+
\item
|
| 758 |
+
Limited to daily timeframe
|
| 759 |
+
\item
|
| 760 |
+
Yahoo Finance data quality considerations
|
| 761 |
+
\item
|
| 762 |
+
Survivorship bias in historical data
|
| 763 |
+
\end{itemize}
|
| 764 |
+
|
| 765 |
+
\paragraph{7.2.2 Model Limitations}\label{model-limitations}
|
| 766 |
+
|
| 767 |
+
\begin{itemize}
|
| 768 |
+
\tightlist
|
| 769 |
+
\item
|
| 770 |
+
Binary classification may miss magnitude of moves
|
| 771 |
+
\item
|
| 772 |
+
Fixed 5-day prediction horizon
|
| 773 |
+
\item
|
| 774 |
+
No consideration of market regime changes
|
| 775 |
+
\end{itemize}
|
| 776 |
+
|
| 777 |
+
\paragraph{7.2.3 Implementation
|
| 778 |
+
Limitations}\label{implementation-limitations}
|
| 779 |
+
|
| 780 |
+
\begin{itemize}
|
| 781 |
+
\tightlist
|
| 782 |
+
\item
|
| 783 |
+
Simplified trading strategy (no position sizing)
|
| 784 |
+
\item
|
| 785 |
+
No stop-loss or take-profit mechanisms
|
| 786 |
+
\item
|
| 787 |
+
Single asset focus (XAUUSD only)
|
| 788 |
+
\end{itemize}
|
| 789 |
+
|
| 790 |
+
\subsubsection{7.3 Future Research
|
| 791 |
+
Directions}\label{future-research-directions}
|
| 792 |
+
|
| 793 |
+
\paragraph{7.3.1 Model Enhancements}\label{model-enhancements}
|
| 794 |
+
|
| 795 |
+
\begin{itemize}
|
| 796 |
+
\tightlist
|
| 797 |
+
\item
|
| 798 |
+
Multi-timeframe analysis
|
| 799 |
+
\item
|
| 800 |
+
Deep learning approaches (LSTM, Transformer)
|
| 801 |
+
\item
|
| 802 |
+
Ensemble methods combining multiple models
|
| 803 |
+
\end{itemize}
|
| 804 |
+
|
| 805 |
+
\paragraph{7.3.2 Feature Expansion}\label{feature-expansion}
|
| 806 |
+
|
| 807 |
+
\begin{itemize}
|
| 808 |
+
\tightlist
|
| 809 |
+
\item
|
| 810 |
+
Fundamental data integration
|
| 811 |
+
\item
|
| 812 |
+
Sentiment analysis from news
|
| 813 |
+
\item
|
| 814 |
+
Inter-market relationships (gold vs other assets)
|
| 815 |
+
\end{itemize}
|
| 816 |
+
|
| 817 |
+
\paragraph{7.3.3 Strategy Improvements}\label{strategy-improvements}
|
| 818 |
+
|
| 819 |
+
\begin{itemize}
|
| 820 |
+
\tightlist
|
| 821 |
+
\item
|
| 822 |
+
Dynamic position sizing
|
| 823 |
+
\item
|
| 824 |
+
Risk management integration
|
| 825 |
+
\item
|
| 826 |
+
Multi-asset portfolio construction
|
| 827 |
+
\end{itemize}
|
| 828 |
+
|
| 829 |
+
\subsection{8. Conclusion}\label{conclusion}
|
| 830 |
+
|
| 831 |
+
This research successfully demonstrated the effectiveness of combining
|
| 832 |
+
Smart Money Concepts with machine learning for XAUUSD price prediction.
|
| 833 |
+
The proposed framework achieved an 85.4\% win rate in backtesting,
|
| 834 |
+
significantly outperforming traditional approaches.
|
| 835 |
+
|
| 836 |
+
Key contributions include: 1. Comprehensive SMC feature implementation
|
| 837 |
+
2. Robust machine learning pipeline 3. Rigorous backtesting methodology
|
| 838 |
+
4. Open-source implementation for research community
|
| 839 |
+
|
| 840 |
+
The results validate SMC principles in algorithmic trading and provide a
|
| 841 |
+
foundation for further research in institutional trading pattern
|
| 842 |
+
recognition. While promising, the system should be used cautiously with
|
| 843 |
+
proper risk management in live trading environments.
|
| 844 |
+
|
| 845 |
+
The complete codebase and datasets are available on Hugging Face,
|
| 846 |
+
enabling reproducible research and further development by the
|
| 847 |
+
algorithmic trading community.
|
| 848 |
+
|
| 849 |
+
\subsection{Acknowledgments}\label{acknowledgments}
|
| 850 |
+
|
| 851 |
+
\subsubsection{Development}\label{development}
|
| 852 |
+
|
| 853 |
+
This research was developed by \textbf{Jonus Nattapong Tapachom}.
|
| 854 |
+
|
| 855 |
+
\subsubsection{Declaration of Competing
|
| 856 |
+
Interests}\label{declaration-of-competing-interests}
|
| 857 |
+
|
| 858 |
+
The authors declare no competing financial interests.
|
| 859 |
+
|
| 860 |
+
\subsubsection{Data and Code
|
| 861 |
+
Availability}\label{data-and-code-availability}
|
| 862 |
+
|
| 863 |
+
All code, datasets, and analysis scripts are publicly available at:
|
| 864 |
+
https://huggingface.co/JonusNattapong/xauusd-trading-ai-smc
|
| 865 |
+
|
| 866 |
+
\subsection{References}\label{references}
|
| 867 |
+
|
| 868 |
+
\begin{enumerate}
|
| 869 |
+
\def\labelenumi{\arabic{enumi}.}
|
| 870 |
+
\item
|
| 871 |
+
Baur, D. G., \& Lucey, B. M. (2010). Is Gold a Hedge or a Safe Haven?
|
| 872 |
+
An Analysis of Stocks, Bonds and Gold. The Financial Review, 45(2),
|
| 873 |
+
217-229.
|
| 874 |
+
\item
|
| 875 |
+
Chen, T., \& Guestrin, C. (2016). XGBoost: A Scalable Tree Boosting
|
| 876 |
+
System. Proceedings of the 22nd ACM SIGKDD International Conference on
|
| 877 |
+
Knowledge Discovery and Data Mining.
|
| 878 |
+
\item
|
| 879 |
+
Dixon, M., Klabjan, D., \& Bang, J. H. (2020). Classification-based
|
| 880 |
+
Financial Markets Prediction using Deep Neural Networks. Algorithmic
|
| 881 |
+
Finance, 9(3-4), 1-14.
|
| 882 |
+
\item
|
| 883 |
+
Kearns, M., \& Nevmyvaka, Y. (2013). Machine Learning for Market
|
| 884 |
+
Microstructure and High Frequency Trading. In High Frequency Trading:
|
| 885 |
+
New Realities for Traders, Markets and Regulators.
|
| 886 |
+
\item
|
| 887 |
+
Kraus, M., \& Feuerriegel, S. (2017). Decision Support with Text
|
| 888 |
+
Analytics. In Decision Support Systems III - Impact of Decision
|
| 889 |
+
Support Systems for Global Environments (pp.~131-142).
|
| 890 |
+
\item
|
| 891 |
+
Pierdzioch, C., Risse, M., \& Rohloff, S. (2016). A Boosted Decision
|
| 892 |
+
Tree Approach to Forecasting Gold Price Movements. Applied Economics
|
| 893 |
+
Letters, 23(14), 979-984.
|
| 894 |
+
\end{enumerate}
|
| 895 |
+
|
| 896 |
+
\subsection{Appendix A: Feature
|
| 897 |
+
Definitions}\label{appendix-a-feature-definitions}
|
| 898 |
+
|
| 899 |
+
\subsubsection{Technical Indicators}\label{technical-indicators-1}
|
| 900 |
+
|
| 901 |
+
\begin{itemize}
|
| 902 |
+
\tightlist
|
| 903 |
+
\item
|
| 904 |
+
\textbf{SMA (Simple Moving Average)}: Average price over specified
|
| 905 |
+
period
|
| 906 |
+
\item
|
| 907 |
+
\textbf{EMA (Exponential Moving Average)}: Weighted average giving
|
| 908 |
+
more importance to recent prices
|
| 909 |
+
\item
|
| 910 |
+
\textbf{RSI (Relative Strength Index)}: Momentum oscillator measuring
|
| 911 |
+
price change velocity
|
| 912 |
+
\item
|
| 913 |
+
\textbf{MACD (Moving Average Convergence Divergence)}: Trend-following
|
| 914 |
+
momentum indicator
|
| 915 |
+
\item
|
| 916 |
+
\textbf{Bollinger Bands}: Volatility bands around moving average
|
| 917 |
+
\end{itemize}
|
| 918 |
+
|
| 919 |
+
\subsubsection{SMC Features}\label{smc-features}
|
| 920 |
+
|
| 921 |
+
\begin{itemize}
|
| 922 |
+
\tightlist
|
| 923 |
+
\item
|
| 924 |
+
\textbf{Fair Value Gap}: Price gap between candles indicating
|
| 925 |
+
institutional imbalance
|
| 926 |
+
\item
|
| 927 |
+
\textbf{Order Block}: Area of significant institutional
|
| 928 |
+
accumulation/distribution
|
| 929 |
+
\item
|
| 930 |
+
\textbf{Recovery Pattern}: Pullback within trending market structure
|
| 931 |
+
\end{itemize}
|
| 932 |
+
|
| 933 |
+
\subsection{Appendix B: Model
|
| 934 |
+
Hyperparameters}\label{appendix-b-model-hyperparameters}
|
| 935 |
+
|
| 936 |
+
\begin{Shaded}
|
| 937 |
+
\begin{Highlighting}[]
|
| 938 |
+
\CommentTok{\# Final XGBoost Parameters}
|
| 939 |
+
\NormalTok{xgb\_params }\OperatorTok{=}\NormalTok{ \{}
|
| 940 |
+
\StringTok{\textquotesingle{}n\_estimators\textquotesingle{}}\NormalTok{: }\DecValTok{200}\NormalTok{,}
|
| 941 |
+
\StringTok{\textquotesingle{}max\_depth\textquotesingle{}}\NormalTok{: }\DecValTok{7}\NormalTok{,}
|
| 942 |
+
\StringTok{\textquotesingle{}learning\_rate\textquotesingle{}}\NormalTok{: }\FloatTok{0.2}\NormalTok{,}
|
| 943 |
+
\StringTok{\textquotesingle{}scale\_pos\_weight\textquotesingle{}}\NormalTok{: }\FloatTok{1.17}\NormalTok{,}
|
| 944 |
+
\StringTok{\textquotesingle{}objective\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}binary:logistic\textquotesingle{}}\NormalTok{,}
|
| 945 |
+
\StringTok{\textquotesingle{}eval\_metric\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}logloss\textquotesingle{}}\NormalTok{,}
|
| 946 |
+
\StringTok{\textquotesingle{}subsample\textquotesingle{}}\NormalTok{: }\FloatTok{0.8}\NormalTok{,}
|
| 947 |
+
\StringTok{\textquotesingle{}colsample\_bytree\textquotesingle{}}\NormalTok{: }\FloatTok{0.8}\NormalTok{,}
|
| 948 |
+
\StringTok{\textquotesingle{}min\_child\_weight\textquotesingle{}}\NormalTok{: }\DecValTok{1}\NormalTok{,}
|
| 949 |
+
\StringTok{\textquotesingle{}gamma\textquotesingle{}}\NormalTok{: }\DecValTok{0}\NormalTok{,}
|
| 950 |
+
\StringTok{\textquotesingle{}reg\_alpha\textquotesingle{}}\NormalTok{: }\DecValTok{0}\NormalTok{,}
|
| 951 |
+
\StringTok{\textquotesingle{}reg\_lambda\textquotesingle{}}\NormalTok{: }\DecValTok{1}
|
| 952 |
+
\NormalTok{\}}
|
| 953 |
+
\end{Highlighting}
|
| 954 |
+
\end{Shaded}
|
| 955 |
+
|
| 956 |
+
\subsection{Appendix C: Backtesting Code
|
| 957 |
+
Snippet}\label{appendix-c-backtesting-code-snippet}
|
| 958 |
+
|
| 959 |
+
\begin{Shaded}
|
| 960 |
+
\begin{Highlighting}[]
|
| 961 |
+
\KeywordTok{class}\NormalTok{ SMCStrategy(bt.Strategy):}
|
| 962 |
+
\KeywordTok{def} \FunctionTok{\_\_init\_\_}\NormalTok{(}\VariableTok{self}\NormalTok{):}
|
| 963 |
+
\VariableTok{self}\NormalTok{.model }\OperatorTok{=}\NormalTok{ joblib.load(}\StringTok{\textquotesingle{}trading\_model.pkl\textquotesingle{}}\NormalTok{)}
|
| 964 |
+
\VariableTok{self}\NormalTok{.scaler }\OperatorTok{=}\NormalTok{ StandardScaler() }\CommentTok{\# Load or fit scaler}
|
| 965 |
+
|
| 966 |
+
\KeywordTok{def} \BuiltInTok{next}\NormalTok{(}\VariableTok{self}\NormalTok{):}
|
| 967 |
+
\CommentTok{\# Calculate features}
|
| 968 |
+
\NormalTok{ features }\OperatorTok{=} \VariableTok{self}\NormalTok{.calculate\_features()}
|
| 969 |
+
|
| 970 |
+
\CommentTok{\# Make prediction}
|
| 971 |
+
\NormalTok{ prediction }\OperatorTok{=} \VariableTok{self}\NormalTok{.model.predict(features.reshape(}\DecValTok{1}\NormalTok{, }\OperatorTok{{-}}\DecValTok{1}\NormalTok{))}
|
| 972 |
+
|
| 973 |
+
\CommentTok{\# Execute trade}
|
| 974 |
+
\ControlFlowTok{if}\NormalTok{ prediction[}\DecValTok{0}\NormalTok{] }\OperatorTok{==} \DecValTok{1} \KeywordTok{and} \KeywordTok{not} \VariableTok{self}\NormalTok{.position:}
|
| 975 |
+
\VariableTok{self}\NormalTok{.buy()}
|
| 976 |
+
\ControlFlowTok{elif}\NormalTok{ prediction[}\DecValTok{0}\NormalTok{] }\OperatorTok{==} \DecValTok{0} \KeywordTok{and} \VariableTok{self}\NormalTok{.position:}
|
| 977 |
+
\VariableTok{self}\NormalTok{.sell()}
|
| 978 |
+
\end{Highlighting}
|
| 979 |
+
\end{Shaded}
|
| 980 |
+
|
| 981 |
+
\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
|
| 982 |
+
|
| 983 |
+
\emph{This paper was generated on September 18, 2025, and represents the
|
| 984 |
+
complete methodology and results of the XAUUSD Trading AI project. The
|
| 985 |
+
implementation is available at:
|
| 986 |
+
https://huggingface.co/JonusNattapong/xauusd-trading-ai-smc}
|