Category Oscilators  Published on 27/10/2022

Stochastic DiNapoli indicator

Description

This is a hybrid version of Stochastic Oscillator



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

namespace cAlgo
{
    [Levels(20, 80)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mStochasticDiNapoli : Indicator
    {
        [Parameter("Fast K (8)", DefaultValue = 8)]
        public int intpFastK { get; set; }
        [Parameter("Slow K (3)", DefaultValue = 3)]
        public int intpSlowK { get; set; }
        [Parameter("Slow D (3)", DefaultValue = 3)]
        public int intpSlowD { get; set; }

        [Output("Stochastic", LineColor = "Black", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outStochastic { get; set; }
        [Output("Signal", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSignal { get; set; }
        
        private IndicatorDataSeries _hh, _ll, _raw, _stoch, _signal;
        

        protected override void Initialize()
        {
            _hh = CreateDataSeries();
            _ll = CreateDataSeries();
            _raw = CreateDataSeries();
            _stoch = CreateDataSeries();
            _signal = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _hh[i] = i>intpFastK ? Bars.HighPrices.Maximum(intpFastK) : Bars.HighPrices[i];
            _ll[i] = i>intpFastK ? Bars.LowPrices.Minimum(intpFastK) : Bars.LowPrices[i];
            _raw[i] = (Bars.ClosePrices[i] - _ll[i]) / (_hh[i] - _ll[i]) * 100;
            
            _stoch[i] = i>intpSlowK ? _stoch[i-1] + (_raw[i] - _stoch[i-1]) / intpSlowK : 50;
            _signal[i] = i>intpSlowD ? _signal[i-1] + (_stoch[i] - _signal[i-1]) / intpSlowD : 50;
            
            outStochastic[i] = _stoch[i];
            outSignal[i] = _signal[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mStochasticDiNapoli.algo
  • Rating: 5
  • Installs: 885
  • Modified: 26/10/2022 21:44
Comments
Log in to add a comment.
No comments found.