Ehlers Super Smooth Indicator free

by mfejza in category Trend at 11/10/2022
Description

Ehlers Super Smooth Indicator

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;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mSuperSmooth : Indicator
    {
        [Parameter("Data Source (close)", DefaultValue = PriceTypes.Close)]
        public PriceTypes PriceType { get; set; }
        [Parameter("Low Pass Period (10)", DefaultValue = 10)]
        public int PeriodLowPass { get; set; }

        [Output("Ehlers Super Smoother Code Filter", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSSCF { get; set; }

        private IndicatorDataSeries _price;
        private IndicatorDataSeries _sscf;
        private double a1, b1, c1, c2, c3, pi;

        protected override void Initialize()
        {
            pi = 3.14159265358979;
            a1 = Math.Exp(-1.0 * Math.Sqrt(2.0) * pi / (double)PeriodLowPass);
            b1 = 2.0 * a1 * Math.Cos(Math.Sqrt(2.0) * pi / (double)PeriodLowPass);
            c2 = b1;
            c3 = -a1 * a1;
            c1 = 1.0 - c2 - c3;
            _sscf = CreateDataSeries();
            _price = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
                switch (PriceType)
                {
                    case PriceTypes.Open:
                        _price[i] = Bars.OpenPrices[i];
                        break;
                    case PriceTypes.Close:
                        _price[i] = Bars.ClosePrices[i];
                        break;
                    case PriceTypes.High:
                        _price[i] = Bars.HighPrices[i];
                        break;
                    case PriceTypes.Low:
                        _price[i] = Bars.LowPrices[i];
                        break;
                    case PriceTypes.Median:
                        _price[i] = Bars.MedianPrices[i];
                        break;
                    case PriceTypes.Typical:
                        _price[i] = Bars.TypicalPrices[i];
                        break;
                    case PriceTypes.Weighted:
                        _price[i] = Bars.WeightedPrices[i];
                        break;
                    default:
                        _price[i] = Bars.ClosePrices[i];
                        break;
                }

                if (i < 3)
                    _sscf[i] = c1 * _price[i];
                else
                    _sscf[i] = c1 * (_price[i] + _price[i - 1]) / 2.0 + c2 * _sscf[i - 1] + c3 * _sscf[i - 2];

                outSSCF[i] = _sscf[i];
        }
    }


    public enum PriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
Comments
0