ZLSMA Enhanced Chandelier Exit Strategy with Volume Spike Detection
This strategy combines the Chandelier Exit rule, the Zero-Lag Smoothed Moving Average (ZLSMA), and the Relative Volume (RVOL) spike detection to form a complete trading system. The Chandelier Exit rule dynamically…

Overview
This strategy combines the Chandelier Exit rule, the Zero-Lag Smoothed Moving Average (ZLSMA), and the Relative Volume (RVOL) spike detection to form a complete trading system. The Chandelier Exit rule dynamically adjusts the stop-loss position based on the Average True Range (ATR), allowing it to better adapt to market changes. The ZLSMA accurately captures price trends, providing direction guidance for trading. The RVOL spike detection helps the strategy avoid low-volatility consolidation markets, improving trading quality.
Strategy Principle
- Calculate ATR and determine long and short stop-loss positions based on ATR and the highest/lowest prices.
- Calculate ZLSMA as a basis for judging trend direction.
- Calculate RVOL and determine whether a volume spike occurs by comparing RVOL with a set threshold.
- Long entry: When the current close crosses above the ZLSMA and RVOL is greater than the threshold, open a long position with the stop-loss set at the recent low.
- Short entry: When the current close crosses below the ZLSMA and RVOL is greater than the threshold, open a short position with the stop-loss set at the recent high.
- Long exit: When the current close crosses below the ZLSMA, close the long position.
- Short exit: When the current close crosses above the ZLSMA, close the short position.
Strategy Advantages
- The Chandelier Exit rule dynamically adjusts the stop-loss position, reducing the risk associated with fixed stop-losses.
- The ZLSMA responds quickly to price changes, providing reliable trend judgment for trading.
- The RVOL spike detection helps the strategy avoid low-volatility consolidation markets, improving trading quality.
- The strategy logic is clear and easy to understand and implement.
Strategy Risks
- In markets with unclear trends or frequent fluctuations, this strategy may result in a high number of trades, increasing transaction costs.
- The performance of the strategy is greatly influenced by parameter settings (such as ATR period, ZLSMA period, RVOL threshold, etc.), and inappropriate parameters may lead to poor strategy performance.
- The strategy does not consider position management and risk control, which need to be incorporated when applying the strategy in practice.
Strategy Optimization Direction
- Introduce trend confirmation indicators, such as moving average systems or momentum indicators, to further improve the accuracy of trend judgment.
- Optimize the logic of RVOL spike detection, such as considering multiple consecutive RVOL spikes before trading, to further improve signal quality.
- Add profit-taking logic to the exit conditions, such as closing a position if a certain profit target is reached, to lock in profits.
- Optimize strategy parameters based on market characteristics and trading instruments to find the best parameter combination.
- Combine position management and risk control principles to improve the strategy's robustness and reliability.
Summary
The ZLSMA-Enhanced Chandelier Exit Strategy with Volume Spike Detection is a trend-following strategy that controls trading risk while capturing trend opportunities through dynamic stop-loss, trend judgment, and volume spike detection. The strategy logic is clear and easy to understand and implement, but it still needs to be optimized and improved based on specific market characteristics and trading instruments when applied in practice. By introducing more signal confirmation indicators, optimizing exit conditions, reasonably setting parameters, and implementing strict position management and risk control, this strategy has the potential to become a robust and efficient trading tool.
Source Pine Script
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Chandelier Exit Strategy with ZLSMA and Volume Spike Detection", shorttitle="CES with ZLSMA and Volume", overlay=true, process_orders_on_close=true, calc_on_every_tick=false)
// Chandelier Exit Inputs
lengthAtr = input.int(title='ATR Period', defval=1)
mult = input.float(title='ATR Multiplier', step=0.1, defval=2.0)
useClose = input.bool(title='Use Close Price for Extremums', defval=true)
// Calculate ATR
atr = mult * ta.atr(lengthAtr)
// Calculate Long and Short Stops
longStop = (useClose ? ta.highest(close, lengthAtr) : ta.highest(high, lengthAtr)) - atr
shortStop = (useClose ? ta.lowest(close, lengthAtr) : ta.lowest(low, lengthAtr)) + atr
// Update stops based on previous values
longStop := na(longStop[1]) ? longStop : close[1] > longStop[1] ? math.max(longStop, longStop[1]) : longStop
shortStop := na(shortStop[1]) ? shortStop : close[1] < shortStop[1] ? math.min(shortStop, shortStop[1]) : shortStop
// Determine Direction
var int dir = na
dir := na(dir[1]) ? (close > shortStop ? 1 : close < longStop ? -1 : na) : close > shortStop[1] ? 1 : close < longStop[1] ? -1 : dir[1]
// ZLSMA Inputs
lengthZLSMA = input.int(title="ZLSMA Length", defval=50)
offsetZLSMA = input.int(title="ZLSMA Offset", defval=0)
srcZLSMA = input.source(close, title="ZLSMA Source")
// ZLSMA Calculation
lsma = ta.linreg(srcZLSMA, lengthZLSMA, offsetZLSMA)
lsma2 = ta.linreg(lsma, lengthZLSMA, offsetZLSMA)
eq = lsma - lsma2
zlsma = lsma + eq
// Plot ZLSMA
plot(zlsma, title="ZLSMA", color=color.purple, linewidth=3)
// Swing High/Low Calculation
swingHigh = ta.highest(high, 5)
swingLow = ta.lowest(low, 5)
// Relative Volume (RVOL) Calculation
rvolLength = input.int(20, title="RVOL Length")
rvolThreshold = input.float(1.5, title="RVOL Threshold")
avgVolume = ta.sma(volume, rvolLength)
rvol = volume / avgVolume
// Define buy and sell signals based on ZLSMA and Volume Spike
buySignal = (dir == 1 and dir[1] == -1 and close > zlsma and rvol > rvolThreshold)
sellSignal = (dir == -1 and dir[1] == 1 and close < zlsma and rvol > rvolThreshold)
// Define exit conditions based on ZLSMA
exitLongSignal = (close < zlsma)
exitShortSignal = (close > zlsma)
// Strategy Entries and Exits
if (buySignal)
strategy.entry("Long", strategy.long, stop=swingLow)
if (sellSignal)
strategy.entry("Short", strategy.short, stop=swingHigh)
if (exitLongSignal)
strategy.close("Long")
if (exitShortSignal)
strategy.close("Short")
// Alerts
alertcondition(buySignal, title='Alert: CE Buy', message='Chandelier Exit Buy!')
alertcondition(sellSignal, title='Alert: CE Sell', message='Chandelier Exit Sell!')
Published by ChaoZhang on the FMZ strategy square · last modified 2024-06-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/ZLSMA-Enhanced-Chandelier-Exit-Strategy-with-Volume-Spike-Detection.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
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- Multi EMA Trend Momentum Trading Strategy with Risk Management SystemPine Script · Momentum · 1h
- Multi Indicator Trend Momentum Trading Strategy with Dynamic Risk Management SystemPine Script · Momentum · 1h
- Triple EMA and Fisher Transform Trend Momentum StrategyPine Script · Momentum · 1d
- Advanced EMA Crossover Momentum Trend Capture StrategyPine Script · Momentum · 2h
- Multi MA Trend Strength Capture with Momentum Profit Taking StrategyPine Script · Momentum · 2h