Chandelier Exit free

by cW22Trader in category Trend at 06/08/2021
Description

This is a volatility-based indicator which identifies stop loss exit points.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChandelierExit : Indicator
    {
        [Parameter(DefaultValue = 22)]
        public int Period { get; set; }

        [Parameter(DefaultValue = 3)]
        public double AtrMultiplier { get; set; }

        [Output("Exit", PlotType = PlotType.Line, LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries Exit { get; set; }


        private AverageTrueRange _atr;
        private IndicatorDataSeries _longExit, _shortExit;
        private int _direction;

        protected override void Initialize()
        {
            _atr = Indicators.AverageTrueRange(Period, MovingAverageType.Exponential);

            _longExit = CreateDataSeries();
            _shortExit = CreateDataSeries();

            _direction = 0;
        }

        public override void Calculate(int index)
        {
            var adjustedAtr = _atr.Result[index] * AtrMultiplier;
            var longExit = Bars.HighPrices.Maximum(Period) - adjustedAtr;
            var shortExit = Bars.LowPrices.Minimum(Period) + adjustedAtr;
            var close = Bars.ClosePrices[index];
            var closePrev = Bars.ClosePrices[index - 1];

            _longExit[index] = double.IsNaN(_longExit[index - 1]) ? longExit : close < _longExit[index - 1] ? longExit : Math.Max(longExit, _longExit[index - 1]);
            _shortExit[index] = double.IsNaN(_shortExit[index - 1]) ? shortExit : close > _shortExit[index - 1] ? shortExit : Math.Min(shortExit, _shortExit[index - 1]);


            var shortSwitch = (close <= _longExit[index - 1] && closePrev > _longExit[index - 1]);
            var longSwtich = (close >= _shortExit[index - 1] && closePrev < _shortExit[index - 1]);

            _direction = _direction <= 0 && longSwtich ? 1 : _direction >= 0 && shortSwitch ? -1 : _direction;

            Exit[index] = _direction > 0 ? _longExit[index] : _shortExit[index];
        }
    }
}
Comments

kenneyy_eur - August 16, 2021 @ 00:15

Quite good!!! - i altered the code to create a stop loss channel and explicitly reference the channel top or bottom depending on my trade direction. 

5