Indicator not updating

Created at 04 Nov 2013, 20:38
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!
Hyperloop's avatar

Hyperloop

Joined 23.10.2013

Indicator not updating
04 Nov 2013, 20:38


I wrote an indicator which does some calculations between two symbols' current bars (arbitrage based). When I run the indicator, values for the most recent 2-20 bars show up as NaN, although the past is showing up perfectly.

 

This code example shows an example of what I am trying to do:

private int GetIndexByDate(DateTime argDateTime)
        {
            for (int i = MarketSeries.Close.Count - 1; i > 0; i--)
            {
                if (argDateTime == MarketSeries.OpenTime[i])
                    return i;
            }
            return -1;
        }

public override void Calculate(int index)
        {
            int SecondIndex = GetIndexByDate(MarketSeries.OpenTime[index]);

            if (SecondIndex != -1)
            {
                Result[index] = MarketSeries.Close[index] / SecondSeries.Close[SecondIndex];
            }
            else
            {
                Result[index] = Result[index - 1];
            }
        }

As you guys can see, I'm using the GetIndexByDate method to double check the both bars are matching open times, since I've found there are gaps in the data and the indices alone do not match up completely.


@Hyperloop
Replies

daemon
05 Nov 2013, 10:02

You need to fix your GetIndexByDate method. 
It should be like this:

        private int GetIndexByDate(DateTime argDateTime)
        {
            for (int i = SecondSeries.Close.Count - 1; i > 0; i--)
            {
                if (argDateTime == SecondSeries.OpenTime[i])
                    return i;
            }
            return -1;
        }

 


@daemon

Hyperloop
05 Nov 2013, 20:06

Thank you Daemon,

It appears to be working properly now. :)


@Hyperloop