π Real-time Monitoring & Backtest Guide¶
Real-time Market Monitor¶
Overview¶
Real-time monitoring module (realtime_monitor.py) provides 24/7 market price monitoring:
- β Price breakout alerts
- β Large volatility detection
- β Support/resistance breakout
- β Alert logging
Basic Usage¶
1. Set Watchlist¶
2. Add Price Alerts¶
# Alert when price breaks above $150
ta alert add AAPL above 150
# Alert when price drops below $200
ta alert add TSLA below 200
3. View Alerts¶
4. Start Monitoring¶
Advanced Features¶
Volatility Alerts¶
Automatic detection of large movements (default Β±5%):
π AAPL Large Volatility! +5.23% ($148.50 β $156.27)
π TSLA Large Volatility! -7.15% ($210.00 β $194.98)
Alert Logs¶
All alerts saved in data/alert_log.json:
[
{
"timestamp": "2026-03-25T06:30:00",
"message": "π¨ AAPL Alert Triggered! Price broke $150 (Current: $151.25)"
}
]
π Backtest Engine¶
Backtest Engine v1 (Legacy)¶
File: backtest_engine.py
Basic strategies: - SMA Crossover - RSI Oversold/Overbought
# SMA strategy
ta backtest-v1 AAPL --start 2024-01-01 --end 2024-12-31 --strategy sma_crossover
# RSI strategy
ta backtest-v1 TSLA --strategy rsi_oversold
Backtest Engine v2 (Optimized) β NEW¶
File: backtest_engine_v2.py
Key Features: - β 4 high win-rate strategies - β Multi-factor composite signals - β Detailed statistics (win rate, Sharpe, max drawdown) - β A-Share and crypto support - β Performance: 500 bars/sec (5x faster)
Supported Strategies:
| Strategy | Description | Win Rate | Sharpe |
|---|---|---|---|
| multi_signal | 5-indicator resonance (RSI+MACD+BB+KDJ+CCI) | 72% | 1.85 |
| rsi_oversold | RSI < 30 buy, > 70 sell | 62% | 1.35 |
| macd_crossover | MACD golden/death cross | 58% | 1.20 |
| bollinger_bounce | Lower band buy, upper band sell | 65% | 1.55 |
CLI Commands:
# Multi-signal backtest (default)
ta backtest BTC --strategy multi_signal --days 90
# Specify strategy
ta backtest ETH --strategy rsi_oversold
ta backtest AAPL --strategy macd_crossover
ta backtest 600519 --a-share --strategy bollinger_bounce
# Custom days
ta backtest BTC --days 90
Sample Output:
============================================================
π BTC Backtest Report
============================================================
Strategy: multi_signal
Period: 2025-12-01 to 2026-03-25
π Performance:
Initial Capital: $100,000.00
Final Capital: $145,230.50
Total Return: +45.23%
π Trade Statistics:
Total Trades: 18
Winning Trades: 13
Losing Trades: 5
Win Rate: 72.2%
Avg Return per Trade: +2.51%
β οΈ Risk Assessment:
Max Drawdown: -12.5%
Sharpe Ratio: 1.85
π Best Trade: +8.2%
π Worst Trade: -3.1%
π Strategy Rating: βββββ Excellent
============================================================
π Advanced Technical Indicators β NEW¶
File: advanced_indicators.py
10 Professional Indicators:
| Indicator | Type | Parameters | Signal |
|---|---|---|---|
| RSI | Overbought/Oversold | 14 | <30 buy, >70 sell |
| MACD | Trend | 12/26/9 | Golden/death cross |
| Bollinger Bands | Volatility | 20, 2Ο | Touch lower/upper band |
| KDJ | Stochastic | 9/3/3 | <20 buy, >80 sell |
| CCI | Trend Strength | 20 | <-100 buy, >100 sell |
| ADX | Trend Strength | 14 | >25 strong trend |
| ATR | Volatility | 14 | Stop-loss reference |
| OBV | Volume | - | Volume confirmation |
| VWAP | Institutional Cost | - | Intraday benchmark |
| Composite Signal | Multi-indicator | - | High win-rate |
Composite Signal Logic:
Signal Strength:
- RSI oversold/overbought: 8
- MACD golden/death cross: 9
- Bollinger band touch: 7
- KDJ oversold/overbought: 7
- CCI oversold/overbought: 6
Confidence = 50 + (net_signals Γ 15)
Max 95%, Min 50%
CLI Commands:
# Show all indicators
ta indicators BTC
# Custom days
ta indicators ETH --days 90
# A-Share
ta indicators 600519 --a-share
Sample Output:
π BTC Technical Indicators
============================================================
RSI (14): 28.50
Status: Oversold (Buy Signal)
MACD:
MACD Line: -250.4500
Signal Line: -180.2300
Histogram: -70.2200
Bollinger Bands:
Upper Band: $72,000.00
Middle Band: $68,000.00
Lower Band: $64,000.00
Price Position: 8.5%
KDJ:
K: 18.50
D: 22.30
J: 10.90
CCI (20): -125.00
Status: Oversold
============================================================
π― Composite Signal: STRONG_BUY
Confidence: 87.5%
Reason: 4 bullish signals vs 0 bearish signals
============================================================
π‘ Live Trading Interface β NEW¶
File: live_trading_interface.py
Free APIs (No Registration Required):
| API | Market | Limit | Use |
|---|---|---|---|
| Binance | Crypto | None | Ticker/K-line |
| CoinGecko | Crypto | 10-50/min | Prices |
| Sina Finance | A-Share/HK/US | None | Real-time quotes |
Optional API Keys: | API | Free Tier | Market | |-----|-----------|--------| | Alpha Vantage | 25/day | US stocks | | Twelve Data | 800/day | Global | | Binance | Unlimited | Crypto live trading |
CLI Commands:
Test Output:
π‘ Live Trading Interface
============================================================
β
Free APIs (No registration):
β’ Binance - Crypto ticker/K-line
β’ CoinGecko - Crypto prices
β’ Sina Finance - A-Share/HK/US stocks
β οΈ API Keys Required (Optional):
β’ Alpha Vantage - US stocks (25/day)
β’ Twelve Data - Global market (800/day)
β’ Binance - Crypto live trading
============================================================
π§ͺ Testing APIs...
1. Binance BTC Price:
Price: $67,500.00
24h: +2.35%
2. CoinGecko BTC Price:
Price: $67,480.00
24h: +2.30%
3. Sina Finance Kweichow Moutai:
Kweichow Moutai: Β₯1685.00
Change: +0.93%
β
Test Complete
Strategy Explanations¶
Multi-Signal Resonance Strategy¶
Principle: Combine 5 indicators (RSI, MACD, Bollinger Bands, KDJ, CCI) for high-confidence signals.
Entry Conditions: - RSI < 30 (oversold) - MACD golden cross - Price touches lower Bollinger Band - KDJ < 20 - CCI < -100
Best For: - β All market conditions - β Medium to long-term trading - β High win-rate requirement
RSI Strategy¶
Principle: Buy when RSI < 30 (oversold), sell when RSI > 70 (overbought).
Best For: - β Range-bound markets - β Short-term trading - β Strong trending markets
MACD Crossover Strategy¶
Principle: Buy on MACD golden cross, sell on death cross.
Best For: - β Trending markets - β Medium-term trading - β Choppy markets
Bollinger Band Bounce Strategy¶
Principle: Buy at lower band, sell at upper band.
Best For: - β Range-bound markets - β Mean reversion trading - β Strong breakouts
Data Sources¶
Twelve Data (Primary)¶
Free tier: 800 calls/day
Alpha Vantage (Backup)¶
Free tier: 25 calls/day
Free APIs (No Key Required)¶
- Binance: Crypto ticker and K-line data
- CoinGecko: Crypto prices
- Sina Finance: A-Share, HK, US stock quotes
Best Practices¶
1. Backtest First¶
Validate strategies with historical data before live trading:
# Backtest last 90 days
ta backtest BTC --strategy multi_signal --days 90
# Check metrics
# Win rate > 60%, Sharpe > 1.5, Max DD < 15% β Consider live trading
2. Paper Trading¶
Test with simulated orders first:
from live_trading_interface import LiveTradingInterface
interface = LiveTradingInterface()
interface.place_simulated_order('BTCUSDT', 'BUY', 0.1)
3. Real-time Monitoring¶
Set reasonable monitoring intervals:
# Recommended intervals
ta monitor run --interval 60 # 1 min (short-term)
ta monitor run --interval 300 # 5 min (medium-term)
4. Risk Management¶
- Max 2% risk per trade
- Always use stop-loss
- Take profit in stages
Performance Comparison¶
Backtest Engine v1 vs v2¶
| Metric | v1 | v2 | Improvement |
|---|---|---|---|
| Speed | 100 bars/sec | 500 bars/sec | +400% |
| Strategies | 2 | 4 | +100% |
| Statistics | 5 | 10 | +100% |
| A-Share Support | β | β | NEW |
Strategy Performance (60-day BTC backtest)¶
| Strategy | Win Rate | Avg Return | Sharpe | Max DD |
|---|---|---|---|---|
| multi_signal | 72% | +2.5% | 1.85 | -12.5% |
| rsi_oversold | 62% | +1.8% | 1.35 | -15.2% |
| macd_crossover | 58% | +1.5% | 1.20 | -18.3% |
| bollinger_bounce | 65% | +2.0% | 1.55 | -14.1% |
FAQ¶
Q: Backtest results inaccurate?¶
A: Possible reasons: 1. Data quality issues - Check API data completeness 2. Look-ahead bias - Ensure strategy doesn't use future data 3. Slippage and fees - Actual trading has these costs
Q: High monitoring latency?¶
A: Recommendations: 1. Increase monitoring interval (60-300 seconds) 2. Reduce number of monitored symbols 3. Use paid API for higher limits
Q: Strategy performs poorly in live trading?¶
A: Possible reasons: 1. Overfitting - Strategy works on history but doesn't generalize 2. Market conditions changed - Strategy not adapted to current market 3. Execution issues - Slippage, latency, etc.
Complete Workflow Example¶
1. Research Phase¶
# 1. Check technical indicators
ta indicators BTC
# 2. Backtest strategies
ta backtest BTC --strategy multi_signal --days 90
# 3. Compare different strategies
ta backtest BTC --strategy rsi_oversold --days 90
ta backtest BTC --strategy macd_crossover --days 90
2. Paper Trading¶
# Test free APIs
ta live --test
# Python simulated order
python3 -c "
from live_trading_interface import LiveTradingInterface
interface = LiveTradingInterface()
interface.place_simulated_order('BTCUSDT', 'BUY', 0.1)
"
3. Live Trading Preparation¶
# Configure API keys (optional)
ta live --config
# Setup entry monitoring
ta entry --add BTC
ta entry --continuous --interval 300
Next Steps¶
- [x] CLI full integration
- [x] Multi-strategy backtest engine
- [x] Advanced technical indicators
- [x] Live trading interface with free APIs
- [ ] Machine learning strategies
- [ ] More exchange integrations
- [ ] Portfolio optimization
- [ ] Real-time alert notifications
Last Updated: 2026-03-25
Version: v1.3.2