381 lines
11 KiB
Markdown
381 lines
11 KiB
Markdown
|
# 🎯 Pure Smart Money Concepts (SMC) Trading System
|
||
|
|
||
|
## 📋 System Overview
|
||
|
|
||
|
Sistem trading berdasarkan konsep **Smart Money Concepts (SMC)** murni tanpa menggunakan indikator teknikal tradisional. Sistem ini fokus pada:
|
||
|
|
||
|
- **Market Structure Analysis** - Analisis struktur pasar (BOS, CHoCH)
|
||
|
- **Liquidity Analysis** - Deteksi zona likuiditas (BSL/SSL, Equal Highs/Lows)
|
||
|
- **Order Block Detection** - Identifikasi blok order institusional
|
||
|
- **Fair Value Gaps (FVG)** - Deteksi gap nilai yang belum terisi
|
||
|
- **Premium/Discount Zones** - Zona premium dan discount berdasarkan range
|
||
|
|
||
|
## 🔧 File Structure
|
||
|
|
||
|
```
|
||
|
ai_forex_adaptif_rev1/
|
||
|
├── technical_indicators_smc.py # Core SMC analysis functions
|
||
|
├── analyze_market_smc.py # Enhanced market analysis with profiles
|
||
|
├── test_smc_analysis.py # Testing script dengan data real (yfinance)
|
||
|
├── simple_test_smc.py # Testing script dengan data dummy
|
||
|
└── SMC_SYSTEM_README.md # Documentation ini
|
||
|
```
|
||
|
|
||
|
## 🚀 Quick Start
|
||
|
|
||
|
### 1. Install Dependencies
|
||
|
```bash
|
||
|
pip install pandas numpy scipy yfinance matplotlib
|
||
|
```
|
||
|
|
||
|
### 2. Basic Usage
|
||
|
|
||
|
#### Analisis dengan Data Real
|
||
|
```python
|
||
|
from analyze_market_smc import get_market_context_smc, fetch_data
|
||
|
|
||
|
# Fetch data
|
||
|
df = fetch_data('BTC-USD', period='3mo', interval='1h')
|
||
|
|
||
|
# Analisis SMC untuk swing trading
|
||
|
context = get_market_context_smc(df, profile='swing', symbol='BTCUSD')
|
||
|
|
||
|
print(f"Market Bias: {context['market_bias']}")
|
||
|
print(f"Current Zone: {context['smc_analysis']['premium_discount_zones']['current_zone']}")
|
||
|
print(f"Entry Direction: {context['entry_exit_analysis']['direction']}")
|
||
|
```
|
||
|
|
||
|
#### Testing dengan Data Dummy
|
||
|
```python
|
||
|
python simple_test_smc.py
|
||
|
```
|
||
|
|
||
|
## 📊 Core SMC Components
|
||
|
|
||
|
### 1. Market Structure Analysis
|
||
|
```python
|
||
|
from technical_indicators_smc import analyze_market_structure
|
||
|
|
||
|
structure = analyze_market_structure(df, swing_length=5)
|
||
|
print(f"Trend: {structure['trend_direction']}")
|
||
|
print(f"BOS Detected: {structure['bos_detected']}")
|
||
|
```
|
||
|
|
||
|
**Output Elements:**
|
||
|
- `structure_type`: BOS_BULLISH, BOS_BEARISH, atau RANGE
|
||
|
- `trend_direction`: BULLISH, BEARISH, atau NEUTRAL
|
||
|
- `bos_detected`: True jika Break of Structure terdeteksi
|
||
|
- `structure_strength`: Kekuatan struktur (0.0-1.0)
|
||
|
|
||
|
### 2. Liquidity Zone Detection
|
||
|
```python
|
||
|
from technical_indicators_smc import detect_liquidity_zones
|
||
|
|
||
|
liquidity_zones = detect_liquidity_zones(df, lookback=20)
|
||
|
```
|
||
|
|
||
|
**Types:**
|
||
|
- **BSL (Buy Side Liquidity)**: Di atas swing highs
|
||
|
- **SSL (Sell Side Liquidity)**: Di bawah swing lows
|
||
|
- **EQH (Equal Highs)**: Level sama pada swing highs
|
||
|
- **EQL (Equal Lows)**: Level sama pada swing lows
|
||
|
|
||
|
### 3. Order Block Detection
|
||
|
```python
|
||
|
from technical_indicators_smc import detect_order_blocks
|
||
|
|
||
|
order_blocks = detect_order_blocks(df, lookback=50)
|
||
|
```
|
||
|
|
||
|
**Types:**
|
||
|
- **BULLISH_OB**: Candle bearish diikuti breakout bullish
|
||
|
- **BEARISH_OB**: Candle bullish diikuti breakout bearish
|
||
|
- **Status**: ACTIVE, TESTED, MITIGATED
|
||
|
|
||
|
### 4. Fair Value Gap (FVG)
|
||
|
```python
|
||
|
from technical_indicators_smc import detect_fair_value_gaps
|
||
|
|
||
|
fvgs = detect_fair_value_gaps(df, min_gap_atr=0.1)
|
||
|
```
|
||
|
|
||
|
**Types:**
|
||
|
- **BULLISH_FVG**: Gap bullish yang perlu diisi
|
||
|
- **BEARISH_FVG**: Gap bearish yang perlu diisi
|
||
|
- **Status**: ACTIVE, FILLED
|
||
|
|
||
|
### 5. Premium/Discount Zones
|
||
|
```python
|
||
|
from technical_indicators_smc import calculate_premium_discount_zones
|
||
|
|
||
|
zones = calculate_premium_discount_zones(df, lookback=100)
|
||
|
print(f"Current Zone: {zones['current_zone']}")
|
||
|
```
|
||
|
|
||
|
**Zones:**
|
||
|
- **PREMIUM**: Top 20% dari range (sell zone)
|
||
|
- **DISCOUNT**: Bottom 20% dari range (buy zone)
|
||
|
- **EQUILIBRIUM**: Middle 60% (wait zone)
|
||
|
|
||
|
## 👤 Trading Profiles
|
||
|
|
||
|
Sistem mendukung 4 profil trading yang berbeda:
|
||
|
|
||
|
### 1. Scalper Profile
|
||
|
- **Timeframe**: M1-M5
|
||
|
- **Focus**: FVG retests, quick order block reactions
|
||
|
- **Risk**: Medium
|
||
|
- **Speed**: Sangat cepat
|
||
|
|
||
|
### 2. Intraday Profile
|
||
|
- **Timeframe**: M15-H1
|
||
|
- **Focus**: Liquidity sweeps, session analysis
|
||
|
- **Risk**: Medium
|
||
|
- **Session awareness**: Ya
|
||
|
|
||
|
### 3. Swing Profile
|
||
|
- **Timeframe**: H1-H4
|
||
|
- **Focus**: Structure breaks, CHoCH, high-quality setups
|
||
|
- **Risk**: Low
|
||
|
- **Hold time**: Beberapa hari
|
||
|
|
||
|
### 4. Position Profile
|
||
|
- **Timeframe**: H4-D1
|
||
|
- **Focus**: Major structure shifts, institutional blocks
|
||
|
- **Risk**: Very Low
|
||
|
- **Hold time**: Minggu/bulan
|
||
|
|
||
|
## 🔍 Analysis Results
|
||
|
|
||
|
### Market Context Output
|
||
|
```python
|
||
|
context = get_market_context_smc(df, profile='swing', symbol='XAUUSD')
|
||
|
```
|
||
|
|
||
|
**Key Fields:**
|
||
|
- `market_bias`: STRONG_BULLISH, BULLISH, NEUTRAL, BEARISH, STRONG_BEARISH
|
||
|
- `bias_strength`: Numerik (0-10+)
|
||
|
- `current_price`: Harga saat ini
|
||
|
- `atr`: Average True Range
|
||
|
- `risk_assessment`: LOW, MEDIUM, HIGH
|
||
|
|
||
|
### Entry/Exit Analysis
|
||
|
```python
|
||
|
entry_exit = context['entry_exit_analysis']
|
||
|
```
|
||
|
|
||
|
**Output:**
|
||
|
- `direction`: BUY, SELL, atau WAIT
|
||
|
- `entry_zones`: List zona entry terbaik
|
||
|
- `confidence`: Score kepercayaan per zona
|
||
|
|
||
|
### Profile-Specific Analysis
|
||
|
```python
|
||
|
profile_analysis = context['profile_analysis']
|
||
|
```
|
||
|
|
||
|
**Output:**
|
||
|
- `market_phase`: accumulation, markup, distribution, markdown, transition
|
||
|
- `confidence`: Persentase confidence
|
||
|
- `entry_signals`: List sinyal entry spesifik profil
|
||
|
- `warnings`: Peringatan untuk profil tersebut
|
||
|
|
||
|
## ⚙️ Configuration
|
||
|
|
||
|
### Symbol-Specific Settings
|
||
|
```python
|
||
|
SMC_CONFIGS = {
|
||
|
"XAUUSD": {
|
||
|
"swing_length": 7,
|
||
|
"liquidity_lookback": 30,
|
||
|
"order_block_lookback": 100,
|
||
|
"min_gap_atr": 0.15,
|
||
|
"eq_tolerance_pips": 10.0
|
||
|
},
|
||
|
"BTCUSD": {
|
||
|
"swing_length": 5,
|
||
|
"liquidity_lookback": 20,
|
||
|
"order_block_lookback": 50,
|
||
|
"min_gap_atr": 0.08,
|
||
|
"eq_tolerance_pips": 50.0
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Spread Rules
|
||
|
```python
|
||
|
SPREAD_RULES = {
|
||
|
"XAUUSD": {"max_abs": 0.5, "max_rel_atr": 0.25, "smc_sensitivity": 1.2},
|
||
|
"BTCUSD": {"max_abs": 30.0, "max_rel_atr": 0.12, "smc_sensitivity": 1.0}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## 📈 Backtesting
|
||
|
|
||
|
### Run Backtest
|
||
|
```python
|
||
|
from analyze_market_smc import backtest_smc_strategy
|
||
|
|
||
|
results = backtest_smc_strategy(
|
||
|
df,
|
||
|
context,
|
||
|
initial_capital=10000,
|
||
|
risk_per_trade=0.02,
|
||
|
symbol='BTCUSD'
|
||
|
)
|
||
|
```
|
||
|
|
||
|
### Backtest Results
|
||
|
- `total_pnl`: Total profit/loss
|
||
|
- `win_rate`: Persentase win rate
|
||
|
- `profit_factor`: Ratio profit vs loss
|
||
|
- `smc_strategy_breakdown`: Breakdown per tipe sinyal SMC
|
||
|
|
||
|
## 🎯 Key SMC Signals
|
||
|
|
||
|
### 1. Break of Structure (BOS)
|
||
|
- Harga break dari struktur sebelumnya
|
||
|
- Konfirmasi trend continuation
|
||
|
- **Action**: Follow trend direction
|
||
|
|
||
|
### 2. Change of Character (CHoCH)
|
||
|
- Perubahan karakter market structure
|
||
|
- Dari bullish ke bearish atau sebaliknya
|
||
|
- **Action**: Prepare untuk trend reversal
|
||
|
|
||
|
### 3. Liquidity Sweep
|
||
|
- Harga sweep liquidity zones lalu reversal
|
||
|
- Tanda smart money action
|
||
|
- **Action**: Counter-trend entry
|
||
|
|
||
|
### 4. Order Block Retest
|
||
|
- Harga kembali test order block yang belum termitigasi
|
||
|
- High probability reaction zones
|
||
|
- **Action**: Entry sesuai OB direction
|
||
|
|
||
|
### 5. FVG Fill
|
||
|
- Harga mengisi Fair Value Gap
|
||
|
- Magnetic effect ke gap zones
|
||
|
- **Action**: Entry saat approach FVG
|
||
|
|
||
|
## 🔄 Example Workflow
|
||
|
|
||
|
### Complete Analysis Workflow
|
||
|
```python
|
||
|
# 1. Fetch data
|
||
|
df = fetch_data('XAUUSD', period='1mo', interval='4h')
|
||
|
|
||
|
# 2. Analisis konteks pasar
|
||
|
context = get_market_context_smc(df, profile='swing', symbol='XAUUSD')
|
||
|
|
||
|
# 3. Check overall bias
|
||
|
print(f"Market Bias: {context['market_bias']}")
|
||
|
|
||
|
# 4. Check SMC elements
|
||
|
smc = context['smc_analysis']
|
||
|
print(f"Structure: {smc['structure']['structure_type']}")
|
||
|
print(f"Active OBs: {len(smc['order_blocks'])}")
|
||
|
print(f"Active FVGs: {len(smc['fair_value_gaps'])}")
|
||
|
|
||
|
# 5. Entry recommendation
|
||
|
entry_exit = context['entry_exit_analysis']
|
||
|
if entry_exit['direction'] != 'WAIT':
|
||
|
best_zone = entry_exit['entry_zones'][0]
|
||
|
print(f"Entry: {entry_exit['direction']} at {best_zone['entry_price']}")
|
||
|
|
||
|
# 6. Profile-specific signals
|
||
|
if context.get('profile_analysis'):
|
||
|
profile = context['profile_analysis']
|
||
|
print(f"Signals: {len(profile['entry_signals'])}")
|
||
|
|
||
|
# 7. Risk assessment
|
||
|
risk = context['risk_assessment']
|
||
|
print(f"Overall Risk: {risk['overall_risk']}")
|
||
|
```
|
||
|
|
||
|
## ⚠️ Important Notes
|
||
|
|
||
|
### Risk Management
|
||
|
- **Always** validate spread conditions
|
||
|
- **Never** ignore risk assessment warnings
|
||
|
- **Position size** berdasarkan risk per trade
|
||
|
- **Stop loss** mandatory untuk semua trades
|
||
|
|
||
|
### Data Requirements
|
||
|
- **Minimum**: 50 candles untuk analisis dasar
|
||
|
- **Recommended**: 200+ candles untuk akurasi optimal
|
||
|
- **Timeframe**: Sesuaikan dengan profil trading
|
||
|
|
||
|
### Performance Optimization
|
||
|
- System dirancang untuk **real-time analysis**
|
||
|
- **Caching** digunakan untuk fungsi berat
|
||
|
- **Error handling** comprehensive
|
||
|
|
||
|
## 🐛 Troubleshooting
|
||
|
|
||
|
### Common Issues
|
||
|
|
||
|
#### 1. "Insufficient data" Error
|
||
|
```python
|
||
|
# Solution: Increase data period
|
||
|
df = fetch_data('BTC-USD', period='3mo', interval='1h') # Lebih panjang
|
||
|
```
|
||
|
|
||
|
#### 2. No Entry Zones Found
|
||
|
```python
|
||
|
# Check market conditions
|
||
|
if context['smc_analysis']['premium_discount_zones']['current_zone'] == 'EQUILIBRIUM':
|
||
|
print("Market in equilibrium - wait for clear bias")
|
||
|
```
|
||
|
|
||
|
#### 3. High Risk Assessment
|
||
|
```python
|
||
|
# Check conflicting signals
|
||
|
bias_components = context['bias_components']
|
||
|
if abs(bias_components['bullish_signals'] - bias_components['bearish_signals']) < 2:
|
||
|
print("Conflicting signals - avoid trading")
|
||
|
```
|
||
|
|
||
|
## 📚 Further Development
|
||
|
|
||
|
### Planned Features
|
||
|
- [ ] **Multi-timeframe analysis**
|
||
|
- [ ] **Volume profile integration**
|
||
|
- [ ] **Real-time alerts**
|
||
|
- [ ] **Advanced backtesting metrics**
|
||
|
- [ ] **Machine learning signal validation**
|
||
|
|
||
|
### Customization Options
|
||
|
- Adjust SMC sensitivity per symbol
|
||
|
- Custom trading sessions
|
||
|
- Enhanced risk metrics
|
||
|
- Portfolio-level analysis
|
||
|
|
||
|
## 🤝 Contributing
|
||
|
|
||
|
Sistem ini dapat dikembangkan lebih lanjut dengan:
|
||
|
|
||
|
1. **Additional SMC concepts**: Wyckoff integration, volume analysis
|
||
|
2. **Enhanced backtesting**: More sophisticated metrics
|
||
|
3. **Real-time features**: Live market scanning
|
||
|
4. **Machine learning**: Pattern recognition enhancement
|
||
|
|
||
|
---
|
||
|
|
||
|
## ✅ System Testing Results
|
||
|
|
||
|
Berdasarkan testing yang telah dilakukan:
|
||
|
|
||
|
- ✅ **Core SMC functions** working properly
|
||
|
- ✅ **All trading profiles** functioning correctly
|
||
|
- ✅ **Entry/exit recommendations** generated successfully
|
||
|
- ✅ **Backtesting system** operational
|
||
|
- ✅ **Multi-symbol support** working
|
||
|
- ✅ **Risk assessment** functioning
|
||
|
|
||
|
## 📞 Support
|
||
|
|
||
|
Untuk pertanyaan atau bantuan pengembangan lebih lanjut, sistem ini telah dirancang dengan dokumentasi lengkap dan error handling yang komprehensif.
|
||
|
|
||
|
**Happy SMC Trading! 🚀📈**
|