Zero-Lag LSMA with Chandelier Exit Trend Following Strategy

ZLSMA CE 趋势跟踪 波动率跟踪止损 方向确认 移动平均线 ATR
Created on: 2025-04-30 11:13:38 Modified on: 2025-07-10 17:00:53
Copy: 9 Number of hits: 674
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Zero-Lag LSMA with Chandelier Exit Trend Following Strategy  Zero-Lag LSMA with Chandelier Exit Trend Following Strategy

Overview

The Zero-Lag LSMA with Chandelier Exit Trend Following Strategy is a quantitative trading system that combines the Zero-Lag Linear Regression Moving Average (ZLSMA) and the Chandelier Exit (CE) indicator. This strategy determines entry points based on the relative position of price to ZLSMA and direction changes in the CE indicator, making it a typical trend-following strategy. The strategy performs best on a 15-minute timeframe, achieving a good balance between signal speed and trend filtering. Through accurate capture of price trends and precise monitoring of volatility, this strategy can achieve favorable returns when market trends are clear.

Strategy Principles

The core principles of this strategy are based on the synergistic effect of two main indicators:

  1. Zero-Lag Linear Regression Moving Average (ZLSMA):

    • ZLSMA is an improved version of the traditional Linear Regression Moving Average (LSMA), eliminating lag through double linear regression calculation, allowing it to react more quickly to price changes.
    • Calculation method: First calculate the linear regression value of the price (LSMA), then calculate the linear regression value of the LSMA (LSMA2), and finally add LSMA and (LSMA-LSMA2) to get ZLSMA.
    • The code includes adjustable parameters, including length (default 200 periods), offset, and data source (default is closing price).
  2. Chandelier Exit (CE):

    • CE is a volatility-based trailing stop indicator that uses ATR (Average True Range) to set dynamic stop-loss levels.
    • Long stop-loss calculation: Highest price minus ATR multiplied by a factor (default is 2.0).
    • Short stop-loss calculation: Lowest price plus ATR multiplied by the factor.
    • Stop-loss levels adjust dynamically according to price changes, creating a trailing stop effect.
    • When the price breaks through the stop-loss level, the indicator direction changes, generating a trading signal.

The trading logic of the strategy is as follows: - Long entry condition: CE direction changes from short to long (buySignal_ce) and price is above ZLSMA - Short entry condition: CE direction changes from long to short (sellSignal_ce) and price is below ZLSMA - The strategy closes any reverse position before opening a new position, ensuring clean position direction switching

This strategy essentially combines trend confirmation (ZLSMA) with volatility-based trailing stops (CE), only triggering trading signals when both conditions are met, effectively reducing false signals.

Strategy Advantages

Through in-depth code analysis, this strategy has the following distinct advantages:

  1. Dual confirmation mechanism: The strategy requires both the CE direction signal and the price position relative to ZLSMA to meet conditions simultaneously, greatly improving signal reliability.

  2. Strong adaptability:

    • ZLSMA has low lag, allowing it to quickly react to price changes.
    • CE calculates based on ATR, automatically adjusting stop-loss positions according to market volatility, maintaining adaptability in different volatility environments.
  3. Balance between trend following and risk control:

    • ZLSMA helps confirm medium to long-term trend direction.
    • CE provides a volatility-adaptive exit mechanism, effectively controlling drawdowns.
  4. Parameter adjustability: The strategy provides multiple adjustable parameters, including ZLSMA length, CE’s ATR period and multiplier, which can be optimized according to different market environments and trading instruments.

  5. Clean direction switching: The strategy closes reverse positions before entering a new direction, avoiding situations of simultaneously holding both long and short positions, clarifying trading direction.

  6. Volatility-based risk management: Using ATR as a volatility measurement standard ensures stop-loss positions match actual market volatility, avoiding problems of fixed stops being either too tight or too loose.

Strategy Risks

Despite the reasonable design of this strategy, there are still the following potential risks:

  1. Poor performance in range-bound markets:

    • As a trend-following strategy, it may produce frequent false signals when there is no clear market trend.
    • Sideways consolidating markets may lead to frequent entries and exits, resulting in excessive trading costs.
  2. Parameter sensitivity:

    • The ZLSMA length (default 200) is relatively large, which may lead to signal lag.
    • Improper setting of the CE’s ATR multiplier may cause stops to be too loose (missing timely exits) or too tight (frequent shakeouts).
  3. Lack of initial stop-loss mechanism: The strategy mainly relies on CE as a dynamic stop-loss, but lacks a clear initial stop-loss setting, potentially suffering significant losses during sudden severe market volatility.

  4. Single timeframe limitation: The strategy is optimized only for the 15-minute timeframe, lacking multi-timeframe confirmation, potentially missing important trend information from larger timeframes.

  5. Balance between trading frequency and costs: CE indicator direction changes may be relatively frequent, especially when the ATR period is set small (default is 1), potentially leading to overtrading.

To address these risks, the following solutions are recommended: - Pause strategy operation in obvious range-bound markets - Dynamically adjust parameters according to different market environments - Add initial fixed stops as additional protection - Introduce multi-timeframe confirmation mechanisms - Set minimum holding time or signal filters to reduce overtrading

Strategy Optimization Directions

Based on code analysis, this strategy has several potential optimization directions:

  1. Multi-timeframe confirmation:

    • Introduce higher timeframe trend confirmation, such as 1-hour or 4-hour ZLSMA direction, only trading when high and low timeframe trends align.
    • This can reduce the possibility of counter-trend operations, improving win rate.
  2. Signal filter enhancement:

    • Add additional filtering conditions, such as volume confirmation, momentum indicators, or important support/resistance level judgment.
    • Consider adding indicators like RSI or MACD, only opening positions in non-overbought/oversold areas.
    • This will help reduce false signals and improve signal quality.
  3. Dynamic parameter optimization:

    • Dynamically adjust ZLSMA length and CE’s ATR multiplier based on market volatility state.
    • High volatility markets can use larger ATR multipliers to avoid frequent exits, while low volatility markets do the opposite.
    • Consider using volatility indicators such as VIX or ATR rate of change to automatically adjust parameters.
  4. Stop-loss strategy improvement:

    • Add fixed initial stops as a first line of defense.
    • Implement partial profit locking mechanisms, such as moving a portion of the position to a risk-free state.
    • Consider intelligent stop-loss settings based on support and resistance levels.
  5. Position management optimization:

    • The current strategy uses a fixed proportion position (100% equity), which could be changed to dynamic position management based on volatility or win rate.
    • Introduce pyramid scaling or partial reduction mechanisms, adding to positions when trends strengthen and reducing when they weaken.
    • This will help maximize profitable trends and minimize drawdowns.
  6. Signal confirmation time:

    • The current strategy confirms signals at candle close, consider requiring signals to persist for several periods before execution, reducing noise impact.
    • Or use price action patterns (such as breakout confirmation, reversal patterns) as additional confirmation.

Conclusion

The Zero-Lag LSMA with Chandelier Exit Trend Following Strategy is a complete trading system combining technical analysis and risk management. By combining the low-lag ZLSMA and the volatility-based CE indicator, this strategy can effectively capture market trends and provide dynamic risk control mechanisms. The strategy’s dual confirmation mechanism greatly improves signal reliability, while its adaptive features allow it to maintain stable performance across different market environments.

Although the strategy may perform poorly in range-bound markets, its performance can be further enhanced through measures such as introducing multi-timeframe confirmation, enhancing signal filters, optimizing parameters, and improving stop-loss strategies. In particular, the introduction of dynamic position management and intelligent stop-loss settings will help maintain a high win rate while controlling risk.

Overall, this is a well-designed, logically clear trend-following strategy that embodies both classic technical analysis concepts and modern quantitative trading risk management ideas. Through continuous optimization and appropriate parameter adjustments, this strategy has the potential to achieve stable performance across various market environments.

Strategy source code
/*backtest
start: 2024-04-30 00:00:00
end: 2025-04-28 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script® strategy uses the Zero-Lag LSMA (ZLSMA) and a Chandelier Exit (CE) mechanism.
// It enters long or short trades based on CE direction signals, confirmed by the position of price relative to ZLSMA.
// Long trades only trigger if price is above ZLSMA; short trades only if price is below it.

// @version=6
//@version=6
strategy("ZLSMACE Strategy", overlay=true)


// ───── ZLSMA Settings ─────
var string calcGroup_zlsma = 'Calculation of ZLSMA'
length_zlsma = input.int(200, title="Length of ZLSMA", group=calcGroup_zlsma)
offset_zlsma = input.int(0, title="Offset of ZLSMA", group=calcGroup_zlsma)
src_zlsma = input.source(close, title="Source of ZLSMA", group=calcGroup_zlsma)

// ZLSMA Calculation
lsma_zlsma = ta.linreg(src_zlsma, length_zlsma, offset_zlsma)
lsma2_zlsma = ta.linreg(lsma_zlsma, length_zlsma, offset_zlsma)
eq_zlsma = lsma_zlsma - lsma2_zlsma
zlsma_value = lsma_zlsma + eq_zlsma

// ───── Chandelier Exit (CE) Settings ─────
var string calcGroup_ce = 'Calculation of CE'
length_ce = input.int(title='ATR Period of CE', defval=14, group=calcGroup_ce)
mult_ce = input.float(title='ATR Multiplier of CE', step=0.1, defval=2.0, group=calcGroup_ce)
useClose_ce = input.bool(title='Use Close Price for Extremums', defval=true, group=calcGroup_ce)

// CE Stop Level Calculations
atr_ce = mult_ce * ta.atr(length_ce)

longStop_ce = (useClose_ce ? ta.highest(close, length_ce) : ta.highest(length_ce)) - atr_ce
longStopPrev_ce = nz(longStop_ce[1], longStop_ce)
longStop_ce := close[1] > longStopPrev_ce ? math.max(longStop_ce, longStopPrev_ce) : longStop_ce

shortStop_ce = (useClose_ce ? ta.lowest(close, length_ce) : ta.lowest(length_ce)) + atr_ce
shortStopPrev_ce = nz(shortStop_ce[1], shortStop_ce)
shortStop_ce := close[1] < shortStopPrev_ce ? math.min(shortStop_ce, shortStopPrev_ce) : shortStop_ce

// CE Direction Detection
var int dir_ce = 1
dir_ce := close > shortStopPrev_ce ? 1 : close < longStopPrev_ce ? -1 : dir_ce

// Entry Signals
buySignal_ce = dir_ce == 1 and dir_ce[1] == -1
sellSignal_ce = dir_ce == -1 and dir_ce[1] == 1

// ───── Strategy Execution ─────
// Long Entry: Direction turns long AND price is above ZLSMA
if (buySignal_ce and close > zlsma_value)
    strategy.entry("Long", strategy.long)

// Exit Short if long signal appears
if (buySignal_ce)
    strategy.close("Short")

// Short Entry: Direction turns short AND price is below ZLSMA
if (sellSignal_ce and close < zlsma_value)
    strategy.entry("Short", strategy.short)

// Exit Long if short signal appears
if (sellSignal_ce)
    strategy.close("Long")