
This strategy is a dynamic trend following system that combines Exponential Moving Averages (EMA) with candlestick patterns. It identifies specific candlestick patterns (Pin Bars and Engulfing Patterns), uses fast and slow EMAs to determine market trends, and employs the ATR indicator to measure market volatility. The core concept is to identify precise entry points through candlestick patterns when the market trend is confirmed.
The strategy consists of three core components: 1. Candlestick Pattern Recognition System: Detects Pin Bars and Engulfing Patterns. Pin Bars require shadow length to be at least twice the body length, while Engulfing Patterns require the current candle to completely encompass the previous candle’s body. 2. Dynamic Trend System: Uses 8-period and 21-period EMAs to determine market trends. An uptrend is confirmed when the fast EMA is above the slow EMA; conversely for downtrends. 3. Volatility Monitoring: Uses 14-period ATR to measure market volatility and provide reference for potential stop-loss settings.
Entry conditions strictly require both trend and pattern confirmation: long entries need bullish candlestick patterns during uptrends, while short entries need bearish patterns during downtrends.
This is a well-structured trend following strategy that provides a relatively reliable trading system by combining multiple technical analysis tools. While the current version has some areas for improvement, its core logic is sound. Through implementing the suggested optimizations, this strategy has the potential to become a more comprehensive trading system. It may perform particularly well in trending markets.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-19 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Candlestick Bible: Dynamic Price Follower (Corrected)", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
//=======================
// 1. PATTERN DETECTION
//=======================
// Pin Bar Detection
bodySize = math.abs(close - open)
upperShadow = high - math.max(close, open)
lowerShadow = math.min(close, open) - low
isBullishPin = (lowerShadow >= 2 * bodySize) and (upperShadow <= bodySize / 2)
isBearishPin = (upperShadow >= 2 * bodySize) and (lowerShadow <= bodySize / 2)
// Engulfing Pattern
isBullishEngulf = (close[1] < open[1]) and (close > open) and (close > open[1]) and (open < close[1])
isBearishEngulf = (close[1] > open[1]) and (close < open) and (close < open[1]) and (open > close[1])
//=======================
// 2. DYNAMIC TREND SYSTEM
//=======================
emaFast = ta.ema(close, 8)
emaSlow = ta.ema(close, 21)
marketTrend = emaFast > emaSlow ? "bullish" : "bearish"
//=======================
// 3. PRICE MOVEMENT SYSTEM
//=======================
atr = ta.atr(14)
//=======================
// 4. STRATEGY RULES
//=======================
longCondition = (isBullishPin or isBullishEngulf) and marketTrend == "bullish" and close > emaSlow
shortCondition = (isBearishPin or isBearishEngulf) and marketTrend == "bearish" and close < emaSlow
//=======================
// 5. STRATEGY ENTRIES
//=======================
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
//=======================
// 6. VISUAL FEEDBACK
//=======================
plot(emaFast, "Fast EMA", color=color.blue)
plot(emaSlow, "Slow EMA", color=color.red)
plotshape(longCondition, "Long Signal", shape.triangleup, location.belowbar, color=color.green, size=size.small)
plotshape(shortCondition, "Short Signal", shape.triangledown, location.abovebar, color=color.red, size=size.small)