new Methods

Created at 16 Dec 2013, 09:43
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!
lec0456's avatar

lec0456

Joined 14.11.2012

new Methods
16 Dec 2013, 09:43


GetIndexByTime and GetindexbyExactTime are 2 new methods that I can't seem to find much information on?  Nothing in the API reference not too many examples.  How does it work? When should you use it?


@lec0456
Replies

Spotware
16 Dec 2013, 11:16

The "index" that is the parameter to the Calculate method, is the index of the series that the instance is attached to. The series of other timeframes / symbols have different indexes. So, to get the index of a specific series you would need to use a method such as GetIndexByTime and GetindexbyExactTime.

example:

        MarketSeries series;

        protected override void Initialize()
        {
            series = MarketData.GetSeries(Symbol, TimeFrame.Daily);
        }

        public override void Calculate(int index)
        {
            var index2 = series.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime.LastValue);
            if (index2 > 0)
                var close = series.Close[index2];
        }

The difference between the two is that GetIndexByTime returns the closest index to the open time, whereas the GetindexbyExactTime will only return an index if there is one at the exact time and will return -1 otherwise.


@Spotware

lec0456
17 Dec 2013, 07:33

Ok, so in this post you use a function:

/forum/whats-new/1463

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

We don't need to use this function or multitime frames anymore? because its implemented as a method, correct?


@lec0456

Spotware
17 Dec 2013, 09:11

RE:

lec0456 said:

Ok, so in this post you use a function:

/forum/whats-new/1463

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

We don't need to use this function or multitime frames anymore? because its implemented as a method, correct?

Yes that is correct.


@Spotware