Category Trend  Published on 21/03/2023

RSI CrossSignal indicator

Description

RSI CrossSignal indicator


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class mRSIcrosssignal : Indicator
    {
        [Parameter("RSI Fast Periods (5)", DefaultValue = 5)]
        public int inpPeriodsFastRSI { get; set; }
        [Parameter("RSI Slow Periods (34)", DefaultValue = 34)]
        public int inpPeriodsSlowRSI { get; set; }
        [Parameter("Smooth Periods (10)", DefaultValue = 10)]
        public int inpPeriodsSmooth { get; set; }

        [Output("CrossSignal OpenLong trigger", LineColor = "Green", PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries outLongOpen { get; set; }
        [Output("CrossSignal OpenShort trigger", LineColor = "Red", PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries outShortOpen { get; set; }
        [Output("CrossSignal dd trigger", LineColor = "Black", PlotType = PlotType.Line, Thickness = 2)]
        public IndicatorDataSeries outTest { get; set; }
        
        private RelativeStrengthIndex _rsifast, _rsislow;
        private IndicatorDataSeries _longtrigger, _shorttrigger;
                

        protected override void Initialize()
        {
            _rsifast = Indicators.RelativeStrengthIndex(Bars.ClosePrices, inpPeriodsFastRSI);
            _rsislow = Indicators.RelativeStrengthIndex(Bars.ClosePrices, inpPeriodsSlowRSI);
            _longtrigger = CreateDataSeries();
            _shorttrigger = CreateDataSeries();
        }

        public override void Calculate(int i)
        {            
            _longtrigger[i] = _shorttrigger[i] = double.NaN;
            if(_rsifast.Result[i-1] > _rsislow.Result[i-1] && _rsifast.Result[i-2] < _rsislow.Result[i-2] && _rsifast.Result[i] > _rsislow.Result[i])
                _longtrigger[i] = Bars.LowPrices[i];
            if(_rsifast.Result[i-1] < _rsislow.Result[i-1] && _rsifast.Result[i-2] > _rsislow.Result[i-2] && _rsifast.Result[i] < _rsislow.Result[i])
                _shorttrigger[i] = Bars.HighPrices[i];

            outLongOpen[i] = _longtrigger[i];
            outShortOpen[i] = _shorttrigger[i];
        }
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mRSIcrosssignal.algo
  • Rating: 5
  • Installs: 966
  • Modified: 21/03/2023 19:42
Comments
Log in to add a comment.
No comments found.