Files
managing-apps/docs/StrategyCombo-README.md
Oda faafedbdd9 Optimize strategies (#23)
* Update Tradingbox + set limit price

* Change discord message
2025-05-30 14:00:27 +07:00

177 lines
6.3 KiB
Markdown

# Strategy Combination System
## Overview
The improved `TradingBox` strategy combination system provides sophisticated logic for combining multiple trading strategies with different purposes and behaviors. The system is designed around three distinct strategy types, each serving a specific role in the trading decision process.
## Strategy Types
### 1. Signal Strategies (`SignalType.Signal`)
- **Purpose**: Generate rare, precise entry signals when specific conditions are met
- **Behavior**: Sparse signal generation - only fire when opportunity is detected
- **Examples**: RSI Divergence, MACD Cross, Chandelier Exit
- **Weight**: High priority in final decision
### 2. Trend Strategies (`SignalType.Trend`)
- **Purpose**: Identify overall market direction on every candlestick
- **Behavior**: Continuous output (Long/Short/Neutral for each candle)
- **Examples**: EMA Trend, SuperTrend, Moving Average Cross
- **Weight**: Supporting role, validates signal direction
### 3. Context Strategies (`SignalType.Context`)
- **Purpose**: Provide market context to prevent trades in unfavorable conditions
- **Behavior**: Act as filters/guards (allow/block trades)
- **Examples**: Volatility filters, Volume filters, Time-based restrictions
- **Weight**: Veto power - can block otherwise valid signals
## Combination Logic
### Basic Flow
1. **Context Validation**: All context strategies must allow the trade (configurable)
2. **Signal Analysis**: Evaluate entry signals using majority voting
3. **Trend Analysis**: Determine overall market direction
4. **Final Decision**: Combine signal and trend with confidence scoring
### Decision Matrix
| Signal Direction | Trend Direction | Result | Confidence |
|-----------------|----------------|---------|------------|
| Long/Short | Same | Execute | High |
| Long/Short | Neutral/None | Execute | Medium |
| Long/Short | Opposite | Execute* | Low |
| None | Long/Short | Execute | Medium/Low |
| None | None | No Trade | N/A |
*_Depends on `AllowSignalTrendOverride` configuration_
## Configuration Options
The system uses `StrategyComboConfig` to customize behavior:
```csharp
var config = new StrategyComboConfig
{
// Trend agreement thresholds
TrendStrongAgreementThreshold = 0.66m, // 66% for strong trend
// Signal agreement thresholds
SignalAgreementThreshold = 0.5m, // 50% majority for signals
// Override behavior
AllowSignalTrendOverride = true, // Allow signals to override trends
// Quality filters
MinimumConfidence = Confidence.Low, // Minimum confidence to trade
MinimumContextConfidence = Confidence.Medium, // Minimum context quality required
// Defaults
DefaultExchange = TradingExchanges.Binance
};
```
### Context Strategy Behavior
Context strategies now work with **confidence levels** rather than allow/block decisions:
- **High Confidence**: Ideal market conditions (e.g., low volatility)
- **Medium Confidence**: Normal market conditions
- **Low Confidence**: Elevated risk conditions (trade with caution)
- **No Confidence**: Poor conditions (blocks trading)
All context strategies must meet the `MinimumContextConfidence` threshold for trades to proceed.
## Usage Examples
### Basic Usage (Default Configuration)
```csharp
var signal = TradingBox.GetSignal(candles, strategies, previousSignals);
```
### Advanced Usage (Custom Configuration)
```csharp
var config = new StrategyComboConfig
{
TrendStrongAgreementThreshold = 0.75m, // Require 75% trend agreement
MinimumConfidence = Confidence.Medium, // Only trade medium+ confidence
MinimumContextConfidence = Confidence.High, // Only trade in ideal conditions
AllowSignalTrendOverride = false // Don't allow trend conflicts
};
var signal = TradingBox.GetSignal(candles, strategies, previousSignals, config);
```
### Typical Strategy Combinations
#### Conservative Setup
- 1 Signal Strategy (RSI Divergence)
- 2 Trend Strategies (EMA Trend, SuperTrend)
- 1 Context Strategy (Volatility Filter)
#### Aggressive Setup
- 2 Signal Strategies (MACD Cross, Chandelier Exit)
- 1 Trend Strategy (EMA Trend)
- No Context Strategies
#### Scalping Setup
- 3 Signal Strategies (Quick signals)
- 1 Trend Strategy (Short-term trend)
- 2 Context Strategies (Volume + Time filters)
## Key Improvements
### 1. **Flexible Requirements**
- No longer requires ALL strategies to produce signals
- Different logic for different strategy types
- Configurable thresholds and behavior
### 2. **Intelligent Voting**
- Majority voting for signals and trends
- Weighted decisions based on strategy type
- Handles neutral/conflicting signals gracefully
### 3. **Confidence Scoring**
- Dynamic confidence based on agreement levels
- Considers signal-trend alignment
- Configurable minimum confidence thresholds
### 4. **Context Awareness**
- Context strategies provide market condition quality through confidence levels
- Configurable minimum context confidence thresholds
- Simplified logic: all context strategies must meet minimum confidence
- No more complex unanimous vs. majority requirements
### 5. **Trend Reversal Support**
- Signal strategies can override trend direction
- Useful for catching trend reversals
- Configurable override behavior
## Best Practices
### Strategy Selection
1. **Use 1-2 Signal strategies** for entry precision
2. **Use 1-3 Trend strategies** for direction confirmation
3. **Use 0-2 Context strategies** for risk management
### Configuration Tuning
1. **Start with defaults** and adjust based on backtesting
2. **Higher thresholds** = fewer but higher quality signals
3. **Lower thresholds** = more signals but potentially more noise
### Testing Recommendations
1. **Backtest different configurations** on historical data
2. **Monitor confidence distributions** in live trading
3. **Adjust thresholds** based on performance metrics
## Migration from Old System
The new system is backward compatible:
- Existing calls to `GetSignal()` work unchanged
- Old unanimous agreement logic is still available via configuration
- New overloads provide additional control when needed
## Performance Considerations
- Strategy evaluation is optimized for efficiency
- Signal caching prevents duplicate calculations
- Configurable quality filters reduce unnecessary trades
- Separate validation logic for different strategy types