Skip to main content

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

FeatureDescription
Buy Conditions1 buy signal (EMA5 crosses above Bollinger Band middle band)
Sell Conditions1 sell signal (EMA5 crosses below Bollinger Band middle band)
Protection MechanismsFixed stop loss + trailing stop + tiered ROI profit-taking
TimeframeDaily (1d)
Dependenciestalib.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:

ConditionDescription
EMA5 crosses above bb_mid5-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:

  1. Short-term price momentum is strengthening
  2. Price has broken through medium-term average cost
  3. 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:

ConditionDescription
bb_mid crosses above EMA5Bollinger 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 MethodTrigger ConditionEffect
Sell SignalEMA5 crosses below bb_midActively exit when trend reverses
ROI Profit-TakingHolding time + profit rateTiered profit locking
Fixed Stop LossLoss reaches 10%Limit maximum loss
Trailing StopPullback 1% after 3% profitProtect small profits

5. Technical Indicator System

5.1 Core Indicators

Indicator CategorySpecific IndicatorUsage
Trend IndicatorEMA(5)Short-term trend tracking
Volatility IndicatorBB(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

MechanismTrigger ConditionProtection Effect
Trend SellEMA5 crosses below bb_midActively exit when trend reverses
ROI Profit-TakingProfit rate reaches thresholdTiered profit locking
Fixed Stop LossLoss reaches 10%Limit maximum loss
Trailing StopPullback 1% after 3% profitProtect 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

ParameterValueMeaning
trailing_stop_positive_offset3%Activate after 3% profit
trailing_stop_positive1%Maximum pullback 1%

Effect: If profit reaches 4%, triggers sell when pullback to 3% at most.


7. Strategy Advantages and Limitations

✅ Advantages

  1. Simple Logic: Single crossover signal, easy to understand and maintain
  2. Symmetric Design: Buy and sell logic completely symmetric, no position bias
  3. Concise Code: Less than 80 lines of code, small computational overhead
  4. Daily Timeframe: Less noise, high signal quality
  5. Multiple Protection: Signal + ROI + Stop Loss + Trailing Stop quadruple exit

⚠️ Limitations

  1. Signal Lag: Moving average crossover is a lagging indicator, may miss early trend
  2. Ranging Market Ineffective: Frequent crossovers in sideways markets lead to repeated stop losses
  3. Single Parameters: No optimization space provided
  4. Lack of Filtering: No trend strength or other confirmation conditions

8. Applicable Scenario Recommendations

Market EnvironmentRecommended ConfigurationDescription
Clear TrendDefault configurationBest environment for trend following strategies
Ranging MarketNot RecommendedFrequent crossovers lead to repeated losses
High VolatilityUse with CautionIncrease stop loss幅度 or add filtering
Low VolatilityUsableFewer 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 TypePerformance RatingReason 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

ConfigurationRecommended ValueDescription
timeframe1dDaily framework, reduce noise
EMA period5-10Can test different periods
BB period20Middle band is SMA20
stoploss-0.05 to -0.10Adjust 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 PairsMinimum MemoryRecommended Memory
Any quantity2GB4GB

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:

  1. Concise Code: Suitable for learning and template extension
  2. Symmetric Logic: Buy and sell logic completely symmetric
  3. 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