This project proposes a visual-based trend prediction trading strategy using Japanese candlestick patterns and a convolutional neural network (CNN). The approach is inspired by the methodology of Mersal et al. (2024), with key adaptations to suit our dataset and simplified implementation.
π Overview of the Strategy
We use a sliding window approach to generate candlestick chart segments (5 candles per window). For each window:
Identify patterns using ta-lib
Use CNN to classify pattern as bullish or bearish
Based on the predicted trend, enter a trade on the next candle
π¦ Trade Walkthrough: A Single Trade
Step 1: Entry Signal
A 5-candle sliding window is fed into the trained CNN model.
CNN outputs: Uptrend (probability: 0.91)
Entry Condition:
Predicted trend = βUptrendβ
The last candle in the window closes above the 20-period Simple Moving Average (SMA20)
β Enter a Long Position (Buy) at the opening of the next candle
Step 2: Exit Signal
Exit after 3 candles (fixed holding period), OR:
If CNN prediction flips to Downtrend in an overlapping future window
Step 3: Stop Loss / Risk Rule
Place a stop loss at 1.5 Γ ATR(14) below the entry price
No more than 2% of portfolio risked per trade
βοΈ Additional Rules
Only one active trade at a time
No trades during low-volume periods (overnight hours or holidays)
π Backtest Setup
Data: EUR/USD 15-min OHLC from 2020β2024
Technical Indicators: SMA, ATR
Pattern Recognition: ta-lib 61-patterns
Model: 3-layer CNN with image input of size 150Γ150
π Data Sample
Here is a preview of the candlestick-based dataset used for training the model.