Category Oscilators  Published on 08/09/2023

RSI Stochastique

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

Stochastic RSI

As the name suggests, calculated using rsi values and not bar values.

A histogram has been added to find new signals.

Have fun, and for any collaboration, contact me !!! 

On telegram : https://t.me/nimi012 (direct messaging)

On Discord: https://discord.gg/jNg7BSCh  (I advise you to come and see, Money management strategies and Signals Strategies !)

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(80, 20)]
    [Indicator(AccessRights = AccessRights.None)]
    public class RSIStochastique : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int KPeriod { get; set; }
        [Parameter(DefaultValue = 3)]
        public int Kslowing { get; set; }
        [Parameter(DefaultValue = 9)]
        public int Dslowing { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Weighted)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Use Histogram", DefaultValue = "true", Group = "Using Histogram")]
        public bool UseHistogram { get; set; }
        [Parameter("MA Signal Fast", DefaultValue = 1, MinValue = 1, Group = "Using Histogram")]
        public int maSignalFastHisto { get; set; }
        [Parameter("Ma Type Fast", DefaultValue = MovingAverageType.Weighted, Group = "Using Histogram")]
        public MovingAverageType MaTypeSignalFastHisto { get; set; }
        [Parameter("MA Signal Fast 2", DefaultValue = 13, MinValue = 1, Group = "Using Histogram")]
        public int maSignalFast2Histo { get; set; }
        [Parameter("Ma Type Fast 2", DefaultValue = MovingAverageType.Weighted, Group = "Using Histogram")]
        public MovingAverageType MaTypeSignalFast2Histo { get; set; }


        [Output("Kslow", LineColor = "Lime")]
        public IndicatorDataSeries Kslow { get; set; }
        [Output("Dslow", LineColor = "Red")]
        public IndicatorDataSeries Dslow { get; set; }


        [Output("White", PlotType = PlotType.Histogram, LineColor = "White", Thickness = 4)]
        public IndicatorDataSeries White { get; set; }
        [Output("Up Bullish", PlotType = PlotType.Histogram, LineColor = "ForestGreen", Thickness = 4)]
        public IndicatorDataSeries StrongBullish { get; set; }
        [Output("Down Bullish", PlotType = PlotType.Histogram, LineColor = "LawnGreen", Thickness = 4)]
        public IndicatorDataSeries WeakBullish { get; set; }
        [Output("Down Bearish", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 4)]
        public IndicatorDataSeries StrongBearish { get; set; }
        [Output("Up Bearish", PlotType = PlotType.Histogram, LineColor = "DarkSalmon", Thickness = 4)]
        public IndicatorDataSeries WeakBearish { get; set; }

        private RelativeStrengthIndex rsi;
        private IndicatorDataSeries result, rsiHighData, rsiLowData, rsiMiddleData;

        private MovingAverage kSlowing, dSlowing, maSignalFHisto, maSignalF2Histo;

        protected override void Initialize()
        {
            result = CreateDataSeries();
            rsiHighData = CreateDataSeries();
            rsiLowData = CreateDataSeries();
            rsiMiddleData = CreateDataSeries();

            rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, KPeriod);

            kSlowing = Indicators.MovingAverage(result, Kslowing, MaType);
            dSlowing = Indicators.MovingAverage(Kslow, Dslowing, MaType);

            maSignalFHisto = Indicators.MovingAverage(Kslow, maSignalFastHisto, MaTypeSignalFastHisto);
            maSignalF2Histo = Indicators.MovingAverage(Kslow, maSignalFast2Histo, MaTypeSignalFast2Histo);
        }

        public override void Calculate(int index)
        {
            // Stoch data 
            rsiHighData[index] = rsi.Result.Maximum(KPeriod);
            rsiLowData[index] = rsi.Result.Minimum(KPeriod);
            rsiMiddleData[index] = (rsiHighData[index] - rsiLowData[index]) / 2 + rsiLowData[index];
            // stoch calculation/Sources
            result[index] = ((rsi.Result.Last(0) - rsiLowData[index]) / (rsiHighData[index] - rsiLowData[index])) * 100;
            //result 
            Kslow[index] = kSlowing.Result.Last(0); ;
            Dslow[index] = dSlowing.Result.Last(0); ;

            if (UseHistogram)
            {

                double HistogramValue = maSignalFHisto.Result[index] - maSignalF2Histo.Result[index];
                double prevHistogramValue = maSignalFHisto.Result[index - 1] - maSignalF2Histo.Result[index - 1];
                if (HistogramValue > 0)
                {
                    if (prevHistogramValue >= HistogramValue)
                    {
                        WeakBullish[index] = HistogramValue;
                        StrongBullish[index] = 0;
                        WeakBearish[index] = 0;
                        StrongBearish[index] = 0;
                        White[index] = 0;
                    }
                    else
                    {
                        StrongBullish[index] = HistogramValue;
                        WeakBullish[index] = 0;
                        WeakBearish[index] = 0;
                        StrongBearish[index] = 0;
                        White[index] = 0;
                    }
                }
                else if (HistogramValue < -0)
                {
                    if (HistogramValue <= prevHistogramValue)
                    {
                        StrongBearish[index] = HistogramValue;
                        WeakBearish[index] = 0;
                        StrongBullish[index] = 0;
                        WeakBullish[index] = 0;
                        White[index] = 0;
                    }
                    else
                    {
                        WeakBearish[index] = HistogramValue;
                        StrongBearish[index] = 0;
                        StrongBullish[index] = 0;
                        WeakBullish[index] = 0;
                        White[index] = 0;
                    }
                }
                else
                {
                    if (HistogramValue <= prevHistogramValue)
                    {
                        White[index] = HistogramValue;
                        WeakBearish[index] = 0;


                        WeakBearish[index] = 0;
                        StrongBullish[index] = 0;
                        WeakBullish[index] = 0;

                    }
                    else
                    {
                        WeakBearish[index] = 0;

                        White[index] = HistogramValue;
                        StrongBearish[index] = 0;
                        StrongBullish[index] = 0;
                        WeakBullish[index] = 0;
                    }
                }
            }

        }
    }
}



YE
YesOrNot

Joined on 10.10.2022 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: RSI Stochastique.algo
  • Rating: 0
  • Installs: 568
  • Modified: 08/09/2023 16:45
Comments
Log in to add a comment.
No comments found.