When BarSeries data are accessed from a UI event handler, the indexer methods for accessing the data are not working properly
e.g. Time[barsAgo] doesn't work but Time.GetValueAt(barIndex) works.
I've knocked together the attached indicator to show the issue. Which does the following:
OnBarUpdate prints out CurrentBar and Time[0] to show that the data are being populated. The correct bar times and indexes are printed out for all bars on the chart as well as a hashcode to identify the executing object instance.
A button is added to chart trader which has a click event handled in the indicator.
Clicking the button prints a few debug checks
CurrentBar (999 as expected)
Time.GetValueAt(999) - gets the time of the most recent bar, as expected
Time.GetValueAt(1) - gets the time of the first bar, as expected.
Now using indexes, it gets weird:
Time[0] should give the most recent bar (same as GetValueAt(999), but instead gives the first bar.... same as GetValueAt(1)
Time[1] and Time[2] throw a NullReferenceException
SuspendedWhileInactive = false and a call to Update() don't resolve this either.
Here's the actual output:
Bar Update 1007 BarTime:26/04/2017 00:55:00 HashCode: 6765737 Bar Update 1008 BarTime:26/04/2017 01:00:00 HashCode: 6765737 Bar Update 1009 BarTime:26/04/2017 01:05:00 HashCode: 6765737 Bar Update 1010 BarTime:26/04/2017 01:10:00 HashCode: 6765737 Bar Update 1011 BarTime:26/04/2017 01:15:00 HashCode: 6765737 Bar Update 1012 BarTime:26/04/2017 01:20:00 HashCode: 6765737 Bar Update 1013 BarTime:26/04/2017 01:25:00 HashCode: 6765737 Bar Update 1014 BarTime:26/04/2017 01:30:00 HashCode: 6765737 Bar Update 1015 BarTime:26/04/2017 01:35:00 HashCode: 6765737 ==== Start Debug Output ==== HashCode: 6765737 Total Bars (CurrentBar): 1015 Time.GetValueAt(CurrentBar 1015): 26/04/2017 01:35:00 Time.GetValueAt(1): 20/04/2017 12:50:00 Time[0]: 20/04/2017 12:45:00 Time[1]: Object reference not set to an instance of an object. Time[2]: Object reference not set to an instance of an object. ==== End Debug Output ====
Comment