0bps

Strategy vault / Multi-timeframe

Multi Timeframe Candlestick Pattern Trading Strategy

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…

Author
ChaoZhang
Complexity
Starter · 49 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

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.

Strategy Principle

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.

Strategy Advantages

  1. Clear Signals: Identifies candlestick patterns through strict mathematical definitions, avoiding subjective judgment
  2. Strong Visualization: Uses different colors and shapes to mark various signals, making them intuitive and easy to understand
  3. Controlled Risk: Based on mature technical analysis theory with a solid theoretical foundation
  4. Timely Notifications: Integrates trading signal alerts for automatic warnings
  5. Flexible Parameters: Supports customizable signal timeframes and color schemes

Strategy Risks

  1. Lag Risk: Pattern confirmation requires waiting for candle closure, potentially missing optimal entry points
  2. False Breakout Risk: Relying solely on candlestick patterns may trigger false signals
  3. Market Environment Risk: May generate excessive trading signals in choppy markets
  4. Parameter Sensitivity: Improper doji threshold settings can affect signal quality

Strategy Optimization Directions

  1. Incorporate Volume Indicators: Validate pattern effectiveness by combining volume changes
  2. Add Trend Filters: Include trend indicators like moving averages to filter counter-trend signals
  3. Optimize Signal Confirmation: Design multiple confirmation mechanisms to improve signal reliability
  4. Enhance Risk Control: Add stop-loss and take-profit functions, optimize money management
  5. Expand Pattern Library: Include recognition of more classic candlestick patterns

Summary

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.

Source Pine Script

/*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")

Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-06. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Multi-Timeframe-Candlestick-Pattern-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open