TL;DR: I just finished guest-lecturing at Boston University’s Questrom School of Business on our book Hands-On AI Trading with Python, QuantConnect, and AWS. The core message: modern traders who rely on a single strategy are bringing a knife to a gunfight. You need a chest of diverse strategies — classical ML, deep learning, generative AI — and the judgment to know when each one works. The book gives you 20+ battle-tested strategies. This post digs deep into one of the most powerful: using CNNs to detect technical analysis patterns like the head-and-shoulders, and the research showing why neural networks are transforming chart pattern recognition across asset classes.

A home office setup at night with three monitors displaying stock charts and code, a keyboard, mouse, an open book, and a glass of dark beverage on a desk, with city lights visible through the window.

What We Covered at BU — and Why It Matters

Earlier today, I joined my co-authors Jared Broad (QuantConnect), Vivek Singh (AWS), and Philip Sun (BU) via Zoom to deliver a guest lecture for Philip’s MF821 class — Algorithmic and High-Frequency Trading in BU’s MS in Mathematical Finance & Financial Technology programme.

I presented two sessions. The first covered the book’s full architecture — 20+ implemented AI strategies spanning three generations of techniques. The second went deep on one specific strategy: real-time head-and-shoulders pattern detection using a Convolutional Neural Network (CNN), turning a textbook chart pattern into a live risk overlay.

Slide Deck 1: Book Overview

20260324-Book-Overview

Slide Deck 2: Head-and-Shoulders CNN Strategy Deep Dive

20260325-HS-Trading-Strategy-Overview

The slides are dense — 35+ pages of architecture, code, and backtest results. But the philosophical thread running through both presentations is simple: the age of the single-strategy trader is over.

Why You Need a Chest of Strategies, Not Just One

Here’s the uncomfortable truth I shared with the BU students: no single strategy works in all market regimes. I’ve seen this firsthand. A momentum strategy that prints money in trending markets gets slaughtered in mean-reverting chop. An RL hedging model that performs beautifully in low-vol environments nearly blows up during vol spikes.

The book covers three generations of AI trading, and each has its sweet spot:

GenerationTechniquesBest ForWeakness
Classical ML (2000s–2010s)Random Forests, SVM, HMMStock selection, regime detection, mean reversionStruggles with complex nonlinear relationships 
Deep Learning (2010s–2020s)CNNs, Temporal CNNsPattern recognition, time series predictionNeeds large datasets, can overfit 
LLMs & Generative AI (2020s+)GPT, FinBERT, ChronosNews analysis, sentiment, unstructured dataHallucination risk, latency 

Most books teach one generation. We teach all three. Because markets require the right tool for each job.

The strategies in the book aren’t academic exercises — they’re designed to be composed. Use an HMM for regime detection, a CNN for pattern risk overlay, corrective AI (meta-labeling) to filter false signals, and an LLM to process news sentiment. Stack them. That’s how institutional desks actually operate.

Why CNNs Are Transforming Technical Analysis

I spent the bulk of the second session on this because it’s one of the most underrated applications of deep learning in finance: treating price charts as images and letting a CNN learn the patterns.

Traditional technical analysis has a fundamental scalability problem. Hand-drawing patterns works on one chart. Try doing it across 3,000 stocks in real time. Rule-based detection sounds better — until you realize you need dozens of arbitrary thresholds: shoulder height tolerance, neckline angle range, lookback window, volume decline percentage. Rules tuned for EURUSD don’t work for AAPL. Rules tuned for 2020’s bull market fail in 2022’s drawdown.

CNNs solve this because they provide what traders actually need — shape invariance:

  • Shift invariant — pattern at the beginning or end of a window gets the same detection
  • Scale invariant — normalize prices, and it works at $50 or $5,000
  • Noise tolerant — pooling layers filter minor fluctuations
  • Learned features — no hand-crafted rules to break

As I put it during the lecture: “We turned a trader’s eyeball test into a differentiable mathematical function that can run 10,000 times per second.”

Which Technical Patterns Benefit Most from Neural Networks?

This is the question I get asked most. Not all patterns benefit equally from CNN detection. Based on the Bulkowski studies (2007–2025), our own backtesting, and recent academic research, here’s where neural networks deliver the most edge:

PatternCNN Detection AccuracyHistorical Success RateAvg Move After ConfirmationBest Asset ClassesNotes
Head & Shoulders (top)97% synthetic / 76% real-world 81% meet price target –16% from neckline break Forex (81%), indices (75%), large-cap stocks (72%) Volume confirmation pushes success to 89% 
Double Top / Bottom~85–90% synthetic73% (top), 78% (bottom)–12% (top), +14% (bottom)Equities, forexSimilar CNN architecture; symmetry detection is CNN’s strength 
Bullish/Bearish Engulfing90–93% with GAF encoding60–83% profitable depending on hold periodVaries by timeframeCrypto, equitiesCNN-LSTM combo boosted profitable positions from 60% to 83% 
Flags & Pennants~73–80%67–71%+/–8–10%Trending marketsRequires multi-scale detection; noise sensitivity is higher 
Triangles (ascending/descending)~75%70–75%+/–9%Indices, forexLonger formation time helps CNN accuracy

Key insight: CNNs excel at patterns with clear geometric structure — symmetrical peaks, defined necklines, measurable breakout levels. They struggle more with diffuse patterns like wedges or channels where the “shape” is ambiguous.

Recent research from Jiang et al. (2023) demonstrated that CNN-based image factors constructed from OHLC bar charts can predict stock returns in ways distinct from known factors — suggesting CNNs detect visual patterns that purely quantitative models miss entirely.

Deep Dive: Head-and-Shoulders with CNN — Our 97% Accuracy Model

This was the centrepiece of the BU lecture. Here’s the architecture and what I’ve learned deploying it:

The Model

class HSCNN(nn.Module):
    def __init__(self, window=64):
        super().__init__()
        self.conv1 = nn.Conv1d(1, 16, kernel_size=7, padding=3)
        self.conv2 = nn.Conv1d(16, 32, kernel_size=5, padding=2)
        self.pool  = nn.MaxPool1d(2)
        flat = 32 * (window // 4)
        self.fc1 = nn.Linear(flat, 64)
        self.fc2 = nn.Linear(64, 1)

    def forward(self, x):
        x = self.pool(torch.relu(self.conv1(x)))
        x = self.pool(torch.relu(self.conv2(x)))
        x = x.view(x.size(0), -1)
        x = torch.relu(self.fc1(x))
        return torch.sigmoid(self.fc2(x))

25 lines of PyTorch. That’s it.

The Data Strategy

Real market data gives you maybe 50–100 clean head-and-shoulders per year across the S&P 500. That’s nowhere near enough to train a neural network. The solution: synthetic data generation — 100,000 patterns created from Gaussian bumps with controlled noise, plus 100,000 negative examples (random walks, trends, double tops, triangles).

The Results

  • 97% accuracy on synthetic test set
  • 76% agreement with human expert on real market data (200 hand-labeled patterns)
  • Backtest (2015–2025): 12.3% annual return, 1.8 Sharpe, –18% max drawdown vs. buy-and-hold’s 8.7% return, 0.9 Sharpe, –32% drawdown
  • +3.6% annual return2x better risk-adjusted returns44% smaller drawdowns

The Critical Design Choice

I don’t use the CNN as a standalone trading signal. I use it as a risk overlay:

wfinal=wbase×max(0,min(1,1phs))

If the CNN detects an 85% probability of a head-and-shoulders forming, the position gate drops to 0.15 — cutting exposure by 85%. We don’t ask the CNN “should I trade?” — we ask it “how loud should I play this position?”

Tips and Tricks from Production

These are the lessons that took me longer to learn than the model itself:

  • Use probability, not binary signals. A 0.73 probability is a different trade than a 0.91. Treat the CNN output as a continuous risk dial, not a yes/no switch.
  • Add persistence filtering. Require 3+ consecutive bars above your threshold before acting. Single-bar spikes are noise.
  • Normalization kills or saves you. Training used series / series[0]? Live inference must use the exact same normalization. This is the #1 production failure I see.
  • Track false positives religiously. Log every trigger with timestamp, symbol, probability, and outcome. If false positive rate exceeds 30%, retrain or adjust your threshold.
  • Retrain quarterly on a rolling 5-year window. Market dynamics drift — your model must follow.
  • Add 10–15 bps per trade in your backtest for slippage and transaction costs. Backtests assume perfect fills. Reality doesn’t.
  • Stick to liquid instruments. This works beautifully on EURUSD (tightest spreads). On exotic pairs or small-cap stocks, slippage eats your edge.
  • Combine with a regime filter. Only run the overlay in trending regimes — choppy sideways markets produce too many incomplete patterns.

What I Think Comes Next

By mid-2027, I expect CNN-based pattern detection to become a standard module in institutional risk management stacks — not as alpha generators, but as regime-aware risk overlays that automatically adjust exposure when reversal formations emerge. The patterns themselves aren’t new. The ability to detect them across thousands of instruments in real time, with calibrated probabilities, is.

The broader shift is even more important: the trader of 2027 doesn’t pick one strategy and pray. They maintain a composable library of AI tools — classical ML for selection, deep learning for pattern detection, LLMs for unstructured data, RL for hedging — and deploy the right combination for the current regime. That’s what the book teaches. That’s what I presented at BU today.

Alternative Perspectives

Contrarian view: Some researchers argue that purely image-based CNN models add little predictive value over raw time-series data, with accuracy plateauing around 70% for market direction prediction. The edge may come not from the CNN itself, but from how you use its output — as a risk filter rather than a return predictor.

Emerging angle: Vision Transformers are starting to outperform CNNs on candlestick pattern classification in recent Stanford research, achieving higher accuracy with less architecture tuning. The next edition of pattern detection may look very different from Conv1D layers.

FAQ

How is this different from traditional rule-based pattern detection?

Rule-based systems require dozens of hand-tuned thresholds that break across assets and regimes. A CNN learns the shape directly from data — shift-invariant, scale-invariant, and noise-tolerant. One model works across EURUSD, AAPL, and S&P 500 without recalibrating thresholds.

Can I use this for patterns other than head-and-shoulders?

Yes — the same CNN architecture generalises to double tops/bottoms, flags, triangles, and engulfing patterns. The key is generating enough synthetic training data for each pattern type and validating against real market examples.

Where can I get the book and code?

Hands-On AI Trading with Python, QuantConnect, and AWS on Amazon. Full source code for all 20+ strategies: github.com/QuantConnect/HandsOnAITradingBook.


Disclaimer: This reflects my personal views and experience, not financial advice. Past performance doesn’t guarantee future results.

Jiri Pik is the founder of RocketEdge, an AI fintech company based in Singapore. Follow him on LinkedIn and X for more.

keyboard_arrow_up
Index