Stochastic without limit 0 to 100

Created at 15 Dec 2021, 21:46
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

Stochastic without limit 0 to 100
15 Dec 2021, 21:46


i try to make stochastic without limit. but i don't know why it's yet between 0 to 1.

actully i don't know why Bars.ClosePrices[index] - LowerResult is always positive?

note: i want to use high and low insist of close price.

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 st : Indicator
    {


        [Parameter("Period", DefaultValue = 26)]
        public int Period { get; set; }


        [Output("resualt", LineColor = "Gray", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries Result { get; set; }

        private double UpperResult;
        private double LowerResult;

        protected override void Initialize()
        {


        }

        public override void Calculate(int index)
        {

            UpperResult = Bars.HighPrices.Maximum(Period);
            LowerResult = Bars.LowPrices.Minimum(Period);

            Result[index] = (Bars.ClosePrices[index] - LowerResult) / (UpperResult - LowerResult);
            
        }

    }

}

 


@IRCtrader
Replies

amusleh
16 Dec 2021, 11:06

Hi,

Your indicator output is based on your code, I don't see any issue.

The Bars.LowPrices.Minimum gives you the minimum price over your passed period which includes the last bar.

And then you subtract it from the current bar close price, it's not going to be negative, you are subtracting the lowest value from the current bar close value, which at most can be equal to lowest value but not lower than it.

 


@amusleh