
This is a multi-timeframe trading strategy based on candlestick pattern analysis, which generates trading signals by identifying bullish engulfing, bearish engulfing, and doji patterns. The strategy operates on daily timeframes, combining multiple technical indicators and pattern characteristics to identify market trend reversal points and optimal entry timing.
The core logic of the strategy is to programmatically identify three classic candlestick patterns: 1. Bullish Engulfing: Previous candle is bearish, current candle is bullish and completely engulfs the previous candle 2. Bearish Engulfing: Previous candle is bullish, current candle is bearish and completely engulfs the previous candle 3. Doji Pattern: The difference between open and close prices is less than 10% of the current candle’s body height
Buy signals are displayed below the candle when bullish engulfing patterns are identified; sell signals are displayed above the candle for bearish engulfing patterns; and doji patterns are marked at the candle top. The strategy implements signal annotation through the label.new() function and enhances signal visualization using the plotshape() function.
The strategy implements classic candlestick pattern analysis programmatically, offering good operability and extensibility. Through appropriate parameter settings and risk control, it can provide valuable reference for trading decisions. Future improvements can focus on adding more technical indicators and optimizing signal confirmation mechanisms to enhance strategy stability and reliability.
/*backtest
start: 2024-01-06 00:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Sensex Option Buy/Sell Signals", overlay=true)
// Input parameters
bullishColor = color.new(color.green, 0)
bearishColor = color.new(color.red, 0)
dojiColor = color.new(color.yellow, 0)
// Candlestick pattern identification
isBullishEngulfing = close[1] < open[1] and close > open and close > high[1] and open < low[1]
isBearishEngulfing = close[1] > open[1] and close < open and close < low[1] and open > high[1]
isDoji = math.abs(close - open) <= (high - low) * 0.1
// Plot buy/sell signals
buySignal = isBullishEngulfing
sellSignal = isBearishEngulfing
timeframeCondition = input.timeframe("D", title="Timeframe for signals")
// Buy Signal
if buySignal
label.new(bar_index, high, "Buy", style=label.style_label_up, color=bullishColor, textcolor=color.white)
strategy.entry("Buy", strategy.long)
// Sell Signal
if sellSignal
label.new(bar_index, low, "Sell", style=label.style_label_down, color=bearishColor, textcolor=color.white)
strategy.entry("Sell", strategy.short)
// Highlight Doji candles
if isDoji
label.new(bar_index, high, "Doji", style=label.style_circle, color=dojiColor, textcolor=color.black)
// Alerts
alertcondition(buySignal, title="Buy Alert", message="Bullish Engulfing Pattern Detected")
alertcondition(sellSignal, title="Sell Alert", message="Bearish Engulfing Pattern Detected")
// Add plot shapes for visibility
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=bullishColor, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=bearishColor, style=shape.labeldown, text="SELL")