This is a complete Reinforcement Learning AI that learns to trade Ethereum (ETH/USD) automatically. The bot:
- Learns from historical price data
- Decides when to buy, sell, or hold
- Manages stop losses and take profits
- Gets smarter through trial and error (600,000+ practice trades!)
Perfect for beginners learning AI and algorithmic trading!
ETHUSD_Candlestick_1_Hour_2020_2023.csv- Training data (3 years)ETHUSD_Candlestick_1_Hour_2023_2025.csv- Testing data (2 years)generate_eth_data.py- Script that created the synthetic data
indicators.py- Calculates technical indicators (RSI, Moving Averages, etc.)trading_env_eth.py- The trading simulator (the "game" the AI plays)train_agent_eth.py- Trains the AI bottest_agent_eth.py- Tests the trained bot and generates reports
model_ethereum_best.zip- Your trained AI modelethereum_trade_history.csv- Detailed log of every tradeethereum_training_results.png- Performance chartsethereum_test_results.png- Test results chartscheckpoints_eth/- Saved models during training
pip install stable-baselines3 pandas numpy matplotlib gymnasiumOr if you're on Linux/Mac:
pip install stable-baselines3 pandas numpy matplotlib gymnasium --break-system-packagespython train_agent_eth.pyThis takes 2-6 hours! ⏰ Go watch a movie, the AI is learning!
You'll see output like:
Training for 600,000 timesteps...
---------------------------------
| rollout/ | |
| ep_len_mean | 1500 |
| ep_rew_mean | 125.3 |
...
python test_agent_eth.pyThis runs in minutes and creates:
ethereum_trade_history.csv- All trades with detailsethereum_test_results.png- Beautiful charts
That's it! 🎉
✅ Test equity curve going UP
✅ Win rate around 40-60%
✅ Profit factor > 1.0
✅ Max drawdown < 30%
✅ Makes 10-50 trades (not too many, not too few)
❌ Test equity curve going DOWN
❌ Win rate < 30% or > 80% (suspicious)
❌ Profit factor < 1.0
❌ Max drawdown > 50%
❌ Too many trades (>100) = overtrading
❌ Too few trades (<5) = not learning
TRADE ANALYSIS
======================================================================
Total trades: 23
Win/Loss breakdown:
Winning trades: 14 (60.9%)
Losing trades: 9 (39.1%)
Winning trades:
Average win: $43.25
Largest win: $127.50
Losing trades:
Average loss: $-28.33
Largest loss: $-51.20
Total P&L: +$350.17
Profit factor: 2.11 (>1 is profitable)
Average time in trade: 18.5 hours (0.8 days)
- Historical Data → You feed the AI 3 years of Ethereum prices
- Learning Phase → AI tries random trades, gets rewards/penalties
- Smart Phase → After 600k tries, AI learns what works
- Testing → Run on unseen data to see if it really learned
Every hour, the AI looks at:
- RSI (is momentum too high/low?)
- Moving averages (what's the trend?)
- Price changes (is it moving fast?)
- Volume (is there strong interest?)
- Its current position (am I in a trade?)
- HOLD - Do nothing this hour
- CLOSE - Close my current trade
- OPEN LONG - Buy ETH (bet price goes up)
- OPEN SHORT - Sell ETH (bet price goes down)
- Choose stop loss: $20, $50, $100, or $150
- Choose take profit: $30, $75, $150, or $225
- ✅ Make profitable trade → Get positive reward → Do more of that
- ❌ Lose money → Get negative reward → Do less of that
- After 600,000 tries, it figures out patterns!
Edit train_agent_eth.py:
# Stop Loss options (dollars)
SL_OPTS = [20, 50, 100, 150] # ← Change these!
# Take Profit options (dollars)
TP_OPTS = [30, 75, 150, 225] # ← Change these!
# Position size (ETH per trade)
position_size_eth=0.1, # ← 0.1 ETH = ~$300 at $3000/ETH
# Trading costs
spread_pct=0.1, # ← 0.1% = typical exchange fee
commission_dollars=0.5, # ← Flat fee per trade
# Training duration
total_timesteps = 600_000 # ← More = better but slowerEdit indicators.py:
# Add your own indicators!
df["my_indicator"] = ... # Calculate something
# Add to feature list
feature_cols = [
"rsi_14",
"ma_20_slope",
# ... other features ...
"my_indicator", # ← Add yours here!
]Replace generate_eth_data.py with real data from:
- Binance API
- CoinGecko API
- Yahoo Finance
- Or any CSV with columns:
Gmt time, Open, High, Low, Close, Volume
Solution: Install requirements
pip install stable-baselines3Solution: Your CSV has wrong column names. Make sure it has:
- Gmt time
- Open
- High
- Low
- Close
- Volume
Solution: You need to train first!
python train_agent_eth.py # This creates the model
python test_agent_eth.py # Now you can testSolution: Reduce total_timesteps in train_agent_eth.py:
total_timesteps = 100_000 # Instead of 600_000Less training = faster but potentially worse results.
Solution: This is normal! Trading is hard. Try:
- Train longer (increase timesteps)
- Adjust SL/TP options
- Add more indicators
- Change reward parameters
- Use more training data
Remember: Even professional traders have losing strategies!
Install TensorBoard:
pip install tensorboardWhile training is running, open another terminal:
tensorboard --logdir=./tensorboard_log_eth/Open browser to: http://localhost:6006
You'll see live graphs of:
- Reward per episode
- Episode length
- Policy loss
- Value function loss
If training crashes, resume from last checkpoint:
# In train_agent_eth.py, replace:
model = PPO(policy="MlpPolicy", env=train_vec_env, ...)
# With:
model = PPO.load("checkpoints_eth/ppo_ethereum_500000_steps", env=train_vec_env)
model.learn(total_timesteps=100_000) # Train for 100k moreWant to test a specific checkpoint instead of the best model?
# In test_agent_eth.py:
model = PPO.load("checkpoints_eth/ppo_ethereum_300000_steps", env=vec_test_env)ethereum-trading-bot/
│
├── Data/
│ ├── ETHUSD_Candlestick_1_Hour_2020_2023.csv
│ └── ETHUSD_Candlestick_1_Hour_2023_2025.csv
│
├── Core Code/
│ ├── indicators.py # Feature engineering
│ ├── trading_env_eth.py # Trading simulator
│ ├── train_agent_eth.py # Training script
│ └── test_agent_eth.py # Testing script
│
├── Generated (after training)/
│ ├── model_ethereum_best.zip # Best model
│ ├── ethereum_trade_history.csv # Trade log
│ ├── ethereum_training_results.png
│ ├── ethereum_test_results.png
│ └── checkpoints_eth/ # Saved models
│ ├── ppo_ethereum_50000_steps.zip
│ ├── ppo_ethereum_100000_steps.zip
│ └── ...
│
└── README.md # This file!
A: No. This is a learning project using synthetic data. Real trading involves:
- Market slippage
- Liquidity issues
- News events
- Changing market conditions
- Psychological factors
A: NOT RECOMMENDED. This is for educational purposes only. If you must:
- Test extensively on real historical data
- Paper trade for months
- Start with tiny positions
- Never risk more than you can afford to lose
A: RL can discover complex patterns humans might miss. But it's also:
- Harder to interpret ("black box")
- Requires lots of data
- Can overfit to training data
- May fail in unexpected ways
A: 40-60% is excellent if average win > average loss. Even 30% win rate can be profitable with good risk management!
A: Main differences:
- Crypto is more volatile → Bigger moves, bigger rewards/losses
- Different spreads → Percentage-based not pip-based
- 24/7 trading → No market close (though this data is hourly)
- Higher fees → Exchanges charge more than Forex brokers
A: Yes! Just:
- Get price data for BTC, ADA, SOL, etc.
- Adjust
position_size_ethfor that crypto - Adjust SL/TP values for its volatility
- Retrain from scratch
A: Proximal Policy Optimization - a reinforcement learning algorithm that:
- Is relatively stable
- Works well for continuous control
- Doesn't require huge datasets
- Popular for trading applications
This project is for educational purposes. Use at your own risk!
- Stable Baselines3 team for the amazing RL library
- OpenAI Gym/Gymnasium for the environment framework
- The crypto and RL communities for inspiration
- ✅ Run the basic training
- ✅ Analyze the results
- 📊 Try different parameters
- 🧪 Add more indicators
- 📚 Study winning vs losing trades
- 🔄 Iterate and improve!
Good luck and happy learning! 🚀
Remember: The goal is to LEARN about AI and trading, not to get rich quick!