Babico_SMA5xBBmid Strategy In-Depth Analysis
Strategy Number: #458 (458th out of 465 strategies)
Strategy Type: Moving Average Crossover Trend Following
Timeframe: Daily (1d)
1. Strategy Overview
Babico_SMA5xBBmid is a concise moving average crossover trend following strategy that uses 5-period EMA crossover with Bollinger Band middle band signals for trading. The strategy design is extremely streamlined, with less than 80 lines of code, suitable as an introductory case for learning Freqtrade strategy development.
Core Features
| Feature | Description |
|---|---|
| Buy Conditions | 1 buy signal (EMA5 crosses above Bollinger Band middle band) |
| Sell Conditions | 1 sell signal (EMA5 crosses below Bollinger Band middle band) |
| Protection Mechanisms | Fixed stop loss + trailing stop + tiered ROI profit-taking |
| Timeframe | Daily (1d) |
| Dependencies | talib.abstract, qtpylib.indicators |
2. Strategy Configuration Analysis
2.1 Base Risk Parameters
# ROI Exit Table
minimal_roi = {
"0": 0.10, # Immediate profit-taking at 10%
"30": 0.05, # After 30 days, reduce to 5%
"60": 0.02 # After 60 days, reduce to 2%
}
# Stop Loss Settings
stoploss = -0.10 # Fixed stop loss at -10%
# Trailing Stop
trailing_stop = True
trailing_only_offset_is_reached = True
trailing_stop_positive = 0.01 # Trailing幅度 1%
trailing_stop_positive_offset = 0.03 # Activate after 3% profit
Design Rationale:
- ROI settings are relatively conservative, initial profit-taking at 10%, gradually decreases over time
- Stop loss at -10% is symmetric with initial ROI target, profit/loss ratio 1:1
- Trailing stop design is gentle: activates after 3% profit, trailing幅度 1%, suitable for locking in small profits
2.2 Order Type Configuration
order_types = {
'buy': 'limit',
'sell': 'limit',
'trailing_stop_loss': 'limit',
'stoploss': 'limit',
'stoploss_on_exchange': False
}
The strategy uses limit orders for buying and selling to avoid slippage risk.
2.3 Other Configuration
use_sell_signal = True # Use custom sell signals
sell_profit_only = True # Only respond to sell signals when profitable
process_only_new_candles = True # Only process on new candles
3. Buy Conditions Detailed
3.1 Single Buy Signal
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
qtpylib.crossed_above(dataframe['ema5'], dataframe['bb_mid'])
),
'buy'] = 1
return dataframe
Logic Analysis:
| Condition | Description |
|---|---|
| EMA5 crosses above bb_mid | 5-period EMA crosses from below to above Bollinger Band middle band |
3.2 Signal Meaning
- Bollinger Band Middle Band: Essentially a 20-period Simple Moving Average (SMA)
- EMA5 crosses above SMA20: Short-term moving average (5-day) crosses medium-term moving average (20-day)
- Trend Confirmation: This is a classic "Golden Cross" pattern, indicating short-term trend strengthening
3.3 Entry Logic
When EMA5 crosses from below Bollinger Band middle band to above:
- Short-term price momentum is strengthening
- Price has broken through medium-term average cost
- May be the beginning of an uptrend
4. Sell Logic Detailed
4.1 Single Sell Signal
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
qtpylib.crossed_above(dataframe['bb_mid'], dataframe['ema5'])
),
'sell'] = 1
return dataframe
Logic Analysis:
| Condition | Description |
|---|---|
| bb_mid crosses above EMA5 | Bollinger Band middle band crosses from below to above EMA5 (i.e., EMA5 crosses below Bollinger Band middle band) |
4.2 Signal Meaning
- EMA5 crosses below SMA20: Classic "Death Cross" pattern
- Trend Weakening: Short-term price momentum weakening, may enter downtrend
- Exit Signal: Completely symmetric with buy signal
4.3 Exit Mechanism Comparison
| Exit Method | Trigger Condition | Effect |
|---|---|---|
| Sell Signal | EMA5 crosses below bb_mid | Actively exit when trend reverses |
| ROI Profit-Taking | Holding time + profit rate | Tiered profit locking |
| Fixed Stop Loss | Loss reaches 10% | Limit maximum loss |
| Trailing Stop | Pullback 1% after 3% profit | Protect small profits |
5. Technical Indicator System
5.1 Core Indicators
| Indicator Category | Specific Indicator | Usage |
|---|---|---|
| Trend Indicator | EMA(5) | Short-term trend tracking |
| Volatility Indicator | BB(20, 2σ) | Middle band as crossover reference |
5.2 Bollinger Band Configuration
bb = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_low'] = bb['lower'] # Lower band
dataframe['bb_mid'] = bb['mid'] # Middle band (SMA20)
dataframe['bb_upp'] = bb['upper'] # Upper band
Note:
- Bollinger Bands use Typical Price (Typical Price = (High + Low + Close) / 3)
- Middle band is essentially 20-period SMA
- Upper and lower bands are not used, only middle band calculated for crossover
5.3 EMA Configuration
dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
5-period Exponential Moving Average, assigns higher weight to recent prices, more sensitive than SMA.
6. Risk Management Features
6.1 Multiple Exit Mechanisms
| Mechanism | Trigger Condition | Protection Effect |
|---|---|---|
| Trend Sell | EMA5 crosses below bb_mid | Actively exit when trend reverses |
| ROI Profit-Taking | Profit rate reaches threshold | Tiered profit locking |
| Fixed Stop Loss | Loss reaches 10% | Limit maximum loss |
| Trailing Stop | Pullback 1% after 3% profit | Protect small profits |
6.2 Profit/Loss Ratio Design
Expected Profit: 10% (initial ROI)
Maximum Loss: 10% (stop loss)
Profit/Loss Ratio: 1:1
6.3 Trailing Stop Analysis
| Parameter | Value | Meaning |
|---|---|---|
| trailing_stop_positive_offset | 3% | Activate after 3% profit |
| trailing_stop_positive | 1% | Maximum pullback 1% |
Effect: If profit reaches 4%, triggers sell when pullback to 3% at most.
7. Strategy Advantages and Limitations
✅ Advantages
- Simple Logic: Single crossover signal, easy to understand and maintain
- Symmetric Design: Buy and sell logic completely symmetric, no position bias
- Concise Code: Less than 80 lines of code, small computational overhead
- Daily Timeframe: Less noise, high signal quality
- Multiple Protection: Signal + ROI + Stop Loss + Trailing Stop quadruple exit
⚠️ Limitations
- Signal Lag: Moving average crossover is a lagging indicator, may miss early trend
- Ranging Market Ineffective: Frequent crossovers in sideways markets lead to repeated stop losses
- Single Parameters: No optimization space provided
- Lack of Filtering: No trend strength or other confirmation conditions
8. Applicable Scenario Recommendations
| Market Environment | Recommended Configuration | Description |
|---|---|---|
| Clear Trend | Default configuration | Best environment for trend following strategies |
| Ranging Market | Not Recommended | Frequent crossovers lead to repeated losses |
| High Volatility | Use with Caution | Increase stop loss幅度 or add filtering |
| Low Volatility | Usable | Fewer signals but higher quality |
9. Applicable Market Environment Detailed
Babico_SMA5xBBmid is a classic moving average crossover strategy. It is most suitable for markets with clear trends, and performs poorly in sideways ranging markets.
9.1 Strategy Core Logic
- Golden Cross Buy: EMA5 crosses above SMA20, short-term trend strengthens
- Death Cross Sell: EMA5 crosses below SMA20, short-term trend weakens
- Trend Following: Does not predict tops or bottoms, only follows existing trends
9.2 Performance in Different Market Environments
| Market Type | Performance Rating | Reason Analysis |
|---|---|---|
| 📈 Clear Trend | ⭐⭐⭐⭐⭐ | Golden/Death Cross signals clear, captures main trend body |
| 🔄 Ranging Market | ⭐⭐☆☆☆ | Frequent crossovers lead to repeated stop losses |
| 📉 Downtrend | ⭐⭐⭐⭐☆ | Death Cross signals exit timely, but may bottom fish during rebounds |
| ⚡️ High Volatility | ⭐⭐⭐☆☆ | Signals increase but false signals also increase |
9.3 Key Configuration Recommendations
| Configuration | Recommended Value | Description |
|---|---|---|
| timeframe | 1d | Daily framework, reduce noise |
| EMA period | 5-10 | Can test different periods |
| BB period | 20 | Middle band is SMA20 |
| stoploss | -0.05 to -0.10 | Adjust according to risk preference |
10. Important Reminder: Learning Value Higher Than Practical Value
10.1 Learning Cost
- Strategy code is concise, suitable for learning Freqtrade framework
- Moving average crossover is the most basic technical analysis method
- Can be used as a template to extend more functionality
10.2 Hardware Requirements
| Number of Trading Pairs | Minimum Memory | Recommended Memory |
|---|---|---|
| Any quantity | 2GB | 4GB |
Note: Strategy calculation volume is extremely small, almost no hardware requirements.
10.3 Differences Between Backtesting and Live Trading
- Moving average crossover strategies usually perform reasonably in backtesting
- In live trading, need to consider slippage and delay
- Ranging markets may perform worse than expected
10.4 Manual Trader Recommendations
- EMA5/SMA20 crossover is a classic technical analysis method
- Can be used as an auxiliary tool for trend judgment
- Recommend combining with other indicators to filter signals
11. Summary
Babico_SMA5xBBmid is an extremely simple moving average crossover trend following strategy. Its core value lies in:
- Concise Code: Suitable for learning and template extension
- Symmetric Logic: Buy and sell logic completely symmetric
- Multiple Protection: Signal + ROI + Stop Loss + Trailing Stop
For quantitative traders, it is recommended to:
- Use as an introductory case for learning Freqtrade
- Can extend to add trend filtering, volume confirmation, and other conditions
- Test use in markets with clear trends