Improved Swing High Low Breakout Strategy with Bullish and Bearish Engulfing Patterns
This strategy is an improved variation of a swing high/low breakout strategy that aims to capitalize on potential trend reversals signaled by bullish and bearish engulfing candlestick patterns. The strategy…

Overview
This strategy is an improved variation of a swing high/low breakout strategy that aims to capitalize on potential trend reversals signaled by bullish and bearish engulfing candlestick patterns. The strategy identifies swing highs and lows and generates trading signals when prices break through these key levels. Additionally, the strategy employs a predefined risk-reward ratio to set take-profit and stop-loss levels for better risk management.
Strategy Principles
- Calculating swing highs and lows: By comparing the current high and low with the highs and lows of the previous two periods, the strategy determines whether a new swing high or low has formed.
- Identifying bullish and bearish engulfing patterns: A bullish engulfing pattern is recognized when the closing price is higher than the previous period's opening price, and the current candle is a bullish candle, while the previous period is a bearish candle. Conversely, a bearish engulfing pattern is identified when the closing price is lower than the previous period's opening price, and the current candle is a bearish candle, while the previous period is a bullish candle.
- Generating trading signals: When a bullish engulfing pattern occurs, and the price breaks above the swing high, a long signal is generated. When a bearish engulfing pattern occurs, and the price breaks below the swing low, a short signal is generated.
- Setting take-profit and stop-loss: The take-profit and stop-loss levels are calculated based on the predefined risk-reward ratio and are set when executing trades.
Advantage Analysis
- Combining price action and candlestick patterns: The strategy not only considers price breakouts at key levels but also incorporates bullish and bearish engulfing patterns, enhancing the reliability of trading signals.
- Risk management: By setting take-profit and stop-loss levels based on a predefined risk-reward ratio, the strategy helps control the risk exposure of individual trades and improves overall risk management.
- Adaptability to different market conditions: The strategy considers both long and short directions, allowing it to find trading opportunities in various market trends.
Risk Analysis
- False signal risk: In some cases, price breakouts and candlestick patterns may generate false signals, leading to trades in the wrong direction. This risk can be mitigated by adding additional confirmation indicators or filtering conditions.
- Market volatility risk: In highly volatile markets, prices may quickly break through key levels and trigger stop-losses, leading to consecutive losses. Adjusting stop-loss levels or employing dynamic stop-loss strategies can help address this risk.
- Trading frequency and costs: Frequent trading may increase transaction costs, affecting the overall performance of the strategy. Optimizing entry conditions or appropriately adjusting parameters can help control trading frequency.
Optimization Directions
- Introducing trend confirmation indicators: Combining moving averages or other trend indicators to validate the effectiveness of price breakouts can improve the quality of trading signals.
- Dynamic stop-loss adjustment: Dynamically adjusting stop-loss levels based on market volatility or price changes can help better adapt to different market conditions.
- Parameter optimization: By backtesting and optimizing different parameter combinations, the optimal parameter settings can be found to improve the stability and profitability of the strategy.
Summary
The improved swing high/low breakout strategy with bullish and bearish engulfing patterns combines price breakouts and candlestick patterns to capture potential trend reversal opportunities while emphasizing risk management. The strategy's advantages lie in its consideration of both price action and market sentiment, adapting to different market environments. However, the strategy also faces risks such as false signals, market volatility, and trading costs, which need to be addressed through the introduction of trend confirmation indicators, dynamic stop-loss adjustment, and parameter optimization. Overall, this strategy provides an approach to capturing potential trend reversal opportunities, but it requires appropriate adjustments and optimizations based on specific market characteristics and trading requirements when applied in practice.
Source Pine Script
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Markoline007
//@version=5
strategy("Improved Swing High/Low Breakout Strategy", overlay=true)
// Define input variables
length = input(14, title="Swing Length")
multiplier = input(3, title="Multiplier")
risk_reward_ratio = input(1.6, title="Risk-Reward Ratio")
target_multiplier = input(2, title="Target Multiplier")
// Calculate swing highs and swing lows
var float lastHigh = na
var float lastLow = na
var bool isHigh = na
var bool isLow = na
if high[1] < high and high[2] < high[1]
lastHigh := high[1]
isHigh := true
isLow := false
else if low[1] > low and low[2] > low[1]
lastLow := low[1]
isLow := true
isHigh := false
else
isHigh := false
isLow := false
// Define buy and sell conditions
buySignal = close > lastHigh and close > open and close[1] < open[1] // Bullish engulfing
sellSignal = close < lastLow and close < open and close[1] > open[1] // Bearish engulfing
// Calculate stop and target levels
stopLevel = close
targetLevel = close + (close - stopLevel) * risk_reward_ratio
// Execute buy and sell trades
if buySignal
strategy.entry("Buy", strategy.long)
strategy.exit("TP/SL", "Buy", profit=targetLevel, loss=stopLevel)
if sellSignal
strategy.entry("Sell", strategy.short)
strategy.exit("TP/SL", "Sell", profit=targetLevel, loss=stopLevel)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-17. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Improved-Swing-High-Low-Breakout-Strategy-with-Bullish-and-Bearish-Engulfing-Patterns.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Channel Breakout StrategyPine Script · Breakout · 1d
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h