Profile Picture

BarsHeld Property incorrect for positions created via live system

Posted By alpha23 8 Years Ago

BarsHeld Property incorrect for positions created via live system

Posted Monday April 05 2010
I've had a position open since 3/25 (confirmed this fill time in the the FilledTime element of LiveOpenPositions.xml); however, when I view the BarsHeld property on an OpenPosition after starting the live system, the value == 1. I'm using 2010 Build 15. Has this been fixed in the latest?

Thanks, Duane
Posted Monday April 05 2010
Position timeouts and the BarsHeld property are updated on NewBar. When running a live system, the existing positions aren't active during the lead bars period, so they will only be affected when a new bar comes in while in live mode. For a daily system this won't ever happen, unless you have it running live at midnight.

I've filed an issue for this in our tracking system, but there's not a simple way to fix it so I don't expect to address it before the next major edition.

Posted Thursday September 13 2012

Any update on this?

Thanks, Duane
Posted Friday September 21 2012
No, no update. Like I said there's not an easy way to fix it with the existing architecture. For now, you will have to write code to keep track of this yourself.

Posted Saturday September 22 2012
Interestingly, I switched to days held versus barsheld and yielded a better return for one of my systems.

Here is the code for days held if anyone is interested. NasdaqHolidaySchedule.HolidayDates is a List of holiday dates. The following is a source for holidays:


public int GetBarsHeld(DateTime openDate, string symbol)
int daysHeld;
var ts = SystemData.CurrentDate.Date.Subtract(openDate.Date).TotalDays;
var weeksHeld = Math.DivRem((int)ts, 7, out daysHeld);
switch (openDate.DayOfWeek){
case DayOfWeek.Monday:
if (daysHeld >= 5) daysHeld = 5;
case DayOfWeek.Tuesday:
if ((daysHeld >= 4) && (daysHeld <= 6)) daysHeld = 4;
if (daysHeld == 7) daysHeld -= 2;
case DayOfWeek.Wednesday:
if ((daysHeld >= 3) && (daysHeld <= 5)) daysHeld = 3;
if (daysHeld >= 6) daysHeld -= 2;
case DayOfWeek.Thursday:
if ((daysHeld >= 2) && (daysHeld <= 4)) daysHeld = 2;
if (daysHeld >= 5) daysHeld -= 2;
case DayOfWeek.Friday:
if ((daysHeld >= 1) && (daysHeld <= 3)) daysHeld = 1;
if (daysHeld >= 4) daysHeld -= 2;
Console.WriteLine("Symbol: {0}; Opened on non-trading day", symbol);
daysHeld += weeksHeld*5;

// account for holidays
var holidays = 0;
foreach (var date in NasdaqHolidaySchedule.HolidayDates){
if ((date.Date.CompareTo(openDate.Date) >= 0) && (date.Date.CompareTo(SystemData.CurrentDate.Date) <= 0)){
daysHeld -= holidays;
return daysHeld;

Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems