Strategy · Pine Script v5 · On the chart

Chandelier Exit & ZLSMA Strategy

by geraked

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average.

View on GitHub

GitHub stars104on the repository
Pine versionv5runs as is
Lines of code64
Settings4inputs
LicenceMIT
Last update3 years ago29 Oct 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

64 lines of Pine Script v5 from strategies/CEZLSMA.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

CEZLSMA.pine
// This is the implementation of the strategy explained in this video: https://youtu.be/2U5VTWBBK8U
// It uses the Chandelier Exit and ZLSMA indicators. It is based on the Heikin Ashi candles.
// © 2023 Geraked, Rabist
// Licensed under MIT

// Backtesting result:
//      Symbol:             EURJPY
//      Timeframe:          1 MIN
//      Range:              2023-07-02 21:05 — 2023-07-12 14:38
//      Percent Profitable: 70.24%
//      Total Trades:       457
//      Profit Factor:      5.392


//@version=5
strategy("Chandelier Exit & ZLSMA Strategy", "CEZLSMA", overlay=true)

showIndicators = input.bool(title="Show Chandelier Exit and ZLSMA Indicators", defval=false)
length = input.int(title="Chandelier Exit ATR Period", defval=1)
mult = input.int(title="Chandelier Exit ATR Multiplier", defval=2)
length2 = input.int(title="ZLSMA Period", defval=50)

atr = mult * ta.atr(length)

longStop = ta.highest(close, length) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop

shortStop = ta.lowest(close, length) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

buySignal = dir == 1 and dir[1] == -1
sellSignal = dir == -1 and dir[1] == 1

plotshape(showIndicators and buySignal ? longStop : na, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.blue, textcolor=color.white)
plotshape(showIndicators and sellSignal ? shortStop : na, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)

lsma = ta.linreg(close, length2, 0)
lsma2 = ta.linreg(lsma, length2, 0)
eq = lsma - lsma2
zlsma = lsma + eq

plot(showIndicators ? zlsma : na, color=color.white, linewidth=3)

buySignal := buySignal and close > zlsma
sellSignal := sellSignal and close < zlsma

if (ta.crossunder(close, zlsma))
    strategy.close(id="long", comment="Close longs")

if (ta.crossover(close, zlsma))
    strategy.close(id="short", comment="Close shorts")

if (buySignal)
    strategy.entry("long", strategy.long)
    strategy.exit("exit", "long", stop=longStop, comment_loss="Stop long")

if (sellSignal)
    strategy.entry("short", strategy.short)
    strategy.exit("exit", "short", stop=shortStop, comment_loss="Stop short")

Overview

Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when price crosses the opposite stop. Long entries need a bullish flip above the average; shorts need a bearish flip below it. Longs close on a cross under the average, and shorts close on a cross above it. Stops sit at the matching Chandelier level, with no take-profit order. Inputs change the ATR period, multiplier, average length, and optional plots.

Details

Published by

geraked on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands

Markets

Forex

Timeframes

M1-M5

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

backtesting-trading-strategiesexpert-advisorexpert-advisorsforex-botgerakedmetatraderpinescriptrabiststock-markettrading-algorithms

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show Chandelier Exit and ZLSMA IndicatorsboolfalseshowIndicators
Chandelier Exit ATR Periodint1length
Chandelier Exit ATR Multiplierint2mult
ZLSMA Periodint50length2
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers