Category Oscilators  Published on 03/10/2023

RSI of FIR SpectralForecast

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

The Spectral Forecast calculation is a method used to compare two states of data arrays in order to define a forecast based on the input data.

In this custom indicator, the output is displayed as an RSI indicator for easy comparison of the calculated data. The input data used includes the 'Close Price' and 'Spectral Forecast' derived from FIR and the 'Close Price'.

For trading purposes, consider going Long if both RSI output values are above the 50 level, and go Short if both RSI output values are below the 50 level.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(30,50,70)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mRSIFIRSpectralForecast : Indicator
    {
        [Parameter("Forecast Lookback (10)", DefaultValue = 10)]
        public int inpLookback { get; set; }
        [Parameter("Period RSI (10)", DefaultValue = 10)]
        public int inpPeriodRSI { get; set; }

        [Output("RSI FIR Spectral Forecast", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outRSIFIRSpectralForecast { get; set; }
        [Output("RSI Close", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outRSIClose { get; set; }
        
        private IndicatorDataSeries _price, _fir, _maxraw, _maxsmooth, _max, _spectralforecast;
        private RelativeStrengthIndex _rsifirsf, _rsi;
        private double _con;

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _fir = CreateDataSeries();
            _maxraw = CreateDataSeries();
            _maxsmooth = CreateDataSeries();
            _max = CreateDataSeries();
            _spectralforecast = CreateDataSeries();
            _con = 33;
            _rsifirsf = Indicators.RelativeStrengthIndex(_spectralforecast, inpPeriodRSI);
            _rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, inpPeriodRSI);
        }

        public override void Calculate(int i)
        {
            _price[i] = Bars.ClosePrices[i];
            _fir[i] = i>3 ? (_price[i] + 2.0 * _price[i-1] + 2.0 * _price[i-2] + _price[i-3]) / 6.0 : Bars.ClosePrices[i];
            _maxraw[i] = i>inpLookback ? _price.Maximum(inpLookback) : _price[i];
            _maxsmooth[i] = i>inpLookback ? _fir.Maximum(inpLookback) : _fir[i];
            _max[i] = Math.Max(_maxraw[i], _maxsmooth[i]);
            _spectralforecast[i] = ((_con / _maxraw[i]) * _price[i]) + (((_max[i] - _con) / _fir[i]) * _fir[i]);
            
            outRSIFIRSpectralForecast[i] = _rsifirsf.Result[i];
            outRSIClose[i] = _rsi.Result[i];
        }
    }
}



mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mRSIFIRSpectralForecast.algo
  • Rating: 5
  • Installs: 532
  • Modified: 03/10/2023 18:13
Comments
Log in to add a comment.
No comments found.