Get Index by Date/Time has NaN gaps.

Created at 11 Nov 2015, 08:50
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!
WhiteSage's avatar

WhiteSage

Joined 02.02.2014

Get Index by Date/Time has NaN gaps.
11 Nov 2015, 08:50


When using either the GetIndexByDate example or GetIndexByExactTime method for multiple symbols, NaN's are returned for some time points at week open. Interestingly, these gaps are longer on bigger time frames.

Here's the 5m:

And an example on the 1h:

And here's the code:

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

        private MarketSeries series2;
        private Symbol symbol2;

        [Parameter(DefaultValue = "USDCHF")]
        public string Symbol2 { get; set; }

        [Output("Main", PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries Result { get; set; }


        protected override void Initialize()
        {
            symbol2 = MarketData.GetSymbol(Symbol2);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            //int index2 = GetIndexByExactDate(series2, MarketSeries.OpenTime[index]);
            int index2 = series2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            Result[index] = series2.Close[index2];
            if (Result[index] == -1)
            {
                Print("-1 @: " + index);
            }
            if (double.IsNaN(Result[index]))
            {
                Print("NaN @: " + index);
            }
        }

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

            Print("No Time Value Found");
            return -1;
        }
    }
}

Is this an expected timezone/daylight savings issue or something to do with the platform or data provider?


@WhiteSage
Replies

Spotware
11 Nov 2015, 16:55

Dear Trader,

Regarding the NaN values in the log could you please check the initial opening times of the symbols you use. The following code snippet prints the initial opening time of the default Symbol:

Print(MarketSeries.OpenTime[0].ToString());

Regarding the NaN values during the week, we weren't able to reproduce your issue. 

Could you please refresh your charts and run your indicator again? You can refresh your charts by right clicking on the chart and select the refresh field. 


@Spotware

WhiteSage
12 Nov 2015, 05:10

RE:

Spotware said:

Dear Trader,

Regarding the NaN values in the log could you please check the initial opening times of the symbols you use. The following code snippet prints the initial opening time of the default Symbol:

Print(MarketSeries.OpenTime[0].ToString());

Regarding the NaN values during the week, we weren't able to reproduce your issue. 

Could you please refresh your charts and run your indicator again? You can refresh your charts by right clicking on the chart and select the refresh field. 

Added open times on initialise and when NaN's are detected. After making the code change and rebuilding the first 200~ samples of the second symbol on 5m (USDCHF) were blank, refreshing restored them.
5m log (after refresh, note the dud datetime on the second symbol for the current bar, this did not occur on the 1h):

12/11/2015 12:19:23.946 |  - Initialize - 
12/11/2015 12:19:23.961 | EURUSD (Ask: 1.07615, Bid: 1.07611) 04/10/2015 21:00:00
12/11/2015 12:19:23.977 | USDCHF (Ask: 1.00362, Bid: 1.00350) 04/10/2015 21:05:00
12/11/2015 12:19:23.992 | NaN @: 0
12/11/2015 12:19:23.992 | EURUSD (Ask: 1.07615, Bid: 1.07611) 04/10/2015 21:00:00
12/11/2015 12:19:23.992 | USDCHF (Ask: 1.00362, Bid: 1.00350) 04/10/2015 21:05:00
12/11/2015 12:19:23.992 | NaN @: 1152
12/11/2015 12:19:23.992 | EURUSD (Ask: 1.07615, Bid: 1.07611) 08/10/2015 21:00:00
12/11/2015 12:19:23.992 | USDCHF (Ask: 1.00362, Bid: 1.00350) 08/10/2015 21:10:00
12/11/2015 12:19:23.992 | NaN @: 2880
12/11/2015 12:19:23.992 | EURUSD (Ask: 1.07615, Bid: 1.07611) 18/10/2015 21:00:00
12/11/2015 12:19:23.992 | USDCHF (Ask: 1.00362, Bid: 1.00350) 18/10/2015 21:15:00
12/11/2015 12:19:24.008 | NaN @: 8133
12/11/2015 12:19:24.008 | EURUSD (Ask: 1.07615, Bid: 1.07611) 12/11/2015 02:45:00
12/11/2015 12:19:24.008 | USDCHF (Ask: 1.00362, Bid: 1.00350) 01/01/0001 00:00:00
12/11/2015 12:19:26.332 | NaN @: 8133
12/11/2015 12:19:26.332 | EURUSD (Ask: 1.07616, Bid: 1.07611) 12/11/2015 02:45:00
12/11/2015 12:19:26.332 | USDCHF (Ask: 1.00362, Bid: 1.00350) 01/01/0001 00:00:00
12/11/2015 12:19:26.613 | NaN @: 8133
12/11/2015 12:19:26.613 | EURUSD (Ask: 1.07617, Bid: 1.07611) 12/11/2015 02:45:00
12/11/2015 12:19:26.613 | USDCHF (Ask: 1.00362, Bid: 1.00350) 01/01/0001 00:00:00

1h log (after refresh):

12/11/2015 12:26:24.289 |  - Initialize - 
12/11/2015 12:26:24.320 | EURUSD (Ask: 1.07643, Bid: 1.07636) 20/07/2014 21:00:00
12/11/2015 12:26:24.320 | USDCHF (Ask: 1.00320, Bid: 1.00308) 20/07/2014 21:00:00
12/11/2015 12:26:24.335 | NaN @: 6642
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 16/08/2015 21:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 13:00:00
12/11/2015 12:26:24.335 | NaN @: 6643
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 16/08/2015 22:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 14:00:00
12/11/2015 12:26:24.335 | NaN @: 6644
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 16/08/2015 23:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 15:00:00
12/11/2015 12:26:24.335 | NaN @: 6645
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 00:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 16:00:00
12/11/2015 12:26:24.335 | NaN @: 6646
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 01:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 17:00:00
12/11/2015 12:26:24.335 | NaN @: 6647
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 02:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 18:00:00
12/11/2015 12:26:24.335 | NaN @: 6648
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 03:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 19:00:00
12/11/2015 12:26:24.335 | NaN @: 6649
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 04:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 20:00:00
12/11/2015 12:26:24.335 | NaN @: 6650
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 05:00:00
12/11/2015 12:26:24.335 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 21:00:00
12/11/2015 12:26:24.335 | NaN @: 6651
12/11/2015 12:26:24.335 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 06:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 22:00:00
12/11/2015 12:26:24.351 | NaN @: 6652
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 07:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 17/08/2015 23:00:00
12/11/2015 12:26:24.351 | NaN @: 6653
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 08:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 18/08/2015 00:00:00
12/11/2015 12:26:24.351 | NaN @: 6654
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 09:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 18/08/2015 01:00:00
12/11/2015 12:26:24.351 | NaN @: 6655
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 10:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 18/08/2015 02:00:00
12/11/2015 12:26:24.351 | NaN @: 6656
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 11:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 18/08/2015 03:00:00
12/11/2015 12:26:24.351 | NaN @: 6657
12/11/2015 12:26:24.351 | EURUSD (Ask: 1.07643, Bid: 1.07636) 17/08/2015 12:00:00
12/11/2015 12:26:24.351 | USDCHF (Ask: 1.00320, Bid: 1.00308) 18/08/2015 04:00:00

After watching the 5m for a bit I can confirm the Original NYE ;) glitch is only occurring during the first 2mins of a new 5min bar!


@WhiteSage

WhiteSage
12 Nov 2015, 10:21

RE: RE:

*The first two entries in the logs are executed in Initialize and the rest in Calculate.

 

I had been using the recommended method from the example and hadn't actually tried the non exact inbuilt method ( series2.OpenTime[0]).

It only has one NaN at the 0 index, but it still displays the time difference.

12/11/2015 17:44:57.774 |  - Initialize - 
12/11/2015 17:44:57.805 | EURUSD (Ask: 1.07454, Bid: 1.07449) 04/10/2015 21:00:00
12/11/2015 17:44:57.805 | USDCHF (Ask: 1.00528, Bid: 1.00516) 04/10/2015 21:05:00
12/11/2015 17:44:57.821 | NaN @: 0
12/11/2015 17:44:57.821 | EURUSD (Ask: 1.07454, Bid: 1.07449) 04/10/2015 21:00:00
12/11/2015 17:44:57.821 | USDCHF (Ask: 1.00528, Bid: 1.00516) 04/10/2015 21:05:00

 


@WhiteSage

Spotware
12 Nov 2015, 15:14

Dear Trader,

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 can contact one of our Partners or post a job in Development Jobs section for further coding assistance.

 


@Spotware