Not sure what's going on with GetSeries().
Not sure what's going on with GetSeries().
20 May 2016, 21:59
protected override void OnStart() { Print("Server Time Today: {0}", Server.Time.DayOfWeek); Print("Current Series Today: {0}", MarketSeries.OpenTime.Last(0).DayOfWeek); //So far so good MarketSeries x = MarketData.GetSeries(Symbol.Code, TimeFrame.Daily); Print("GetSeries Today: {0}", x.OpenTime.Last(0).DayOfWeek); //This thwows data 1 day behind, why? }
Hello Community, I got an issue here.
Why if I try to get the opentime of the current day it thows the previous one instead?
The data printed is:
20/05/2016 18:58:40.369 | Server Time Today: Friday
20/05/2016 18:58:40.369 | Current Series Today: Friday
20/05/2016 18:59:01.541 | GetSeries Today: Thursday
And how can I fix this?
Replies
galafrin
23 May 2016, 03:50
RE:
galafrin said:
Most FOREX markets start at 21H00 GMT on sunday except RUB , in order to get 24hours bars there is no such ting like friday in FOREX daily series except for RUB .
Slight correction : Most FOREX markets start at 0H00 GMT on Monday which translate in Sunday 21H00 Cyprus DST or russian time or Sunday 23:00 London DST or Monday 00.00 GMT . Hence in order to have friday daily bars , Russian time is to be set as time zone. Just a a bit of a headache but it goes like this
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.RussianStandardTime, AccessRights = AccessRights.None)]
public class NewIndicator : Indicator
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
protected override void Initialize()
{
Print("Server Time Today: {0} {1}", Server.Time.DayOfWeek, TimeZones.RussianStandardTime.ToString());
Print("bar OpenTime Series : {0}", MarketSeries.OpenTime.Last(1).DayOfWeek);
//So far so good
MarketSeries x = MarketData.GetSeries(Symbol.Code, TimeFrame.Daily);
Print("GetSeries dAily: {0}", x.OpenTime.Last(1).DayOfWeek);
Print("Server Time Today: {0} {1}", Server.Time.DayOfWeek, TimeZones.RussianStandardTime.ToString());
Print("Current Series Today: {0} {1} {2} {3} ", Symbol.Code, TimeFrame, MarketSeries.OpenTime.Last(1).DayOfWeek, MarketSeries.OpenTime.Last(1));
//So far so good
for (int i = 1; i < MarketData.GetSeries(TimeFrame.Daily).OpenTime.Count; i++)
if (MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i).TimeOfDay != MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1).TimeOfDay)
Print("GetSeries Today: {0} {1} {2} {3} {4} {5} {6} ", i, Symbol.Code, TimeFrame.Daily, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i).DayOfWeek, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i), MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1).DayOfWeek, MarketData.GetSeries(TimeFrame.Daily).OpenTime.Last(i - 1));
//This thwows data 1 day behind, why? */
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] = ...
}
}
23/05/2016 00:44:19.278 | Server Time Today: Monday Russian Standard Time
23/05/2016 00:44:19.278 | bar OpenTime Series : Friday
23/05/2016 00:44:19.278 | GetSeries dAily: Friday
23/05/2016 00:44:19.294 | Server Time Today: Monday Russian Standard Time
23/05/2016 00:44:19.294 | Current Series Today: EURUSD Daily Friday 20/05/2016 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 51 EURUSD Daily Friday 11/03/2016 1:00:00 Monday 14/03/2016 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 144 EURUSD Daily Friday 30/10/2015 0:00:00 Monday 02/11/2015 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 315 EURUSD Daily Sunday 08/03/2015 1:00:00 Monday 09/03/2015 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 405 EURUSD Daily Friday 31/10/2014 0:00:00 Monday 03/11/2014 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 410 EURUSD Daily Friday 24/10/2014 1:00:00 Monday 27/10/2014 0:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 576 EURUSD Daily Sunday 09/03/2014 2:00:00 Monday 10/03/2014 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 668 EURUSD Daily Saturday 02/11/2013 1:00:00 Monday 04/11/2013 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 869 EURUSD Daily Friday 08/03/2013 2:00:00 Monday 11/03/2013 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 964 EURUSD Daily Saturday 03/11/2012 1:00:00 Monday 05/11/2012 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1167 EURUSD Daily Sunday 11/03/2012 2:00:00 Monday 12/03/2012 1:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1272 EURUSD Daily Friday 04/11/2011 1:00:00 Monday 07/11/2011 2:00:00
23/05/2016 00:44:19.294 | GetSeries Today: 1462 EURUSD Daily Sunday 27/03/2011 0:00:00 Monday 28/03/2011 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1474 EURUSD Daily Sunday 13/03/2011 1:00:00 Monday 14/03/2011 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1581 EURUSD Daily Friday 05/11/2010 0:00:00 Monday 08/11/2010 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1586 EURUSD Daily Friday 29/10/2010 1:00:00 Monday 01/11/2010 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1771 EURUSD Daily Sunday 28/03/2010 0:00:00 Monday 29/03/2010 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1783 EURUSD Daily Sunday 14/03/2010 1:00:00 Monday 15/03/2010 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1894 EURUSD Daily Friday 30/10/2009 0:00:00 Monday 02/11/2009 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 1899 EURUSD Daily Friday 23/10/2009 1:00:00 Monday 26/10/2009 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2078 EURUSD Daily Sunday 29/03/2009 0:00:00 Monday 30/03/2009 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2096 EURUSD Daily Sunday 08/03/2009 1:00:00 Monday 09/03/2009 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2202 EURUSD Daily Sunday 02/11/2008 0:00:00 Monday 03/11/2008 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2208 EURUSD Daily Sunday 26/10/2008 1:00:00 Monday 27/10/2008 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2388 EURUSD Daily Sunday 30/03/2008 0:00:00 Monday 31/03/2008 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2406 EURUSD Daily Sunday 09/03/2008 1:00:00 Monday 10/03/2008 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2514 EURUSD Daily Sunday 04/11/2007 0:00:00 Monday 05/11/2007 1:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2520 EURUSD Daily Sunday 28/10/2007 1:00:00 Monday 29/10/2007 0:00:00
23/05/2016 00:44:19.310 | GetSeries Today: 2706 EURUSD Daily Sunday 25/03/2007 0:00:00 Monday 26/03/2007 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 2718 EURUSD Daily Sunday 11/03/2007 1:00:00 Monday 12/03/2007 0:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3010 EURUSD Daily Sunday 02/04/2006 2:00:00 Monday 03/04/2006 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3016 EURUSD Daily Sunday 26/03/2006 1:00:00 Monday 27/03/2006 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3322 EURUSD Daily Sunday 03/04/2005 2:00:00 Monday 04/04/2005 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3328 EURUSD Daily Sunday 27/03/2005 1:00:00 Monday 28/03/2005 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3611 EURUSD Daily Sunday 04/04/2004 2:00:00 Monday 05/04/2004 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3617 EURUSD Daily Sunday 28/03/2004 1:00:00 Monday 29/03/2004 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3874 EURUSD Daily Sunday 06/04/2003 2:00:00 Monday 07/04/2003 1:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 3880 EURUSD Daily Sunday 30/03/2003 1:00:00 Monday 31/03/2003 2:00:00
23/05/2016 00:44:19.325 | GetSeries Today: 4137 EURUSD Daily Sunday 07/04/2002 2:00:00 Monday 08/04/2002 1:00:00
23/05/2016 00:44:19.341 | GetSeries Today: 4143 EURUSD Daily Sunday 31/03/2002 1:00:00 Monday 01/04/2002 2:00:00
@galafrin
Waxy
24 May 2016, 05:49
Thank you galafrin, can't believe I had no idea of this.
So my purpose was to use a function for a range (day) and skip the weekends, I had to find a more reliable source code, tho not efficient it works, anyway I'll post it here.
DayOfWeek _ref = MarketSeries.OpenTime.LastValue.DayOfWeek; int i = 0; int _auxday = 1; while (_auxday < _DaysToCompute) { if (MarketSeries.OpenTime.Last(i).DayOfWeek == _ref) { i++; } else { _ref = MarketSeries.OpenTime.Last(i).DayOfWeek; UseFunctionForDayBack(_auxday); _auxday++; } }
@Waxy
galafrin
20 May 2016, 22:54
Most FOREX markets start at 21H00 GMT on sunday except RUB , in order to get 24hours bars there is no such ting like friday in FOREX daily series except for RUB .
@galafrin