SMAOffset Strategy In-Depth Analysis
Strategy ID: #358 (358th of 465 strategies)
Strategy Type: SMA Offset Mean Reversion Strategy
Timeframe: 5 minutes (5m)
I. Strategy Overview
SMAOffset is a clean and efficient SMA offset strategy with core logic: buy when price falls below the MA by a certain offset percentage, sell when price rises above the MA by a certain offset percentage. The strategy supports switching between SMA (Simple Moving Average) and EMA (Exponential Moving Average), adapting to different market conditions through parameter optimization.
Core Features
| Feature | Description |
|---|---|
| Buy Condition | 1: Price below offset MA |
| Sell Condition | 1: Price above offset MA |
| Protection Mechanism | Trailing stop + Profit-only sell |
| Timeframe | 5 minutes (5m) |
| Dependencies | talib, numpy, qtpylib |
II. Strategy Configuration Analysis
2.1 Basic Risk Parameters
# ROI exit table
minimal_roi = {
"0": 1, # 100% profit required for ROI exit (actually relies on sell signals)
}
# Stop loss setting
stoploss = -0.10 # Fixed stop loss at 10%
Design Philosophy:
- ROI set to 100%, meaning the strategy doesn't rely on ROI for profit taking, but exits through sell signals and trailing stop
- Stop loss set at 10%, serving as the final protection mechanism
2.2 Trailing Stop Configuration
trailing_stop = True
trailing_stop_positive = 0.0001 # Locks 99.99% profit
trailing_stop_positive_offset = 0 # Activates immediately
trailing_only_offset_is_reached = False # No profit threshold needed
Design Philosophy:
- Trailing stop activates immediately, no need to wait for profit threshold
- Locks 99.99% of profit, almost equivalent to "lock any profit"
- Extremely conservative profit protection mechanism
2.3 Order Type Configuration
use_sell_signal = True # Enable sell signals
sell_profit_only = True # Only sell when profitable
III. Buy Condition Detailed Analysis
3.1 Optimizable Parameter Groups
The strategy provides multiple optimizable parameters:
| Parameter Type | Parameter Name | Default Value | Optimization Range |
|---|---|---|---|
| Buy MA Period | base_nb_candles_buy | 30 | 5-80 |
| Buy Offset | low_offset | 0.958 | 0.8-0.99 |
| Buy MA Type | buy_trigger | SMA | SMA/EMA |
3.2 Buy Condition Analysis
Single Buy Condition: Offset MA Low Buy
# Logic
- Price below offset MA (close < ma_offset_buy)
- Volume greater than 0
# Where
ma_offset_buy = MA(close, base_nb_candles_buy) * low_offset
Interpretation: When price falls below the moving average by 4.2% (default offset 0.958), a buy signal is triggered. This is essentially a "mean reversion" strategy - assuming price will revert to the MA, buying when price is low and waiting for reversion.
Parameter Explanation:
base_nb_candles_buy: MA period, longer period means smootherlow_offset: Offset ratio, smaller means more conservative (waiting for larger drops)buy_trigger: MA type, SMA is smoother, EMA is more sensitive
IV. Sell Logic Detailed Analysis
4.1 Trailing Stop Mechanism
The strategy employs an aggressive trailing stop design:
Activation Condition Locked Profit
───────────────────────
Immediate activation 99.99%
Interpretation: As soon as there's any profit, the trailing stop activates, locking almost all profit. This is an extremely conservative profit protection strategy.
4.2 Sell Signal
Single Sell Condition: Offset MA High Sell
# Logic
- Price above offset MA (close > ma_offset_sell)
- Volume greater than 0
# Where
ma_offset_sell = MA(close, base_nb_candles_sell) * high_offset
Interpretation: When price rises above the moving average by 1.2% (default offset 1.012), a sell signal is triggered. This is also mean reversion logic - selling when price is high, waiting for pullback.
Parameter Explanation:
base_nb_candles_sell: Sell MA period (default 30)high_offset: Sell offset ratio (default 1.012)sell_trigger: Sell MA type (default EMA)
4.3 Profit-Only Sell
sell_profit_only = True
Interpretation: The strategy only responds to sell signals when in profit. This protects the strategy from exiting during losses, avoiding "cutting losses."
V. Technical Indicator System
5.1 Core Indicators
| Indicator Category | Specific Indicator | Purpose |
|---|---|---|
| Trend | SMA/EMA | Offset buy/sell line calculation |
5.2 MA Offset Principle
MA offset is the core concept of this strategy:
Buy Line = MA(Price, Period) × Offset Ratio
Sell Line = MA(Price, Period) × Offset Ratio
Core Idea:
- Don't use MA directly as buy/sell points
- Use a certain offset ratio of MA as trigger lines
- Buy offset < 1: Wait for price to fall below MA by certain percentage
- Sell offset > 1: Wait for price to rise above MA by certain percentage
5.3 SMA vs EMA Selection
| MA Type | Characteristics | Applicable Scenarios |
|---|---|---|
| SMA | Smoother, slower response | Clear trending markets |
| EMA | More sensitive, faster response | More volatile markets |
The strategy supports using different MA types for buying and selling, defaulting to SMA for buying and EMA for selling.
VI. Risk Management Features
6.1 Dual Protection Mechanism
| Protection Type | Parameter | Function |
|---|---|---|
| Fixed Stop Loss | -10% | Final defense line |
| Trailing Stop | 99.99% | Locks profit |
6.2 Profit-Only Sell
sell_profit_only = True
Interpretation: Avoids being triggered by sell signals during losses, protecting capital.
6.3 Parameter Isolation Design
The strategy's buy and sell parameters are completely independent:
base_nb_candles_buy # Buy MA period
base_nb_candles_sell # Sell MA period
low_offset # Buy offset
high_offset # Sell offset
buy_trigger # Buy MA type
sell_trigger # Sell MA type
Advantage: Entry and exit can be optimized separately, offering high flexibility.
VII. Strategy Advantages and Limitations
✅ Advantages
- Simple Logic: One buy condition + one sell condition, easy to understand and maintain
- Independent Parameters: Buy and sell parameters optimized separately, high flexibility
- Good Protection: Trailing stop + profit-only sell, dual protection
- Efficient Calculation: Only calculates MA, low resource consumption
⚠️ Limitations
- Mean Reversion Assumption: Assumes price will revert to MA, may fail in strong trends
- Ranging Market Risk: May trade frequently in trendless consolidation, fees eroding profits
- No Trend Filter: No trend judgment indicator, may trade against trends
- Over-Aggressive Trailing Stop: Locking 99.99% profit may cause premature exits
VIII. Applicable Scenario Recommendations
| Market Environment | Recommended Configuration | Notes |
|---|---|---|
| Ranging Market | Moderate offset ratio | Price fluctuates around MA, strategy effective |
| Uptrend | Increase buy offset | Wait for larger pullbacks before entry |
| Downtrend | Decrease sell offset | Exit with profit faster |
| High Volatility Coins | Use EMA | Faster response to price changes |
IX. Applicable Market Environment Details
SMAOffset is a typical mean reversion strategy, suitable for ranging markets, while potentially underperforming in strong trending markets.
9.1 Strategy Core Logic
- Buy Logic: Price below MA by certain percentage → oversold → buy waiting for reversion
- Sell Logic: Price above MA by certain percentage → overbought → sell waiting for pullback
- Assumption: Price oscillates around MA, extreme prices will revert
9.2 Performance in Different Market Environments
| Market Type | Performance Rating | Analysis |
|---|---|---|
| 📈 Uptrend | ⭐⭐☆☆☆ | Price keeps rising, buy signals may get trapped |
| 🔄 Ranging Market | ⭐⭐⭐⭐⭐ | Price oscillates around MA, perfect fit |
| 📉 Downtrend | ⭐⭐☆☆☆ | Price keeps falling, may catch falling knives |
| ⚡ High Volatility | ⭐⭐⭐☆☆ | Trailing stop protects profits, but may exit prematurely |
9.3 Key Configuration Recommendations
| Configuration Item | Ranging Market Suggestion | Trending Market Suggestion |
|---|---|---|
| low_offset | 0.95-0.97 | 0.90-0.95 |
| high_offset | 1.03-1.05 | 1.01-1.03 |
| base_nb_candles | 20-30 | 50-80 |
X. Important Note: Simple Doesn't Mean Easy
10.1 Learning Cost
The strategy logic is simple, but tuning parameters well requires understanding:
- MA period's impact on strategy
- Offset ratio's market adaptability
- SMA and EMA selection
10.2 Hardware Requirements
| Trading Pairs | Minimum Memory | Recommended Memory |
|---|---|---|
| 1-50 pairs | 1GB | 2GB |
| 50-200 pairs | 2GB | 4GB |
10.3 Backtesting vs Live Trading Differences
- Trailing stop slippage may affect actual returns
- Frequent trading in ranging markets generates significant fees
- Recommend setting minimum profit threshold
10.4 Manual Trading Recommendations
- Understand MA offset concept: how much price deviates from MA before entry
- Focus on ranging markets, avoid strong trending markets
- Set minimum trade interval to avoid over-trading
XI. Summary
SMAOffset is a minimalist SMA offset mean reversion strategy. Its core value lies in:
- Clear Logic: Buy low sell high, mean reversion, simple and intuitive
- Independent Parameters: Buy/sell parameters optimized separately, highly adaptable
- Good Protection: Trailing stop + profit-only sell, controllable risk
For quantitative traders, this is a lightweight strategy suitable for ranging markets, but needs careful use or combination with trend filtering indicators in strong trending markets.