SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Apr 05, 2020 11:28 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Aug 31, 2009 9:18 am 
Offline

Joined: Tue Aug 25, 2009 2:57 am
Posts: 1
When running paper/live, I am trying to look at the previous day's data. My system trades on day-to-day basis, and so the prior day's data is necessary to make today's trading decision, and thus must be considered whenever the strategy is restarted.

The code works fine in simulation mode, but when I try to run it paper/live I get the following error:
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

Here is the code in question:
****
...
if (DebugMessages) Console.WriteLine("Retrieving historical data from " + D + " to " + DateCurrent);
mybars = DataManager.GetHistoricalBars(Instrument, D, DateCurrent, BarType.Time, 60);
if (DebugMessages) Console.WriteLine("Retrieved " + mybars.Count + " historical bars.");
if (mybars.Count == 0)
Console.WriteLine("WARNING: No historical bars retrieved!");

// Set DHistStart and DHistEnd to session open and close for the day being examined

DateTime DHistStart = D;
DateTime DHistEnd = D;
DHistStart = DHistStart.AddHours(RTHStartTime.Hours);
DHistStart = DHistStart.AddMinutes(RTHStartTime.Minutes);
DHistStart = DHistStart.AddSeconds(RTHStartTime.Seconds);
DHistEnd = DHistEnd.AddHours(RTHEndTime.Hours);
DHistEnd = DHistEnd.AddMinutes(RTHEndTime.Minutes);
DHistEnd = DHistEnd.AddSeconds(RTHEndTime.Seconds);

if (DebugMessages) Console.WriteLine("Analyzing day from " + DHistStart + " to " + DHistEnd);

// Set PrevX, these will be used in OnBar to set yesterday's data
histHigh = mybars.HighestHigh(DHistStart, DHistEnd);
histLow = mybars.LowestLow(DHistStart, DHistEnd);

if (DebugMessages) Console.WriteLine(mybars.GetIndex(DHistStart));
if (DebugMessages) Console.WriteLine(mybars.GetIndex(DHistEnd));
histOpen = mybars[mybars.GetIndex(DHistStart), BarData.Open];
histClose = mybars[mybars.GetIndex(DHistEnd), BarData.Close];
if (DebugMessages) Console.WriteLine("Captured " + histOpen + " " + histHigh + " " + histLow + " " + histClose);

// if the strategy started running in the middle of the day's session, we also need to retrieve today's opening value
if (initDuringSession) {
DHistStart = DHistStart.AddDays(1);
if (DHistStart.DayOfWeek==DayOfWeek.Saturday)
DHistStart = DHistStart.AddDays(2);
if (DHistStart.DayOfWeek==DayOfWeek.Sunday)
DHistStart = DHistStart.AddDays(1);
openToday = mybars[mybars.GetIndex(DHistStart), BarData.Open];
if (DebugMessages) Console.WriteLine("Analyzing today, captured open: " + openToday);
dayNum++;
}

return 0;

****

Here's the output I get:

INITIALIZING STRATEGY...
Bar size: 60 secs
Bars in day: 390

INITIALIZING DATES & HISTORICAL DATA
Running as PAPER or LIVE.
Strategy start date/time: 8/30/2009 11:07:25 PM
After RTH, loading data for today.
Retrieving historical data from 8/28/2009 12:00:00 AM to 8/30/2009 11:07:25 PM
Retrieved 945 historical bars.
Analyzing day from 8/28/2009 6:30:00 AM to 8/28/2009 12:59:00 PM
-1
-1

So it appears that the "mybars.GetIndex(DHistStart)" is returning an index of "-1", which is what generates the error. But this works fine in historical mode. (So in historical mode, if I set the strategy to start on Tuesday, Aug 4, the code will automatically load and analyze the data for Monday, Aug 3.)

Any help would be appreciated. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 07, 2009 3:13 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi,

Could you post the full error description(stack trace)?

Regards,
Alex

_________________
SmartQuant Development Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group