Indicator not update on index

Created at 15 Nov 2015, 21:33
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!
HQ

hq76

Joined 29.03.2015

Indicator not update on index
15 Nov 2015, 21:33


Hello,

Do someone can tell me what i am doing wrong here ?

My  TotChgAvr[index] is updating well in the first part of the code (print "hello") but stuck on a unique value on the second part (print "goodbye").

I'll appreciate any clue, thanks !


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

namespace cAlgo
{
    [Indicator(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SmoothedRSI : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int X { get; set; }

        [Parameter(DefaultValue = 6)]
        public int N { get; set; }

        [Output("SRSI", Color = Colors.Turquoise)]
        public IndicatorDataSeries SRSI { get; set; }

        private IndicatorDataSeries NetChgAvr;
        private IndicatorDataSeries TotChgAvr;
        private IndicatorDataSeries InitRatio;
        private IndicatorDataSeries ChgRatio;
        private MovingAverage EMAPrice;
        private MovingAverage InitPrice;



        protected override void Initialize()
        {
            NetChgAvr = CreateDataSeries();
            TotChgAvr = CreateDataSeries();
            ChgRatio = CreateDataSeries();
            InitRatio = CreateDataSeries();
            EMAPrice = Indicators.MovingAverage(MarketSeries.Close, X, MovingAverageType.Exponential);
            InitPrice = Indicators.MovingAverage(InitRatio, N, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {


            var SF = 1 / N;

            var Change = EMAPrice.Result[index] - EMAPrice.Result[index - 1];


            int total = MarketSeries.Close.Count;


            if (total <= N + X)
            {
                InitRatio[index] = Math.Abs(EMAPrice.Result[index] - EMAPrice.Result[index - 1]);
                NetChgAvr[index] = (EMAPrice.Result[index] - EMAPrice.Result[N]) / N;
                TotChgAvr[index] = InitRatio[index];
                //Print("hello=", TotChgAvr[index]);
            }
            else
            {
                NetChgAvr[index] = NetChgAvr[index - 1] + SF * (Change - NetChgAvr[index - 1]);
                TotChgAvr[index] = TotChgAvr[index - 1] + SF * (Math.Abs(Change) - TotChgAvr[index - 1]);
                //Print("goodbye=", TotChgAvr[index]);
            }

            if (TotChgAvr[index] != 0)
            {
                ChgRatio[index] = NetChgAvr[index] / TotChgAvr[index];
                //Print(ChgRatio[index]);
            }
            else
            {
                ChgRatio[index] = 0;
            }


            SRSI[index] = 50 * (ChgRatio[index] + 1);
        }

    }
}

 


@hq76
Replies

Spotware
16 Nov 2015, 08:05

Dear Trader,

From the quick look at your code we have seen that you are initializing the variable SF with the result of a division. The result of dividing 2 integers is always an integer. We recommend you to have a look at the following article: / Operator (C# Reference).

We would like to inform you that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware