This repository contains a machine learning model for predicting chart patterns in cryptocurrency price data. The model uses a hybrid CNN-LSTM architecture to analyze both technical indicators and candlestick images.
The codebase has been modified to separate the data preparation and model training steps, which provides several benefits:
- Faster Iterations: No need to re-fetch and re-process 8 years of data every time you want to train the model
- Consistent Training: Using the same prepared data ensures consistent model training results
- Reduced API Usage: Fewer calls to exchange APIs, reducing the risk of rate limiting
- Incremental Updates: Ability to update the model with new data without retraining from scratch
- Automatic Daily Training: The model can now be scheduled to automatically train daily with new data
- Multiple Cryptocurrency Pairs: Support for preparing data for multiple trading pairs at once
- Enhanced Scheduling: Configurable training time and immediate or scheduled training options
chart_pattern_prediction_model.py: The core model implementationtrain_8years.py: Script to prepare and save 8 years of historical datapredict_realtime.py: Script to train the model and make real-time predictionsrun_chart_pattern_model.py: New script that combines all steps in a single command
The simplest way to use this model is with the new run_chart_pattern_model.py script:
# Basic usage (uses default settings: BTCUSDT, 1d timeframe, 8 years of data)
python run_chart_pattern_model.py
# Specify a different trading pair
python run_chart_pattern_model.py --symbol ETHUSDT
# Specify a different timeframe
python run_chart_pattern_model.py --timeframe 4h
# Use fewer years of data
python run_chart_pattern_model.py --years 4
# Force data preparation even if data exists
python run_chart_pattern_model.py --force-prepare
# Force model retraining even if model exists
python run_chart_pattern_model.py --force-retrain
# Skip training and only run predictions
python run_chart_pattern_model.py --predict-only
# Prepare data for multiple cryptocurrency pairs
python run_chart_pattern_model.py --symbols BTCUSDT,ETHUSDT,BNBUSDT,ADAUSDT,SOLUSDT
# Schedule automatic daily training
python run_chart_pattern_model.py --schedule-daily
# Schedule automatic daily training at a specific time (24-hour format)
python run_chart_pattern_model.py --schedule-daily --training-time 04:30If you prefer to run each step separately:
-
Prepare Data:
# Prepare data for a single trading pair python train_8years.py --symbol BTCUSDT --timeframe 1d --years 8 # Prepare data for multiple trading pairs python train_8years.py --symbols BTCUSDT,ETHUSDT,BNBUSDT --timeframe 1d --years 8
-
Train Model:
python predict_realtime.py
-
Make Predictions:
python predict_realtime.py --predict-only
-
Schedule Daily Training:
# In Python code: from chart_pattern_prediction_model import ChartPatternPredictor # Initialize the predictor predictor = ChartPatternPredictor(symbol="BTC/USDT", timeframe="1d") # Load an existing model predictor.load_model() # Schedule daily training at midnight predictor.schedule_daily_training(training_time="00:00") # Keep the script running import time while True: time.sleep(60)
- Prepared data is stored in directories named
chart_pattern_data_{SYMBOL}_{YEARS}years - Trained models are stored in directories named
chart_pattern_model_{SYMBOL}_{YEARS}years - Prediction results and visualizations are stored in the
prediction_resultsdirectory - Training logs are stored in the
training_logsdirectory within each model directory
The automatic daily training feature allows the model to stay up-to-date with the latest market data. When enabled:
- The model checks for new data at the scheduled time each day
- If sufficient new data is available, it incrementally trains the model
- Training logs are saved to track the model's performance over time
For production use, consider setting up a system service or cron job to ensure the scheduler runs continuously.
- Python 3.7+
- TensorFlow 2.x
- pandas
- numpy
- matplotlib
- mplfinance
- scikit-learn
- Binance API client
- schedule (for automatic daily training)
- If you encounter errors related to missing data, run with the
--force-prepareflag - If you encounter errors related to model loading, run with the
--force-retrainflag - For API rate limit issues, reduce the frequency of predictions or use a different API key
- If automatic daily training is not working, check that the script is running continuously and that the
schedulepackage is installed
This project is licensed under the MIT License - see the LICENSE file for details.