MengNotes
BlogTagsAbout
Home/Blog/66-Day Quant Training, Days 4–10: SMA, ADX, Ichimoku, and Risk Management
Quant-Trading

66-Day Quant Training, Days 4–10: SMA, ADX, Ichimoku, and Risk Management

Days 4–10 of a 66-day quant training program: SMA, Bollinger Bands, MACD, ADX, Ichimoku, and what out-of-sample tests reveal about overfitting and risk.

March 8, 20262,187 words11 min read
#quant-trading#technical-indicators#backtesting#66-days-training#week-summary
Summary

Days 4–10 covered SMA, Bollinger Bands, MACD, ADX, and Ichimoku before returning to risk management. The useful result was not a winning indicator. Out-of-sample performance, trading costs, and stop-loss logic quickly exposed backtests that looked convincing in sample.


The Seven-Day Learning Map

DayCore TopicIndicator TypeKey Insight
Day 4SMA Strategy + IBKR IntegrationTrend FollowingMoving average crossovers, data extraction pipeline
Day 5SMA Intraday Trading AdaptationTrend Following (Short-term)Timeframe switching, SMA parameter sensitivity
Day 6Bollinger BandsVolatility + Mean ReversionThe 95% rule, the cost of overfitting
Day 7MACD Golden CrossMomentumLagging indicator behavior, histogram slope filter
Day 8ADX Trend StrengthTrend Strength FilterDirection vs. strength, false signal filtering
Day 9Ichimoku CloudAll-in-One SystemFive-line integration, the cloud as a no-trade zone
Day 10Risk Management MindsetPsychology & DisciplineIndependent stop-losses, risk of ruin, positive expectancy

Day-by-Day Notes

Days 4–5: Starting with an SMA Trend Strategy

The Simple Moving Average (SMA) is straightforward: calculate the arithmetic mean of the past NNN closing prices.

SMAN=1N∑i=1NPiSMA_N = \frac{1}{N} \sum_{i=1}^{N} P_iSMAN​=N1​i=1∑N​Pi​
Core Concept

The SMA smooths noise so price direction is easier to see. A crossover is a possible trend-shift signal, not a prediction by itself.

What We Learned in Practice

  • Day 4: We used the IBKR API to extract historical data for the MAG7 stocks (MSFT, AAPL, TSLA, NVDA, META, GOOGL, AMZN) and searched for an SMA window for each ticker. The same parameter set did not transfer cleanly across all seven.
  • Day 5: We converted a daily SMA 200 strategy into a 1-minute SMA 5 intraday script. The shorter timeframe made signals more responsive and increased false signals sharply.
Shorter Periods = More Noise

SMA 5 on a 1-minute chart is extremely jittery. Faster pace does not equal higher returns; it demands even stricter entry/exit discipline.


Day 6: Describing Volatility with Bollinger Bands

Bollinger Bands consist of three lines:

  • Middle Band: SMA (typically 20-day)
  • Upper Band: SMA + k×σk \times \sigmak×σ (typically k=2k = 2k=2)
  • Lower Band: SMA - k×σk \times \sigmak×σ

Where σ\sigmaσ is the standard deviation of closing prices.

The 95% Rule

Under a normal-distribution assumption, about 95% of observations fall within ±2 standard deviations. A band break does not guarantee reversal; it only says price is far from its recent average.

Backtest Results and Reflection

Using AAPL with a "buy at lower band, sell at upper band" mean-reversion logic over ten years:

MetricIn-Sample (2016–2021)Out-of-Sample (2022–2026)
CAGR25.99%8.85%
Sharpe1.200.59
Max Drawdown-31.43%-16.61%
  • The grid search's best parameters (SMA=20, σ=3.0) produced a Sharpe 2.05× above the mean, an overfitting warning.
  • The 3σ bandwidth was rarely touched (only 1 trade out-of-sample), meaning the strategy sat in cash most of the time — low drawdown but also low returns.
  • AAPL exhibited a strong uptrend over 2016–2026; a pure mean-reversion strategy sold too early at the upper band, missing extended trend gains.
Key Lesson

A parameter set that ranks first in a backtest is not automatically best for the future. Here, the result looks more like an overfitting warning.


Day 7: Using MACD to Read Momentum

MACD stands for Moving Average Convergence Divergence. It measures momentum through the relationship between two exponential moving averages.

MACD=EMA12−EMA26MACD = EMA_{12} - EMA_{26}MACD=EMA12​−EMA26​ Signal=EMA9(MACD)Signal = EMA_9(MACD)Signal=EMA9​(MACD) Histogram=MACD−SignalHistogram = MACD - SignalHistogram=MACD−Signal
Golden Cross & Death Cross
  • Golden Cross: MACD crosses above the signal line, treated as a bullish momentum signal
  • Death Cross: MACD crosses below the signal line, treated as a bearish momentum signal

Advanced Technique: Histogram Slope Filter

Pure crossover signals are prone to whipsaws in ranging markets. Adding a histogram slope filter:

  • Only allow buy entries when the histogram is rising
  • Only allow sell entries when the histogram is falling

This confirmation layer removes some false signals and delays entry. That is the trade: more confirmation, less timeliness.


Day 8: ADX Measures Strength, Not Direction

ADX (Average Directional Index) does not generate direction by itself. It measures whether a trend exists and how strong that trend is.

How ADX Is Calculated

ADX isn't derived directly from price — it goes through multiple layers of processing. The full calculation chain breaks down into five steps:

Step 1: Directional Movement (+DM / -DM)

For each bar, compare the current high/low against the previous bar:

+DM={Hight−Hight−1if Hight−Hight−1>Lowt−1−Lowt and >00otherwise+DM = \begin{cases} High_t - High_{t-1} & \text{if } High_t - High_{t-1} > Low_{t-1} - Low_t \text{ and } > 0 \\ 0 & \text{otherwise} \end{cases}+DM={Hight​−Hight−1​0​if Hight​−Hight−1​>Lowt−1​−Lowt​ and >0otherwise​ −DM={Lowt−1−Lowtif Lowt−1−Lowt>Hight−Hight−1 and >00otherwise-DM = \begin{cases} Low_{t-1} - Low_t & \text{if } Low_{t-1} - Low_t > High_t - High_{t-1} \text{ and } > 0 \\ 0 & \text{otherwise} \end{cases}−DM={Lowt−1​−Lowt​0​if Lowt−1​−Lowt​>Hight​−Hight−1​ and >0otherwise​

In plain terms: +DM captures the magnitude of "upward breakouts," while -DM captures "downward breakouts."

Step 2: True Range (TR)

TR=max⁡(Hight−Lowt,  ∣Hight−Closet−1∣,  ∣Lowt−Closet−1∣)TR = \max(High_t - Low_t,\; |High_t - Close_{t-1}|,\; |Low_t - Close_{t-1}|)TR=max(Hight​−Lowt​,∣Hight​−Closet−1​∣,∣Lowt​−Closet−1​∣)

TR measures each bar's actual volatility range, accounting for gap openings.

Step 3: Wilder's Smoothing

Apply Wilder's smoothed moving average (typically N=14N = 14N=14) to +DM, -DM, and TR separately:

Smoothedt=Smoothedt−1−Smoothedt−1N+ValuetSmoothed_{t} = Smoothed_{t-1} - \frac{Smoothed_{t-1}}{N} + Value_tSmoothedt​=Smoothedt−1​−NSmoothedt−1​​+Valuet​
Wilder's Smoothing vs Regular EMA

Wilder's smoothing is equivalent to a 2N−12N - 12N−1 period EMA. So ADX 14 actually decays at roughly the same rate as EMA 27 — slower than you might intuitively expect.

Step 4: Directional Indicators (+DI / -DI) and DX

+DI=Smoothed(+DM)Smoothed(TR)×100+DI = \frac{Smoothed(+DM)}{Smoothed(TR)} \times 100+DI=Smoothed(TR)Smoothed(+DM)​×100 −DI=Smoothed(−DM)Smoothed(TR)×100-DI = \frac{Smoothed(-DM)}{Smoothed(TR)} \times 100−DI=Smoothed(TR)Smoothed(−DM)​×100 DX=∣+DI−(−DI)∣+DI+(−DI)×100DX = \frac{|+DI - (-DI)|}{+DI + (-DI)} \times 100DX=+DI+(−DI)∣+DI−(−DI)∣​×100

+DI represents the proportion of upward momentum relative to total volatility; -DI represents the downward proportion. DX measures the "divergence" between the two.

Step 5: ADX = Smoothed DX

ADX=1N∑i=1NDXi(initial value)ADX = \frac{1}{N} \sum_{i=1}^{N} DX_i \quad \text{(initial value)}ADX=N1​i=1∑N​DXi​(initial value) ADXt=ADXt−1×(N−1)+DXtN(subsequent values)ADX_t = \frac{ADX_{t-1} \times (N-1) + DX_t}{N} \quad \text{(subsequent values)}ADXt​=NADXt−1​×(N−1)+DXt​​(subsequent values)

The final ADX applies one more round of smoothing to DX, making the trend-strength reading more stable and less reactive to single-day spikes.

No Need to Calculate by Hand!

In practice, one line of Python calculates it: ta.trend.ADXIndicator(high, low, close, window=14). The formula matters because two smoothing stages make ADX slow, so it is better suited to confirmation than prediction.

ADX Value Interpretation

ADX ValueTrend StrengthSuggested Action
0–20Weak / No TrendStay on the sidelines
20–40Moderate TrendTrend is forming
40–60Strong TrendSuitable for trend-following
60–100Extreme TrendExceptionally strong momentum

ADX works alongside +DI (Positive Directional Indicator) and -DI (Negative Directional Indicator):

  • Buy: ADX > 25 and +DI crosses above -DI
  • Sell: ADX > 25 and -DI crosses above +DI
The Real Value of ADX

ADX works better as a filter than as a direction signal. ADX > 25 only says trend strength has crossed the chosen threshold; +DI, -DI, or another condition still has to supply direction.


Day 9: Ichimoku Puts Several Readings on One Chart

Ichimoku Kinko Hyo displays trend direction, momentum strength, and support or resistance on one chart through five lines:

ComponentCalculationRole Analogy
Tenkan-sen (Conversion Line)(9-day High + 9-day Low) ÷ 2The Scout — quick, responsive short-term detection
Kijun-sen (Base Line)(26-day High + 26-day Low) ÷ 2The General — stable, authoritative medium-term anchor
Senkou Span A (Leading Span A)(Tenkan + Kijun) ÷ 2, shifted forward 26 periodsUpper or lower edge of the cloud
Senkou Span B (Leading Span B)(52-day High + 52-day Low) ÷ 2, shifted forward 26 periodsThe other edge of the cloud
Chikou Span (Lagging Span)Current close, shifted backward 26 periodsThe Second Confirmer
The Cloud (Kumo) = No-Trade Zone

The area between Senkou Span A and B forms the "cloud."

  • Price above the cloud → bullish environment
  • Price below the cloud → bearish environment
  • Price inside the cloud → direction unclear, best to wait

Compared to a Single MA Strategy

While SMA only tells you "where price is relative to the average," Ichimoku simultaneously provides:

  1. Forward-looking perspective: The cloud extends into the future, letting you anticipate support and resistance zones
  2. Multi-dimensional confirmation: Tenkan/Kijun crossover + cloud position + Chikou Span — triple confirmation reduces false signals
  3. Built-in momentum reading: The distance between price and cloud indicates momentum strength; convergence signals weakening momentum

The tradeoff: signals are more conservative, trading frequency is lower, and opportunities in choppy markets are often missed.


Day 10: How a $1.88 Million Account Went to Zero

There was no code on Day 10. We read about a trader who ran a quantitative strategy called Imhotep. The account reached $1.88 million, then went to zero overnight after untested stop-loss code, absent monitoring, 100% capital deployment, and leverage combined in one liquidation event.

His Fatal Mistakes
  1. Using leverage
  2. Not testing the stop-loss logic
  3. No proper monitoring or alert system
  4. Trading with 100% of his capital
  5. Believing he was invincible when things were going well

My Safety Net Framework

Drawing from The Trading Bible's core philosophy, I distilled three survival principles:

Principle 1: Drive Single-Trade Risk Toward Zero

  • Maximum risk per trade ≤ 1% of total capital
  • Calculate leverage based on actual exposure, not nominal position size

Principle 2: Maximize Your Survival in the Market

  • Even after 20 consecutive stop-losses, the account retains 80%+ of its capital
  • Separate "trading capital" from "reserve capital" — the reserve is never touched

Principle 3: Ensure Positive Expected Value

E=(W×Gˉ)−(L×Lˉ)>0E = (W \times \bar{G}) - (L \times \bar{L}) > 0E=(W×Gˉ)−(L×Lˉ)>0

Where WWW = win rate, Gˉ\bar{G}Gˉ = average gain, LLL = loss rate, Lˉ\bar{L}Lˉ = average loss. Only strategies with positive expected value are worth executing.

Quote

Code can execute your logic, but only your risk awareness can keep you in the game.


Problems That Recurred Across Seven Days

In-Sample Winners Rarely Stay Winners Out of Sample

Every parameter optimization is a battle against overfitting. Across Day 6 (Bollinger Bands), Day 7 (MACD), Day 8 (ADX), and Day 9 (Ichimoku), we repeatedly confirmed the same truth:

The best in-sample parameters often lose their lead out of sample.

How to cope:

  1. Always split data into in-sample (training) and out-of-sample (validation) periods
  2. When reading Sharpe heatmaps, choose the "plateau" over the "peak" — a stable parameter region is more reliable than a single optimal point
  3. When in-sample Sharpe dramatically exceeds out-of-sample, that's the overfitting red flag

The R.E.A.L. Backtesting Framework

All backtests followed the R.E.A.L. principles:

  • Realistic: Include commissions ($0.005/share) and slippage (0.05%)
  • Evidence-based: Validate phase by phase, never skip steps
  • Avoiding Bias: Apply signal.shift(1) — execute on the next bar's open to prevent look-ahead bias
  • Logged: Document observations in Markdown at every phase for reproducibility

Indicator Selection Quick Reference

Market ConditionWell-Suited IndicatorsLess Suitable Indicators
Clear TrendSMA, MACD, IchimokuBollinger Bands (mean reversion)
Range-BoundBollinger Bands, RSIMACD, ADX
Uncertain DirectionADX (to confirm whether it's worth trading)All signal-type indicators
Need Comprehensive ViewIchimoku (trend + momentum + S/R)Any single indicator alone
No Universal Indicator Exists

Every indicator depends on a market regime. Identifying that regime before selecting a tool is more useful than searching for one universally “best” indicator.


Five Rules from the Week

  1. Simple strategies tend to be more robust. The more complex the system, the more likely it breaks in live trading.
  2. Backtests are maps, not territories. Historical data is perfect; markets are not.
  3. Risk management comes before everything. Survive first, profit second.
  4. Lagging isn't a flaw — it's a feature. An extra layer of confirmation means fewer false signals.
  5. Don't chase "optimal" — chase "robust." Peaks on a Sharpe heatmap are traps; plateaus are where you want to be.

What's Next

Day 11 starts RSI divergence and indicator combinations, using the same out-of-sample checks and R.E.A.L. framework.

Table of Contents

The Seven-Day Learning MapDay-by-Day NotesDays 4–5: Starting with an SMA Trend StrategyDay 6: Describing Volatility with Bollinger BandsDay 7: Using MACD to Read MomentumDay 8: ADX Measures Strength, Not DirectionDay 9: Ichimoku Puts Several Readings on One ChartDay 10: How a $1.88 Million Account Went to ZeroProblems That Recurred Across Seven DaysIn-Sample Winners Rarely Stay Winners Out of SampleThe R.E.A.L. Backtesting FrameworkIndicator Selection Quick ReferenceFive Rules from the Week
← Back to all posts

© 2024-2026 MengNotes | All Rights Reserved