Category Trend  Published on 11/10/2022

Ehlers Super Smooth Indicator

Description

Ehlers Super Smooth Indicator



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
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mSuperSmooth.algo
  • Rating: 5
  • Installs: 851
  • Modified: 10/10/2022 21:39
Comments
Log in to add a comment.
No comments found.