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
| Feature | Description |
|---|---|
| Buy Conditions | 1 buy signal, combining MA crossover with trend filter |
| Sell Conditions | 1 sell signal, reverse MA crossover |
| Protection Mechanisms | Trailing stop mechanism |
| Timeframe | Primary 4h + resampled trend confirmation |
| Dependencies | talib, 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 Type | Logic Description |
|---|---|---|
| 1 | MA Crossover | Short-term EMA(8) crosses above medium-term EMA(21) |
| 2 | Trend Confirmation | Close above resampled SMA(50) |
| 3 | Volume Check | Volume 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:
| Parameter | Value | Description |
|---|---|---|
| trailing_stop | True | Enable trailing stop |
| trailing_stop_positive | 0.01 | Stop distance 1% |
| trailing_stop_positive_offset | 0.02 | Activation threshold 2% |
| trailing_only_offset_is_reached | False | No restriction on activation |
How It Works:
- When price rises 2%, trailing stop activates
- Stop line always stays 1% below the highest point
- When price pulls back more than 1%, sell triggers
V. Technical Indicator System
5.1 Core Indicators
| Indicator Category | Specific Indicators | Purpose |
|---|---|---|
| Trend Indicators | EMA(8), EMA(21) | MA crossover signals |
| Resampled Indicators | SMA(50) @ 48h cycle | Major trend direction confirmation |
| Volatility Indicators | Bollinger 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
- Simple and Clear Logic: Only relies on MA crossovers, easy to understand and debug
- Trend Confirmation Mechanism: Resampled SMA(50) effectively filters counter-trend trades
- Trailing Stop Protection: Lets profits run while controlling drawdown
- Large Cycle Stability: 4-hour timeframe reduces noise interference
⚠️ Limitations
- Lag: MA signals are inherently lagging, may miss trend initiation points
- Unfavorable in Oscillating Markets: Frequent crossovers during sideways oscillation produce false signals
- Single Parameter Set: Only one MA parameter group, lacks adaptability
- Large Stop Loss: 20% stop loss requires higher capital management standards
VIII. Suitable Scenario Recommendations
| Market Environment | Recommended Configuration | Description |
|---|---|---|
| Clear Trend Market | Default configuration | MA crossovers perform well in trends |
| Sideways Oscillation | Use cautiously | May produce multiple false signals |
| High Volatility Market | Appropriately widen stop loss | Avoid 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 Type | Performance Rating | Analysis |
|---|---|---|
| 📈 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 Item | Recommended Value | Description |
|---|---|---|
| Resampling factor | 12 | Keep default, approximately 2-day cycle |
| Trailing stop offset | 2% | Adapt to 4-hour volatility |
| Stop loss ratio | 15%-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 Pairs | Minimum Memory | Recommended Memory |
|---|---|---|
| 1-10 pairs | 2GB | 4GB |
| 10-50 pairs | 4GB | 8GB |
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:
- Add EMA(8) and EMA(21) to your chart
- Wait for golden cross confirmation (short-term crossing above medium-term)
- Check if major trend is upward on larger timeframe
- 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:
- Simple and Effective: MA crossover is one of the most classic trend signals
- Trend Filtering: Resampling mechanism avoids counter-trend trading
- 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.