
The Advanced Moving Average with Engulfing Pattern Quantitative Strategy is a trading system that combines multiple technical indicators, primarily based on moving averages, engulfing candlestick patterns, and price structure breakouts to determine trading signals. This strategy seeks to improve reliability by finding confluence points of multiple factors, following a trend-following approach that looks for entry opportunities in confirmed market directions. The core logic uses 66-period and 85-period simple moving averages to determine the overall trend direction, combines short-term reversal signals provided by engulfing candlestick patterns, and confirms trend continuity through structure breakouts (breaking previous highs or lows), forming a comprehensive trading decision system.
The core principles of this strategy are based on the collaborative confirmation of multiple technical indicators, including the following key components:
Dual Moving Average System: The strategy uses 66-period and 85-period simple moving averages (SMA) to determine the overall market trend direction. When price is above both moving averages, it is considered a bullish trend; when price is below both moving averages, it is considered a bearish trend.
Engulfing Pattern Recognition:
Price Structure Breakout Recognition:
Multiple Confirmation Mechanism: The strategy requires at least 2 out of 4 conditions to be met to generate a trading signal:
Cooldown Period: The strategy implements a directional cooldown mechanism that prevents generating repeated trading signals in the same direction within a specified number of candles after a signal is triggered, to avoid overtrading.
Multiple Confirmation Mechanism: Requires at least two technical indicators to simultaneously meet conditions before generating a trading signal, greatly reducing the possibility of false signals and improving signal reliability.
Combination of Trend and Reversal: Captures medium to long-term trends through moving averages while utilizing engulfing patterns to capture short-term reversal opportunities, achieving an organic combination of trend and reversal strategies.
Price Structure Analysis: Incorporates market structure analysis by identifying breakouts of highs and lows to confirm trend continuity, which is a more advanced technical analysis method.
Cooldown Mechanism: Designed with a cooldown feature that effectively prevents overtrading problems caused by consecutive signals, helping to control trading frequency.
Parameter Adjustability: Key parameters in the strategy (such as moving average periods, cooldown period length) can be adjusted according to different markets and timeframes, providing good adaptability.
Risk-Reward Optimization: According to strategy testing, although the win rate is approximately 30%, profitable trades have a significant advantage over losing trades, conforming to the trading principle of “let profits run, control losses.”
False Breakout Risk: Price structure breakouts may experience false breakouts, especially in highly volatile markets, potentially leading to incorrect trading signals. The solution is to add confirmation mechanisms, such as requiring continuity after breakout or incorporating volume analysis.
Moving Average Lag: Moving averages are inherently lagging indicators and may not reflect price changes promptly in rapidly changing markets, causing delayed entry signals. Consider using more sensitive indicators like EMA or adjusting moving average periods to mitigate this issue.
Overtrading Risk: Despite having a cooldown mechanism, the strategy author mentions that the strategy still generates numerous signals, potentially leading to excessive trading. It is recommended to add stricter filtering conditions or extend the cooldown period.
Market Environment Dependency: This strategy performs better in markets with clear trends but may generate more false signals in ranging or highly volatile markets. Add market environment recognition mechanisms to adjust strategy parameters or pause trading in different market states.
Lack of Stop-Loss Mechanism: The code does not explicitly set a stop-loss strategy, which may lead to excessive losses on individual trades. It is recommended to implement strict stop-loss mechanisms, such as ATR-based stops or fixed percentage stops.
Perfect the Fibonacci Retracement Zone: The current Fibonacci retracement check in the code is a placeholder (always returns true). Implementing actual Fibonacci retracement zone recognition can provide more precise price level support for entry points.
Add Volume Confirmation: Incorporating volume analysis into the strategy can help confirm the validity of price breakouts and reduce false breakout risks. Especially during structure breakouts, increased volume can enhance breakout reliability.
Dynamic Parameter Adjustment: Dynamically adjust moving average periods and cooldown period length based on market volatility (such as the ATR indicator) to better adapt to different market environments.
Add Take-Profit and Stop-Loss Mechanisms: Implement risk management-based profit-taking and stop-loss strategies, such as dynamic stops based on ATR or using previous support and resistance levels as take-profit and stop-loss points.
Market Environment Filtering: Add market environment recognition modules, such as using the ADX indicator to determine whether the market is in a trending state, pausing trading or adjusting strategy parameters in non-trending markets.
Time Filtering: Add trading time filters to avoid high-volatility or low-liquidity periods, such as major economic data releases or market opening and closing sessions.
Signal Strength Grading: Grade signals based on the number and strength of conditions met, and adjust position sizes accordingly to achieve more refined position management.
The Advanced Moving Average with Engulfing Pattern Quantitative Strategy is a comprehensive trading system that combines various technical analysis methods, using the collaborative effect of moving averages, engulfing patterns, and price structure breakouts to identify potential trading opportunities. The main advantage of this strategy lies in its multiple confirmation mechanism, which effectively reduces false signals and improves trading quality. At the same time, the strategy’s cooldown mechanism helps control trading frequency and avoid overtrading.
However, the strategy also has some risks, such as false breakouts, moving average lag, and market environment dependency. By perfecting Fibonacci retracement zone recognition, adding volume confirmation, dynamically adjusting parameters, and adding more comprehensive risk management mechanisms, the performance of the strategy can be further improved.
Overall, this strategy has a solid theoretical foundation and practical potential, particularly suitable for traders who tend to use multiple technical indicators for trading decisions. However, it should be noted that any trading strategy needs to be thoroughly backtested and validated before actual application and adjusted according to individual risk tolerance and market conditions.
/*backtest
start: 2024-07-28 00:00:00
end: 2025-07-26 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © IamKRfx
//@version=6
//@version=6
strategy("Refined MA + Engulfing (M5 + Confirmed Structure Break)", overlay=true, default_qty_type=strategy.fixed, default_qty_value=5)
// === INPUTS ===
ma1Len = input.int(66, title="MA1 Length")
ma2Len = input.int(85, title="MA2 Length")
cooldownBars = input.int(5, title="Directional Cooldown (bars)")
// === MOVING AVERAGES ===
ma1 = ta.sma(close, ma1Len)
ma2 = ta.sma(close, ma2Len)
plot(ma1, color=color.orange, title="MA 66")
plot(ma2, color=color.blue, title="MA 85")
aboveMAs = close > ma1 and close > ma2
belowMAs = close < ma1 and close < ma2
// === ENGULFING LOGIC ===
bullEngulf = close > open and close > close[1] and open <= close[1]
bearEngulf = close < open and close < close[1] and open >= close[1]
// === SWING HIGH/LOW DETECTION ===
pivotHigh = ta.pivothigh(high, 2, 2)
pivotLow = ta.pivotlow(low, 2, 2)
var float lastSwingHigh = na
var float lastSwingLow = na
var string marketStructure = "none" // can be "bullish", "bearish", or "none"
var bool structureConfirmed = false
// Track last swing points
if not na(pivotHigh)
lastSwingHigh := pivotHigh
if not na(pivotLow)
lastSwingLow := pivotLow
// Confirm structure breaks
bullBreakConfirmed = not na(lastSwingHigh) and close > lastSwingHigh
bearBreakConfirmed = not na(lastSwingLow) and close < lastSwingLow
if bullBreakConfirmed
marketStructure := "bullish"
structureConfirmed := true
if bearBreakConfirmed
marketStructure := "bearish"
structureConfirmed := true
bullishStructure = marketStructure == "bullish" and structureConfirmed
bearishStructure = marketStructure == "bearish" and structureConfirmed
// === PLACEHOLDER FOR FIB CONFLUENCE ===
inFibLong = true
inFibShort = true
// === CONFLUENCE CHECK (2 of 4) ===
longConfluence = 0
longConfluence += bullEngulf ? 1 : 0
longConfluence += bullishStructure ? 1 : 0
longConfluence += aboveMAs ? 1 : 0
longConfluence += inFibLong ? 1 : 0
shortConfluence = 0
shortConfluence += bearEngulf ? 1 : 0
shortConfluence += bearishStructure ? 1 : 0
shortConfluence += belowMAs ? 1 : 0
shortConfluence += inFibShort ? 1 : 0
longReady = longConfluence >= 2
shortReady = shortConfluence >= 2
// === COOLDOWN TRACKING ===
var int lastLongBar = na
var int lastShortBar = na
canLong = na(lastLongBar) or (bar_index - lastLongBar >= cooldownBars)
canShort = na(lastShortBar) or (bar_index - lastShortBar >= cooldownBars)
// === FINAL ENTRY CONDITIONS ===
longCondition = longReady and canLong and bullishStructure and aboveMAs
shortCondition = shortReady and canShort and bearishStructure and belowMAs
if (longCondition)
strategy.entry("Long", strategy.long)
lastLongBar := bar_index
if (shortCondition)
strategy.entry("Short", strategy.short)
lastShortBar := bar_index