Skip to main content

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

FeatureDescription
Buy Condition1: Price below offset MA
Sell Condition1: Price above offset MA
Protection MechanismTrailing stop + Profit-only sell
Timeframe5 minutes (5m)
Dependenciestalib, 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 TypeParameter NameDefault ValueOptimization Range
Buy MA Periodbase_nb_candles_buy305-80
Buy Offsetlow_offset0.9580.8-0.99
Buy MA Typebuy_triggerSMASMA/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 smoother
  • low_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 CategorySpecific IndicatorPurpose
TrendSMA/EMAOffset 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 TypeCharacteristicsApplicable Scenarios
SMASmoother, slower responseClear trending markets
EMAMore sensitive, faster responseMore 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 TypeParameterFunction
Fixed Stop Loss-10%Final defense line
Trailing Stop99.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

  1. Simple Logic: One buy condition + one sell condition, easy to understand and maintain
  2. Independent Parameters: Buy and sell parameters optimized separately, high flexibility
  3. Good Protection: Trailing stop + profit-only sell, dual protection
  4. Efficient Calculation: Only calculates MA, low resource consumption

⚠️ Limitations

  1. Mean Reversion Assumption: Assumes price will revert to MA, may fail in strong trends
  2. Ranging Market Risk: May trade frequently in trendless consolidation, fees eroding profits
  3. No Trend Filter: No trend judgment indicator, may trade against trends
  4. Over-Aggressive Trailing Stop: Locking 99.99% profit may cause premature exits

VIII. Applicable Scenario Recommendations

Market EnvironmentRecommended ConfigurationNotes
Ranging MarketModerate offset ratioPrice fluctuates around MA, strategy effective
UptrendIncrease buy offsetWait for larger pullbacks before entry
DowntrendDecrease sell offsetExit with profit faster
High Volatility CoinsUse EMAFaster 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 TypePerformance RatingAnalysis
📈 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 ItemRanging Market SuggestionTrending Market Suggestion
low_offset0.95-0.970.90-0.95
high_offset1.03-1.051.01-1.03
base_nb_candles20-3050-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 PairsMinimum MemoryRecommended Memory
1-50 pairs1GB2GB
50-200 pairs2GB4GB

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:

  1. Clear Logic: Buy low sell high, mean reversion, simple and intuitive
  2. Independent Parameters: Buy/sell parameters optimized separately, highly adaptable
  3. 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.