Category Oscilators  Published on 19/12/2022

Zero Lag RSI indicator

Description

Zero Lag RSI oscillator is an RSI with a minimum delay.


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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mRSIzerolag : Indicator
    {
        [Parameter("DataSeries (close)", DefaultValue = "Close")]
        public DataSeries inDataSeries { get; set; }
        [Parameter("RSI 1 Periods(8)", DefaultValue = 8)]
        public int inpPeriodsRSI1 { get; set; }
        [Parameter("RSI 2 Periods(21)", DefaultValue = 21)]
        public int inpPeriodsRSI2 { get; set; }
        [Parameter("RSI 3 Periods(34)", DefaultValue = 34)]
        public int inpPeriodsRSI3 { get; set; }
        [Parameter("RSI 4 Periods(55)", DefaultValue = 55)]
        public int inpPeriodsRSI4 { get; set; }
        [Parameter("RSI 5 Periods(89)", DefaultValue = 89)]
        public int inpPeriodsRSI5 { get; set; }
        [Parameter("RSI 1 Factor(0.05)", DefaultValue = 0.05)]
        public double inpFactor1 { get; set; }
        [Parameter("RSI 2 Factor(0.05)", DefaultValue = 0.1)]
        public double inpFactor2 { get; set; }
        [Parameter("RSI 3 Factor(0.05)", DefaultValue = 0.16)]
        public double inpFactor3 { get; set; }
        [Parameter("RSI 4 Factor(0.05)", DefaultValue = 0.26)]
        public double inpFactor4 { get; set; }
        [Parameter("RSI 5 Factor(0.05)", DefaultValue = 0.43)]
        public double inpFactor5 { get; set; }        
        [Parameter("RSI 1 SmoothPeriods(15)", DefaultValue = 15)]
        public int inpSmoothPeriod1 { get; set; }
        [Parameter("RSI 2 SmoothPeriods(6)", DefaultValue = 7)]
        public int inpSmoothPeriod2 { get; set; }

        [Output("RSI ZeroLag", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outRSIzl { get; set; }
        
        private RelativeStrengthIndex _rsi1, _rsi2, _rsi3, _rsi4, _rsi5;
        private IndicatorDataSeries _fsattrend, _slowtrend, _rsizl;
        double smoothingconst1, smoothingconst2;
        

        protected override void Initialize()
        {
            smoothingconst1 = (inpSmoothPeriod1-1.0)/inpSmoothPeriod1;
            smoothingconst2 = (inpSmoothPeriod2-1.0)/inpSmoothPeriod2;
            _rsi1 = Indicators.RelativeStrengthIndex(inDataSeries, inpPeriodsRSI1);
            _rsi2 = Indicators.RelativeStrengthIndex(inDataSeries, inpPeriodsRSI2);
            _rsi3 = Indicators.RelativeStrengthIndex(inDataSeries, inpPeriodsRSI3);
            _rsi4 = Indicators.RelativeStrengthIndex(inDataSeries, inpPeriodsRSI4);
            _rsi5 = Indicators.RelativeStrengthIndex(inDataSeries, inpPeriodsRSI5);
            _fsattrend = CreateDataSeries();
            _slowtrend = CreateDataSeries();
            _rsizl = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _fsattrend[i] = i>inpPeriodsRSI5 ? inpFactor1 * _rsi1.Result[i] + inpFactor2 * _rsi2.Result[i] + inpFactor3 * _rsi3.Result[i] + inpFactor4 * _rsi4.Result[i] + inpFactor5 * _rsi5.Result[i] : Symbol.PipSize;
            _slowtrend[i] = _fsattrend[i] / inpSmoothPeriod1 + (!double.IsNaN(_slowtrend[i-1]) ? _slowtrend[i-1] : 0) * smoothingconst1;
            _rsizl[i] = (_fsattrend[i] - _slowtrend[i]) / (inpSmoothPeriod2 * Symbol.PipSize) + (i>inpPeriodsRSI5 ? _rsizl[i-1] : 0) * smoothingconst2;
            
            outRSIzl[i] = _rsizl[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mRSIzerolag.algo
  • Rating: 5
  • Installs: 855
  • Modified: 19/12/2022 00:37
Comments
Log in to add a comment.
No comments found.