where is thew code for the stochastic oscillator

Created at 10 Apr 2015, 10:38
lec0456's avatar

lec0456

Joined 14.11.2012

where is thew code for the stochastic oscillator
10 Apr 2015, 10:38


where is thew code for the stochastic oscillator?


@lec0456
Replies

GunArm
15 Apr 2015, 21:38

It's built in, in the "StochasticOscillator" class.  If you wanted to modify the code, you would probably need to re-implement it.


@GunArm

lec0456
15 Apr 2015, 21:42

They used to have it posted in the samples section.  Anyway I found the code from when I downloaded it before..


@lec0456

benyamin
29 May 2015, 15:42

RE:

lec0456 said:

They used to have it posted in the samples section.  Anyway I found the code from when I downloaded it before..

 

 

 

Hey hey

 

I write it :

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Levels(20, 50, 80)]

    [Indicator()]
    public class AMIRSTOCHASTIC : Indicator
    {
        private IndicatorDataSeries _fastK;
        private MovingAverage _slowK;
        private MovingAverage _averageOnSlowK;

        [Parameter("K Periods", DefaultValue = 15, MinValue = 1)]
        public int KPeriods { get; set; }

        [Parameter("K Slowing", DefaultValue = 3, MinValue = 2)]
        public int KSlowing { get; set; }

        [Parameter("D Periods", DefaultValue = 3, MinValue = 0)]
        public int DPeriods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }

        [Output("%D", Color = Colors.Lime, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries PercentD { get; set; }

        [Output("%K", Color = Colors.Red)]
        public IndicatorDataSeries PercentK { get; set; }


// Added by amir for line ! 
        //  [Output("Overbought", Color = Colors.Turquoise)]
        // public IndicatorDataSeries overbought { get; set; }

        // [Output("Oversold", Color = Colors.Red)]
        //  public IndicatorDataSeries oversold { get; set; }
        //   [Output("over30", Color = Colors.Turquoise)]
        //   public IndicatorDataSeries over30 { get; set; }

        [Output("Line34", Color = Colors.White, LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries Line34 { get; set; }

        [Output("Line50", Color = Colors.Gray, LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries Line50 { get; set; }

        [Output("Line66", Color = Colors.White, LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries Line66 { get; set; }
//  [Output("over80", Color = Colors.Red)]
        //    public Line over80 { get; set; }


        protected override void Initialize()
        {

            _fastK = CreateDataSeries();
            _slowK = Indicators.MovingAverage(_fastK, KSlowing, MAType);

            _averageOnSlowK = Indicators.MovingAverage(_slowK.Result, DPeriods, MAType);
        }

        public override void Calculate(int index)
        {


            Line34[index] = 34;
            Line50[index] = 50;
            Line66[index] = 66;
            _fastK[index] = GetFastKValue(index);
            PercentK[index] = _slowK.Result[index];
            PercentD[index] = _averageOnSlowK.Result[index];
        }

        private double GetFastKValue(int index)
        {
            var lowestLow = MarketSeries.Low.Minimum(KPeriods);
            var hightestHigh = MarketSeries.High.Maximum(KPeriods);
            var currentClose = MarketSeries.Close[index];

            return 100 * (currentClose - lowestLow) / (hightestHigh - lowestLow);
        }
    }
}

 


@benyamin