Based on CNN,employed SMC and ATR for TP/SL,this bot is dedicated for high frequent trading.It implements a hybrid strategy, using a CatBoost machine learning model to predict future price direction, which then gates entry signals generated by a set of Smart Money Concepts (SMC) indicators and structure analysis.
The logic of risk management of this bot is similiar with CatBoost Crypto trader(one of my projects). What is different is that CatBoost has been switch as CNN.
- Hybrid Strategy: Combines the predictive power of a CNN classificatioN model with the structural and order flow insights from Smart Money Concepts (SMC) (Swings, Order Blocks, FVGs).
- Real-time Data: Fetches real-time OHLCV data using the robust
ccxtlibrary, supporting major exchanges like Binance. - Comprehensive Indicators: Calculates essential technical indicators including RSI, ADX, ATR, VWAP, and Taker Ratio, with Z-Score normalization for ML feature stability.
- Robust Risk Management: Features an ATR-based stop-loss (ART Stop), automatic breakeven move, and trailing stop based on volatility and profit.
- Persistence & Logging: Uses SQLite for trade and state logging (
TradeDB) and Python's standardloggingfor runtime transparency. - Configurable: Easy configuration via a
paper_trade_config.jsonfile for symbol, timeframe, indicators, and risk parameters. - Modes: Supports
SIMULATEmode for backtesting/paper trading and aTESTNETmode for live-testing with zero financial risk.
- Python 3.8+
- Required Libraries:
pip install ccxt pandas numpy catboost
- Clone the repository:
git clone https://github.com/AlexanderWilliams1 cd CNNCryptoTrader - The script will automatically create a default configuration file,
paper_trade_config.json, on the first run.
The bot uses paper_trade_config.json for all settings.
Key Parameters to Adjust:
| Parameter | Default | Description |
|---|---|---|
"exchange" |
"binance" |
The target CCXT exchange ID. |
"symbol" |
"BTC/USDT" |
The trading pair. |
"timeframe" |
"1h" |
OHLCV data interval (e.g., '1h', '4h', '1d'). |
"mode" |
"SIMULATE" |
Set to SIMULATE for paper trading or TESTNET for test environment (requires API keys). |
"atr_mult_stop" |
2.0 |
ATR multiplier for initial stop-loss calculation. |
"breakeven_at_pct" |
0.05 |
Move stop to entry price when position is X% in profit. |
"min_return_threshold" |
0.0001 |
Minimum predicted return to activate SMC-based entry checks. |
"lookback" |
100 |
Lookback window for training the CNN model. |
Run the main script:
python trader.pyThe bot will continuously fetch data, retrain its model periodically, compute SMC signals, and execute simulated trades based on the combined strategy. Trade history is saved to an SQLite database.
The core strategy operates in a three-stage pipeline:
- Data & Indicators: Fetch OHLCV, calculate technical indicators (RSI, ADX, ATR, VWAP, Taker Ratio) and apply Z-Score normalization.
- Deep Learning Gating:
- A CNN Classifier/Regressor model is trained (and periodically retrained) on historical data, using the normalized indicators as features.
- It predicts the probability of a significant price move (class 1) or the future relative return (regression).
- This prediction must exceed the
min_return_thresholdto enable a trade entry.
- SMC Execution:
- If the ML prediction is favorable, the bot looks for Smart Money Concepts signals:
- Order Blocks: Checks if the current price is interacting with a recent Order Block.
- Market Structure: Verifies the current trend bias (HH/HL or LH/LL) against the predicted direction.
- An entry is executed only if both the ML prediction and an SMC condition are met.
- If the ML prediction is favorable, the bot looks for Smart Money Concepts signals:
- Risk Management: After entry, the position is protected by an ART Stop (ATR-based with swing structure). The stop-loss is managed dynamically:
- It moves to breakeven once a profit target (
breakeven_at_pct) is hit. - It utilizes an ATR-based trailing stop to lock in further profits.
- It moves to breakeven once a profit target (
| Component | Purpose |
|---|---|
SMCTrader class |
The main trading engine, responsible for the trading loop and state management. |
ccxt helpers |
Handles connection, data fetching, and sandbox mode for the exchange. |
compute_prediction_series |
Calculates all technical indicators and runs the CatBoost inference. |
detect_swings, compute_structure |
Detects swing highs/lows and derives market structure bias (SMC). |
detect_order_blocks, detect_fvg |
Detects key SMC zones for potential entry/reaction. |
TradeDB |
SQLite wrapper for persistent storage of trades and bot state. |
Please pay attention that the thershold and parameters may not be the best ones for your trading pairs. You can optimize them via GA. WARENING: DO YOUR OWN RESERCH ON THIS BOT BEFORE YOU EMPLOYED IT. 24
Please pay attention that the thershold and parameters may not be the best ones for your trading pairs. You can optimize them via GA. WARENING: DO YOUR OWN RESERCH ON THIS BOT BEFORE YOU EMPLOYED IT. 24