Category Oscilators  Published on 26/12/2019

Stochastic for Indicators

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp and an Instagram page https://www.instagram.com/ctrader_community/

This is a stochastic oscillator with a source, it will fit on any other indicator but cannot be used to calculate stochastic on marketseries, for those you'll have to use the standard one.

Here's an example of it calculated on Pring's Special K:


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StochasticForIndicators : Indicator
    {
        [Parameter("%K Period", DefaultValue = 9)]
        public int K { get; set; }
        [Parameter("%K Smoothing", DefaultValue = 3)]
        public int Ks { get; set; }
        [Parameter("%K Smoothing Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType Kt { get; set; }
        [Parameter("%D Period", DefaultValue = 9)]
        public int D { get; set; }
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Output("%K")]
        public IndicatorDataSeries KLine { get; set; }
        [Output("%D", LineColor = "Red", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries DLine { get; set; }

        private IndicatorDataSeries Stochastic;
        private MovingAverage Smoothing, Signal;

        protected override void Initialize()
        {
            Stochastic = CreateDataSeries();
            Smoothing = Indicators.MovingAverage(Stochastic, Ks, Kt);
            Signal = Indicators.SimpleMovingAverage(KLine, D);
        }

        public override void Calculate(int index)
        {
            Stochastic[index] = 100 * (Source[index] - Source.Minimum(K)) / (Source.Maximum(K) - Source.Minimum(K));
            KLine[index] = Smoothing.Result[index];
            DLine[index] = Signal.Result[index];
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: StochasticForIndicators.algo
  • Rating: 0
  • Installs: 1645
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.