Skip to main content

ReinforcedAverageStrategy In-Depth Analysis

Strategy ID: #346 (346th of 465 strategies)
Strategy Type: Dual Moving Average Crossover + Resampled Trend Filter
Timeframe: 4 hours (4h)


I. Strategy Overview

ReinforcedAverageStrategy is a trend following strategy based on moving average crossover signals. It captures trend turning points through crossovers between short-term and medium-term Exponential Moving Averages (EMA), while introducing resampling technology to confirm trends from higher timeframes, effectively filtering out false breakout signals.

Core Features

FeatureDescription
Buy Conditions1 buy signal, combining MA crossover with trend filter
Sell Conditions1 sell signal, reverse MA crossover
Protection MechanismsTrailing stop mechanism
TimeframePrimary 4h + resampled trend confirmation
Dependenciestalib, qtpylib, technical

II. Strategy Configuration Analysis

2.1 Basic Risk Parameters

# ROI exit table
minimal_roi = {
"0": 0.5 # 50% profit target
}

# Stop loss settings
stoploss = -0.2 # 20% fixed stop loss

# Trailing stop configuration
trailing_stop = True
trailing_stop_positive = 0.01 # Positive trailing threshold 1%
trailing_stop_positive_offset = 0.02 # Activation offset 2%
trailing_only_offset_is_reached = False

Design Rationale:

  • ROI set to 50%, very loose, practically relies on trailing stop and sell signals
  • 20% stop loss space is relatively wide, suitable for 4-hour level trend following
  • Trailing stop activates once price rises above 2%, then triggers sell on 1% pullback

2.2 Order Type Configuration

process_only_new_candles = False
use_sell_signal = True
sell_profit_only = True
ignore_roi_if_buy_signal = False

Description:

  • sell_profit_only = True: Only responds to sell signals when profitable, avoids premature exit during losses

III. Buy Condition Detailed Analysis

3.1 Buy Signal Logic

The strategy uses a single buy condition, but includes triple verification:

dataframe.loc[
(
qtpylib.crossed_above(dataframe['maShort'], dataframe['maMedium']) &
(dataframe['close'] > dataframe[f'resample_{self.resample_interval}_sma']) &
(dataframe['volume'] > 0)
),
'buy'] = 1

Condition Breakdown

Condition #Condition TypeLogic Description
1MA CrossoverShort-term EMA(8) crosses above medium-term EMA(21)
2Trend ConfirmationClose above resampled SMA(50)
3Volume CheckVolume greater than 0 (valid trading)

3.2 Technical Indicator Calculation

# Short-term MA: 8-period exponential moving average
dataframe['maShort'] = ta.EMA(dataframe, timeperiod=8)

# Medium-term MA: 21-period exponential moving average
dataframe['maMedium'] = ta.EMA(dataframe, timeperiod=21)

# Resampled trend MA: SMA(50) at 12x timeframe
# i.e., 4h × 12 = 48h ≈ 2-day cycle
self.resample_interval = timeframe_to_minutes(self.timeframe) * 12
dataframe_long = resample_to_interval(dataframe, self.resample_interval)
dataframe_long['sma'] = ta.SMA(dataframe_long, timeperiod=50, price='close')

3.3 Auxiliary Indicators (For Chart Display)

# Bollinger Bands indicator
bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2)
dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_upperband'] = bollinger['upper']
dataframe['bb_middleband'] = bollinger['mid']

IV. Sell Logic Detailed Analysis

4.1 Sell Signal

The strategy uses a single sell signal:

dataframe.loc[
(
qtpylib.crossed_above(dataframe['maMedium'], dataframe['maShort']) &
(dataframe['volume'] > 0)
),
'sell'] = 1

Logic Description:

  • Medium-term EMA(21) crosses above short-term EMA(8), i.e., short-term MA crosses below medium-term MA
  • Indicates trend turning from bullish to bearish, triggers sell

4.2 Trailing Stop Mechanism

The strategy configures trailing stop as a protection mechanism:

ParameterValueDescription
trailing_stopTrueEnable trailing stop
trailing_stop_positive0.01Stop distance 1%
trailing_stop_positive_offset0.02Activation threshold 2%
trailing_only_offset_is_reachedFalseNo restriction on activation

How It Works:

  1. When price rises 2%, trailing stop activates
  2. Stop line always stays 1% below the highest point
  3. When price pulls back more than 1%, sell triggers

V. Technical Indicator System

5.1 Core Indicators

Indicator CategorySpecific IndicatorsPurpose
Trend IndicatorsEMA(8), EMA(21)MA crossover signals
Resampled IndicatorsSMA(50) @ 48h cycleMajor trend direction confirmation
Volatility IndicatorsBollinger Bands(20, 2)Auxiliary chart display

5.2 Resampling Technology Explanation

The strategy uses resample_to_interval function to resample 4-hour data to 48-hour cycles:

Original timeframe: 4h
Resampling factor: 12
Resampled cycle: 4h × 12 = 48h ≈ 2 days

Purpose: Confirm trend direction through higher-dimension timeframes, avoiding entries during false breakouts in smaller cycles.


VI. Risk Management Features

6.1 Multiple Trend Filters

The strategy requires double confirmation when buying:

  • Small cycle signal: EMA(8) crosses above EMA(21)
  • Large cycle trend: Close above 48-hour cycle SMA(50)

6.2 Trailing Stop Protection

Trailing stop mechanism lets profits run:

  • 2% activation threshold ensures not exiting too early
  • 1% pullback tolerance protects existing profits

6.3 Sell Only When Profitable

sell_profit_only = True configuration ensures:

  • Don't respond to sell signals during losses
  • Wait for price recovery or stop loss trigger

VII. Strategy Advantages and Limitations

✅ Advantages

  1. Simple and Clear Logic: Only relies on MA crossovers, easy to understand and debug
  2. Trend Confirmation Mechanism: Resampled SMA(50) effectively filters counter-trend trades
  3. Trailing Stop Protection: Lets profits run while controlling drawdown
  4. Large Cycle Stability: 4-hour timeframe reduces noise interference

⚠️ Limitations

  1. Lag: MA signals are inherently lagging, may miss trend initiation points
  2. Unfavorable in Oscillating Markets: Frequent crossovers during sideways oscillation produce false signals
  3. Single Parameter Set: Only one MA parameter group, lacks adaptability
  4. Large Stop Loss: 20% stop loss requires higher capital management standards

VIII. Suitable Scenario Recommendations

Market EnvironmentRecommended ConfigurationDescription
Clear Trend MarketDefault configurationMA crossovers perform well in trends
Sideways OscillationUse cautiouslyMay produce multiple false signals
High Volatility MarketAppropriately widen stop lossAvoid being stopped by normal fluctuations

IX. Suitable Market Environment Analysis

ReinforcedAverageStrategy is a classic trend following strategy. Based on its code architecture and MA crossover core logic, it performs best in one-way trending markets, while performing poorly in sideways oscillating markets.

9.1 Strategy Core Logic

  • MA Crossover Signals: Captures trend turning points using EMA fast/slow line crossovers
  • Resampled Trend Filter: Confers major direction through higher timeframes
  • Trailing Stop Mechanism: Dynamically protects profits, adapts to trend extensions

9.2 Performance in Different Market Environments

Market TypePerformance RatingAnalysis
📈 One-way Uptrend⭐⭐⭐⭐⭐MA golden cross signals accurate, trailing stop captures full profits
📉 One-way Downtrend⭐⭐⭐⭐☆Waits in cash, won't trade against trend
🔄 Sideways Oscillation⭐⭐☆☆☆Frequent crossovers create false signals, repeated stop losses
⚡ High Volatility Oscillation⭐☆☆☆☆MA crossovers distorted, frequent stop triggers

9.3 Key Configuration Recommendations

Configuration ItemRecommended ValueDescription
Resampling factor12Keep default, approximately 2-day cycle
Trailing stop offset2%Adapt to 4-hour volatility
Stop loss ratio15%-20%Adjust based on asset volatility

X. Important Note: The Cost of Complexity

10.1 Learning Cost

This strategy has relatively simple logic, suitable for beginners to understand the basic principles of MA crossover trading. Resampling technology adds a small amount of complexity, but the overall barrier is low.

10.2 Hardware Requirements

Trading PairsMinimum MemoryRecommended Memory
1-10 pairs2GB4GB
10-50 pairs4GB8GB

Strategy computation is moderate, can run on a regular VPS.

10.3 Backtest vs Live Trading Differences

MA strategies typically perform well in backtests, but in live trading note:

  • Slippage Impact: Price may have already moved when crossover signal triggers
  • Delayed Execution: Must wait for 4-hour candle close to confirm signal

10.4 Manual Trader Recommendations

This strategy's logic can be manually replicated:

  1. Add EMA(8) and EMA(21) to your chart
  2. Wait for golden cross confirmation (short-term crossing above medium-term)
  3. Check if major trend is upward on larger timeframe
  4. Set trailing stop and enter

XI. Summary

ReinforcedAverageStrategy is a classic trend following strategy that constructs trading signals through dual MA crossovers and resampled trend filtering. Its core value lies in:

  1. Simple and Effective: MA crossover is one of the most classic trend signals
  2. Trend Filtering: Resampling mechanism avoids counter-trend trading
  3. Controlled Risk: Trailing stop protects profits

For quantitative traders, this is a foundational strategy suitable for learning and improvement, serving as a reference implementation for trend following modules. Recommend using in clearly trending markets, and reducing position or pausing during oscillating periods.