First Candle Breakout - Dynamic Trailing Stop & EOD Close Strategy

ATR ADR SL TP EOD RANGE BREAKOUT Trailing Stop
Created on: 2025-04-01 11:06:47 Modified on: 2025-04-01 11:06:47
Copy: 0 Number of hits: 378
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 First Candle Breakout - Dynamic Trailing Stop & EOD Close Strategy  First Candle Breakout - Dynamic Trailing Stop & EOD Close Strategy

Overview

The First Candle Breakout - Dynamic Trailing Stop & EOD Close Strategy is an intraday trading strategy that uses the price range of the first candle after market opening as significant support and resistance levels. This strategy enters the market after price breaks above or below the first candle’s high or low points, employs a dynamic trailing stop loss mechanism based on the first candle’s price range, and forces position closure at a specific time each day to avoid overnight risk.

Strategy Principles

This strategy is based on the market observation that the price range formed by the first candle after market opening often has significant technical importance. The core logic of the strategy is as follows:

  1. Identify and record the high and low of the first candle of the day at a user-defined specific time (default is 9:15).
  2. Calculate the price range of the first candle (high minus low).
  3. When the price breaks above the first candle’s high after the first candle has formed, the strategy triggers a long signal.
  4. When the price breaks below the first candle’s low after the first candle has formed, the strategy triggers a short signal.
  5. Set a dynamic trailing stop loss after entry, with the stop distance being 1.5 times the first candle’s price range (adjustable via parameters).
  6. For long positions, as the price rises, the stop loss level also rises accordingly, maintaining a fixed stop distance from the current price.
  7. For short positions, as the price falls, the stop loss level also falls accordingly, maintaining a fixed stop distance from the current price.
  8. Force close all positions at a specific time each day (default is 15:30) to avoid overnight risk.

The strategy adopts a confirmation-based entry mechanism, meaning it only enters trades after the price has actually broken through the first candle’s high or low, rather than entering immediately when the price just touches these levels, which helps reduce the risk of false breakouts.

Strategy Advantages

  1. Clear Entry Signals: The strategy enters based on clear price breakout signals, with simple and easy-to-understand rules that are straightforward to implement and execute.
  2. Dynamic Risk Management: Employs a dynamic trailing stop loss mechanism based on market volatility, with the stop distance automatically adjusting according to the day’s first candle range, making risk management more adaptive.
  3. Avoids False Breakouts: By waiting for price to close beyond the first candle’s high or low before entering, rather than entering as soon as price touches these levels, it helps filter out some false breakout signals.
  4. Avoids Overnight Risk: Forced position closure at a fixed time each day avoids potential gap risk and uncertainties associated with holding positions overnight.
  5. Adapts to Market Volatility: The entry points and stop loss levels automatically adjust according to the day’s market volatility - wider stop distances on volatile days and narrower stop distances on calmer days - thus better adapting to different market environments.
  6. Single Trade Per Day: Only one trade per day is allowed, avoiding overtrading and reducing transaction costs.
  7. Fully Automated: The strategy can be executed completely automatically without manual intervention, suitable for traders who don’t have time to monitor the market in real-time.

Strategy Risks

Despite its numerous advantages, the strategy still has some potential risks:

  1. False Breakout Risk: Although the strategy waits for price to close beyond breakout levels before entering, it may still encounter false breakouts where price breaks through but quickly retraces, triggering the stop loss. A solution is to consider adding additional confirmation indicators such as volume confirmation or trend confirmation.
  2. Excessively Wide Stop Loss: On highly volatile days, the first candle’s range may be wide, resulting in a large stop distance and potentially significant losses per trade. A solution is to set an absolute upper limit for the maximum stop distance.
  3. Excessively Narrow Stop Loss: Conversely, on days with low volatility, the first candle’s range may be very narrow, resulting in a small stop distance that can easily be triggered by market noise. A solution is to set an absolute lower limit for the minimum stop distance.
  4. Missing Major Trends: Since the strategy only allows one trade per day and forces position closure at a fixed time, it may miss continuing major market moves. A solution is to consider allowing overnight position holding under specific conditions.
  5. Time Dependency: The strategy has strict requirements for the timing of the first candle formation and forced position closure, making it highly time-dependent. Different markets or time zones may require parameter adjustments. The solution is to adjust parameters according to specific market trading hours.
  6. No Profit Target: The strategy does not set a clear profit target and relies entirely on trailing stops or end-of-day closures to end trades, which may not capitalize at optimal positions. A solution is to consider adding profit-taking mechanisms based on support/resistance levels or technical indicators.
  7. Parameter Sensitivity: The strategy’s performance may be very sensitive to parameter settings (such as start time, end time, trailing stop multiplier, etc.), requiring thorough backtesting and optimization.

Strategy Optimization Directions

Addressing the above risks, the strategy can be optimized in the following directions:

  1. Add Filtering Conditions: Combine market trend indicators or volume indicators, entering only when the trend direction is consistent or volume confirms, to reduce the risk of false breakouts. For example, adding moving averages as trend filters, or requiring significant volume increase during breakouts.
  2. Optimize Stop Loss Mechanism: Set absolute upper and lower limits for stop distances to maintain reasonable risk levels even on extremely volatile days. Consider incorporating the ATR (Average True Range) indicator to set more dynamic stop distances.
  3. Introduce Partial Profit-Taking: Consider partial position closure when price reaches certain targets (such as 2x or 3x the first candle’s range), with remaining positions continuing to be managed by trailing stops.
  4. Add Overnight Holding Conditions: Allow partial or complete position holding overnight under specific conditions (such as strong trends or price far from entry point) to capture major trend movements.
  5. Add Time Filters: Avoid trading during periods of low market volatility or high uncertainty, such as avoiding entries before and after important economic data releases.
  6. Optimize Parameter Adaptation: Enable the strategy to automatically adjust parameters based on recent market conditions, such as adjusting the trailing stop multiplier based on the average volatility of recent days.
  7. Incorporate Market Environment Recognition: Apply different trading parameters or even different trading logic in different market environments (such as ranging markets, trending markets) to improve strategy adaptability.
  8. Consider Multi-Timeframe Analysis: Combine larger timeframe market structures, trading only when aligned with the main trend direction to avoid counter-trend trading.
  9. Add Money Management Module: Dynamically adjust position sizes based on market volatility and historical performance, reducing positions during periods of high uncertainty and increasing positions during periods of good strategy performance.

Summary

The First Candle Breakout - Dynamic Trailing Stop & EOD Close Strategy is an intraday trading strategy based on the price range of the first candle after market opening. It enters trades based on confirmed price breakout signals, employs a dynamic trailing stop loss mechanism based on market volatility to manage risk, and forces position closure at a fixed time each day to avoid overnight risk.

The strategy’s advantages include clear entry signals, dynamic risk management, avoidance of false breakouts and overnight risks, adaptation to market volatility, limited overtrading, and fully automated execution. However, it also faces challenges such as false breakout risks, potentially unreasonable stop distances, missing major market moves, strong time dependency, lack of profit targets, and parameter sensitivity.

Through adding filtering conditions, optimizing stop loss mechanisms, introducing partial profit-taking, adding overnight holding conditions, incorporating time filters, optimizing parameter adaptation, integrating market environment recognition, considering multi-timeframe analysis, and adding money management modules, the strategy’s stability and profitability can be further enhanced.

Overall, this is a clearly structured and logically sound intraday trading strategy, suitable for traders who wish to conduct intraday trading through automated systems with strict risk control. With targeted optimization and appropriate parameter adjustments, this strategy has the potential to achieve stable performance across different market environments.

Strategy source code
/*backtest
start: 2025-03-24 00:00:00
end: 2025-03-31 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"TRX_USDT"}]
*/

//@version=5
strategy("First Candle Breakout - Trailing Stop & EOD Close", overlay=true)

// User Inputs
startHour = input(9, "Start Hour (Exchange Time)")
startMinute = input(15, "Start Minute (Exchange Time)")
endHour = input(15, "End Hour (Exchange Time)")  // Market closing hour
endMinute = input(30, "End Minute (Exchange Time)")
trailStopMultiplier = input(1.5, "Trailing Stop Multiplier")  // 1.5x first candle range

// Variables to store the first candle's high & low
var float firstCandleHigh = na
var float firstCandleLow = na
var bool tradeTaken = false  // Ensures only one trade per day
var int tradeDirection = 0   // 1 for long, -1 for short
var float trailStopLevel = na  // Trailing stop level

// Identify first candle's high & low
if (hour == startHour and minute == startMinute and bar_index > 1)
    firstCandleHigh := high
    firstCandleLow := low
    tradeTaken := false  // Reset trade flag at start of day
    tradeDirection := 0   // Reset trade direction
    trailStopLevel := na  // Reset trailing stop

// Calculate first candle range
firstCandleRange = firstCandleHigh - firstCandleLow
trailStopDistance = firstCandleRange * trailStopMultiplier

// Buy condition: Close above first candle high AFTER the first candle closes
longCondition = not na(firstCandleHigh) and close > firstCandleHigh and not tradeTaken and hour > startHour
if (longCondition)
    strategy.entry("Buy", strategy.long, comment="Buy")
    trailStopLevel := close - trailStopDistance  // Set initial trailing stop
    tradeTaken := true
    tradeDirection := 1

// Sell condition: Close below first candle low AFTER the first candle closes
shortCondition = not na(firstCandleLow) and close < firstCandleLow and not tradeTaken and hour > startHour
if (shortCondition)
    strategy.entry("Sell", strategy.short, comment="Sell")
    trailStopLevel := close + trailStopDistance  // Set initial trailing stop
    tradeTaken := true
    tradeDirection := -1

// Update trailing stop for long trades
if (tradeDirection == 1 and not na(trailStopLevel))
    trailStopLevel := nz(trailStopLevel, close - trailStopDistance)  // Initialize if na
    trailStopLevel := math.max(trailStopLevel, close - trailStopDistance)  // Adjust trailing stop up
    if (close <= trailStopLevel)  // Stop loss hit
        strategy.close("Buy", comment="Trailing SL Hit")

// Update trailing stop for short trades
if (tradeDirection == -1 and not na(trailStopLevel))
    trailStopLevel := nz(trailStopLevel, close + trailStopDistance)  // Initialize if na
    trailStopLevel := math.min(trailStopLevel, close + trailStopDistance)  // Adjust trailing stop down
    if (close >= trailStopLevel)  // Stop loss hit
        strategy.close("Sell", comment="Trailing SL Hit")

// Close trade at end of day if still open
if (tradeTaken and hour == endHour and minute == endMinute)
    strategy.close_all(comment="EOD Close")