FIR (Finite Impulse Response Filter) free

by mfejza in category Trend at 08/09/2022
Description

Indicator FIR is a symmetrically weighted filter (Finite Impulse Response Filter)

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 mFIR_htf : Indicator
    {
        [Parameter("Base Timeframe", DefaultValue = "Minute")]
        public TimeFrame prmTF1 { get; set; }
        [Parameter("Data Source (close)", DefaultValue = PriceTypes.Close)]
        public PriceTypes PriceType { get; set; }


        [Output("FIR - Finite Impulse Response Filter", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outFIR { get; set; }


        private Bars _barsTF1;
        private IndicatorDataSeries _price;
        private IndicatorDataSeries _fir;


        protected override void Initialize()
        {
            _barsTF1 = prmTF1 > Bars.TimeFrame ? MarketData.GetBars(prmTF1) : Bars;
            while (_barsTF1.OpenTimes[0] > Bars.OpenTimes[0])
                _barsTF1.LoadMoreHistory();

            _price = CreateDataSeries();
            _fir = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            if (i < 4)
            {
                _fir[i] = Bars.ClosePrices[i];
                return;
            }

            var idx = _barsTF1.OpenTimes.GetIndexByTime(Bars.OpenTimes[i]);
            if (idx != -1)
            {
                switch (PriceType)
                {
                    case PriceTypes.Open:
                        _price[i] = _barsTF1.OpenPrices[idx];
                        break;
                    case PriceTypes.Close:
                        _price[i] = _barsTF1.ClosePrices[idx];
                        break;
                    case PriceTypes.High:
                        _price[i] = _barsTF1.HighPrices[idx];
                        break;
                    case PriceTypes.Low:
                        _price[i] = _barsTF1.LowPrices[idx];
                        break;
                    case PriceTypes.Median:
                        _price[i] = _barsTF1.MedianPrices[idx];
                        break;
                    case PriceTypes.Typical:
                        _price[i] = _barsTF1.TypicalPrices[idx];
                        break;
                    case PriceTypes.Weighted:
                        _price[i] = _barsTF1.WeightedPrices[idx];
                        break;
                    default:
                        _price[i] = _barsTF1.ClosePrices[idx];
                        break;
                }

                _fir[i] = (_price[i] + 2.0 * _price[i - 1] + 2.0 * _price[i - 2] + _price[i - 3]) / 6.0;
            }

            outFIR[i] = _fir[i];
        }
    }

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


Comments

junealexis001 - September 12, 2022 @ 11:51

Awesome post i love it keep posting more!  https://painterbillingsmt.com

gemma140622 - November 08, 2022 @ 05:29

I have strong opinions on it and am interested in learning more. Would you mind expanding on your blog Quordle once you have the required knowledge if that is possible? It is quite beneficial to me.

0