Skip to main content

SMAIP3 Strategy In-Depth Analysis

Strategy ID: #354 (354th of 465 strategies)
Strategy Type: Moving Average Deviation + Trend Filter + Hyperopt Optimization Strategy
Timeframe: 5 minutes (5m)


I. Strategy Overview

SMAIP3 is a trend-following strategy based on moving average deviation principles, combining EMA trend filtering, MA deviation buying, and dynamic trailing stop mechanisms. Through the Hyperopt parameter optimization framework, this strategy achieves adaptive adjustment of buy/sell parameters, while including a built-in "bad trading pair" detection mechanism to filter high-risk trading environments.

Core Features

FeatureDescription
Buy Condition1 composite buy signal requiring 5 conditions to be met simultaneously
Sell Condition1 composite sell signal requiring 2 conditions to be met simultaneously
Protection MechanismFixed stop-loss (-33.1%) + Trailing stop + Tiered ROI exit + Bad pair filtering
Timeframe5-minute primary timeframe
Dependenciestalib, pandas, datetime
Special FeaturesHyperopt parameter optimization, bad trading pair detection

II. Strategy Configuration Analysis

2.1 Basic Risk Parameters

# ROI Exit Table
minimal_roi = {
"0": 0.135, # Exit immediately with 13.5% profit
"35": 0.061, # Exit with 6.1% profit after 35 minutes
"86": 0.037, # Exit with 3.7% profit after 86 minutes
"167": 0 # Exit at break-even after 167 minutes
}

# Stop-loss Setting
stoploss = -0.331 # Fixed 33.1% stop-loss

# Trailing Stop
trailing_stop = True
trailing_stop_positive = 0.098 # Start trailing after 9.8% profit
trailing_stop_positive_offset = 0.159 # Trigger when profit pulls back to 15.9%
trailing_only_offset_is_reached = True # Only start trailing when offset is reached

Design Philosophy:

  • ROI uses aggressive time-decreasing design with initial target profit as high as 13.5%
  • Stop-loss is relatively wide (-33.1%), giving the strategy enough room for volatility
  • Trailing stop is precisely designed: only starts after 9.8% profit, triggers sell when profit pulls back to 15.9%
  • Trailing stop offset is higher than activation value, avoiding being shaken out too early

2.2 Order Type Configuration

# Using default configuration
process_only_new_candles = True # Only calculate on new candles
startup_candle_count = 30 # Requires 30 candles for warm-up

III. Buy Conditions Detailed Analysis

3.1 Protection Mechanism

Strategy includes built-in "bad trading pair" detection mechanism:

# Bad trading pair definition
dataframe['pair_is_bad'] = (
(((dataframe['open'].shift(12) - dataframe['close']) / dataframe['close']) >= pair_is_bad_1_threshold) |
(((dataframe['open'].shift(6) - dataframe['close']) / dataframe['close']) >= pair_is_bad_2_threshold)
).astype('int')
Detection TypeParameter DescriptionDefault Value
12-period ago open price dropDrop threshold of current price vs 12-period ago open13.0%
6-period ago open price dropDrop threshold of current price vs 6-period ago open7.5%

Design Purpose: When price drops significantly in a short time, it's flagged as a high-risk trading pair to avoid buying.

3.2 Buy Condition Breakdown

The strategy uses a single composite buy condition requiring all 5 conditions to be met simultaneously:

dataframe.loc[
(
(dataframe['ema_50'] > dataframe['ema_200']) & # Trend filter
(dataframe['close'] > dataframe['ema_200']) & # Price above long-term MA
(dataframe['pair_is_bad'] < 1) & # Not a bad trading pair
(dataframe['close'] < dataframe['ma_offset_buy']) & # Price below deviation MA
(dataframe['volume'] > 0) # Has volume
),
'buy'] = 1
Condition #Condition NameLogic DescriptionPurpose
#1Trend FilterEMA50 > EMA200Confirm uptrend
#2Price PositionClose > EMA200Price above long-term MA
#3Bad Pair Filterpair_is_bad < 1Avoid crashing pairs
#4Deviation BuyClose < deviation MABuy on pullback
#5Volume ConfirmationVolume > 0Filter invalid signals

3.3 Deviation MA Calculation

# Buy deviation MA
ma_offset_buy = SMA/EMA(close, base_nb_candles_buy) * low_offset
# Default: EMA(18) * 0.968

Calculation Logic:

  • Uses 18-period moving average (SMA or EMA)
  • Multiplies by 0.968 deviation coefficient
  • Forms a buy trigger line below the MA

IV. Sell Logic Detailed Analysis

4.1 Tiered ROI Profit-Taking

The strategy uses a four-tier ROI exit mechanism:

Holding Time    Target Profit    Signal Name
────────────────────────────────────────────
0 minutes 13.5% Aggressive profit
35 minutes 6.1% Medium-term profit
86 minutes 3.7% Break-even profit
167 minutes 0% Forced exit

4.2 Trailing Stop Mechanism

Trailing Stop Trigger Process:
├── Profit reaches 9.8% → Start trailing stop
├── Price continues to rise → Stop-loss follows upward
└── Profit pulls back to 15.9% → Trigger sell

Mechanism Features:

  • Requires 9.8% profit to start trailing, avoiding small profits being shaken out
  • Offset value of 15.9% is higher than activation value, giving price enough volatility room
  • Only starts trailing when offset is reached, reducing invalid triggers

4.3 Technical Sell Signal

dataframe.loc[
(
(dataframe['close'] > dataframe['ma_offset_sell']) & # Price above deviation MA
(dataframe['volume'] > 0) # Has volume
),
'sell'] = 1
# Sell deviation MA
ma_offset_sell = SMA/EMA(close, base_nb_candles_sell) * high_offset
# Default: EMA(55) * 1.07
Condition #Condition NameLogic DescriptionPurpose
#1Deviation SellClose > deviation MASell when price above target level
#2Volume ConfirmationVolume > 0Filter invalid signals

V. Technical Indicator System

5.1 Core Indicators

Indicator CategorySpecific IndicatorPurpose
TrendEMA50Medium-term trend judgment
TrendEMA200Long-term trend judgment
Deviationma_offset_buyDynamic buy trigger line
Deviationma_offset_sellDynamic sell trigger line
Riskpair_is_badBad trading pair detection

5.2 Hyperopt Optimization Parameters

Parameter CategoryParameter NameValue RangeDefault Value
Buy Parametersbase_nb_candles_buy16-6018
Buy Parameterslow_offset0.8-0.990.968
Buy Parametersbuy_triggerSMA/EMAEMA
Sell Parametersbase_nb_candles_sell16-6055
Sell Parametershigh_offset0.8-1.11.07
Sell Parameterssell_triggerSMA/EMAEMA
Risk Parameterspair_is_bad_1_threshold0.00-0.300.13
Risk Parameterspair_is_bad_2_threshold0.00-0.250.075

VI. Risk Management Features

6.1 Bad Trading Pair Detection Mechanism

Detection Logic:

  • 12-period ago open price drop vs current price ≥ 13% → Mark as bad pair
  • 6-period ago open price drop vs current price ≥ 7.5% → Mark as bad pair

Design Purpose:

  • Filter trading pairs with short-term crashes
  • Avoid "catching falling knives" risk
  • Dynamic adjustment, real-time detection

6.2 Trend Filter Dual Insurance

Trend Confirmation Mechanism:
├── EMA50 > EMA200 → Confirm short-term trend upward
└── close > EMA200 → Confirm price above long-term MA

Dual Confirmation: Only buy when both conditions are met, ensuring being in a clear uptrend.

6.3 Precision Trailing Stop

trailing_stop = True
trailing_stop_positive = 0.098 # 9.8% activation
trailing_stop_positive_offset = 0.159 # 15.9% trigger
trailing_only_offset_is_reached = True # Only trail when offset reached

Design Highlights:

  • Don't rush to trail, wait until profit reaches a certain level
  • Give price enough volatility room
  • Avoid being shaken out by small fluctuations

VII. Strategy Advantages and Limitations

✅ Advantages

  1. Strict Trend Confirmation: EMA50/200 dual filtering ensures buying in uptrend
  2. Bad Pair Filtering: Avoids buying during crashes, proactive risk control
  3. Optimizable Parameters: Auto-optimize parameters through Hyperopt framework
  4. Precision Trailing Stop: Avoids small profits being shaken out
  5. Reasonable Buy Logic: Trend up + buy on pullback

⚠️ Limitations

  1. Wide Stop-Loss: 33.1% stop-loss may be too large, needs capital management coordination
  2. Parameter Dependency: Default parameters may not suit all trading pairs
  3. Simple Sell Condition: Only relies on deviation MA for selling, lacks multiple confirmations
  4. Aggressive Target: 13.5% initial target may be hard to reach

VIII. Applicable Scenario Recommendations

Market EnvironmentRecommended ConfigurationNotes
Uptrend PullbackDefault configurationBest scenario, buy pullbacks
Single-direction RallyAdjust low_offsetMay miss entry opportunities
Oscillating MarketReduce tradingTrend filter will reduce signals
Single-direction DowntrendDisableTrend filter will prevent buying

IX. Applicable Market Environment Details

SMAIP3 strategy is a trend-following + pullback buying strategy. Based on its code architecture and Hyperopt optimization design, it is best suited for pullback markets in uptrends, while performing poorly in oscillating or downtrending markets.

9.1 Strategy Core Logic

  • Trend Confirmation: EMA50 > EMA200 confirms uptrend
  • Position Confirmation: close > EMA200 ensures price above long-term MA
  • Pullback Buy: close < ma_offset_buy buys on pullback
  • Risk Filter: pair_is_bad avoids crashing pairs
  • Deviation Sell: close > ma_offset_sell exits at target level

9.2 Performance in Different Market Environments

Market TypePerformance RatingReason Analysis
📈 Uptrend Pullback⭐⭐⭐⭐⭐Best scenario, pullback buying most effective
🔄 Sideways Oscillation⭐⭐⭐☆☆Trend filter reduces signals, occasional trades
📉 Single-direction Downtrend⭐☆☆☆☆Trend filter prevents buying, basically no signals
⚡️ High Volatility⭐⭐☆☆☆Bad pair detection may be oversensitive

9.3 Key Configuration Recommendations

Configuration ItemRecommended ValueNotes
Stop-loss-0.25 ~ -0.35Adjust based on trading pair volatility
low_offset0.95 ~ 0.98Lower to increase entry opportunities
high_offset1.05 ~ 1.10Raise to extend holding time
Timeframe5m (default)Try 15m for more stable signals

X. Important Reminder: The Cost of Complexity

10.1 Learning Curve

This strategy uses Hyperopt parameter optimization, requiring understanding of:

  • EMA indicator's trend judgment principle
  • MA deviation buy/sell logic
  • Hyperopt parameter optimization usage
  • Trailing stop trigger mechanism

10.2 Hardware Requirements

Number of PairsMinimum MemoryRecommended Memory
1-10 pairs2GB4GB
10-50 pairs4GB8GB

10.3 Backtesting vs Live Trading Differences

  • Hyperopt Overfitting Risk: Optimized parameters may be overfitted to historical data
  • Live Trading Notes: Bad pair detection may be oversensitive
  • Recommendation: Use out-of-sample data to validate parameter effectiveness

10.4 Manual Trader Recommendations

  • Wait for EMA50 to cross above EMA200 to confirm uptrend
  • Consider buying when price pulls back near EMA50
  • Pay attention to stop-loss settings, control single loss
  • Can reference "bad trading pair" logic to avoid crashing coins

XI. Summary

SMAIP3 Strategy is a parameter-optimizable trend pullback buying strategy. Its core value lies in:

  1. Strict Trend Confirmation: Dual MA filtering ensures buying in uptrend
  2. Proactive Risk Control: Bad pair detection avoids crash risk
  3. Precision Trailing Stop: Gives price enough volatility room, avoiding early exit
  4. Optimizable Parameters: Auto-find optimal parameters through Hyperopt

For quantitative traders, this is a strategy suitable for trending markets, but requires Hyperopt optimization for best results.