How could i add Slowing to this code?

Created at 15 Dec 2021, 22:37
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
IR

IRCtrader

Joined 17.06.2021

How could i add Slowing to this code?
15 Dec 2021, 22:37


how could i add slowing to this code?

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

namespace cAlgo
{
    [Levels(1)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWStochasticLimitless : Indicator
    {

        private double UpperResult1;
        private double LowerResult1;

        [Parameter("K% periods 1", DefaultValue = 5)]
        public int inpKPeriods1 { get; set; }

        [Parameter("K% Slowing", DefaultValue = 1)]
        public int inpKSlowing { get; set; }

        [Output("K% 1", LineColor = "Black", LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries k1 { get; set; }


        protected override void Initialize()
        {

        }


        public override void Calculate(int index)
        {

            UpperResult1 = Bars.HighPrices.Maximum(inpKPeriods1);
            LowerResult1 = Bars.LowPrices.Minimum(inpKPeriods1);
            k1[index] = (Bars.ClosePrices[index]) / ((UpperResult1 + LowerResult1) / 2);


        }

    }

}

 


@IRCtrader
Replies

amusleh
16 Dec 2021, 11:12

Hi,

You just have to add a simple moving average over your K output:

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

namespace cAlgo
{
    [Levels(1)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWStochasticLimitless : Indicator
    {
        private double UpperResult1;
        private double LowerResult1;
        private SimpleMovingAverage _sma;

        [Parameter("K% periods 1", DefaultValue = 5)]
        public int inpKPeriods1 { get; set; }

        [Parameter("K% Slowing", DefaultValue = 3)]
        public int inpKSlowing { get; set; }

        [Output("K% 1", LineColor = "Black", LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries k1 { get; set; }

        [Output("K% 2", LineColor = "White", LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries k2 { get; set; }

        protected override void Initialize()
        {
            _sma = Indicators.SimpleMovingAverage(k1, inpKSlowing);
        }

        public override void Calculate(int index)
        {
            UpperResult1 = Bars.HighPrices.Maximum(inpKPeriods1);
            LowerResult1 = Bars.LowPrices.Minimum(inpKPeriods1);
            k1[index] = (Bars.ClosePrices[index]) / ((UpperResult1 + LowerResult1) / 2);
            k2[index] = _sma.Result[index];
        }
    }
}

 


@amusleh