Problem: For US and Canadian indexes, a few of trading dates per year are not the same because of different stock market holidays. This caused the index data to be out of sync.
1. Retrieving data using Closes[index][barsAgo] – DAILY data are out of sync when a different trading holidays are encountered.
2. Retrieving data using BarsArray[index].GetClose(bar) – data are also out of sync because the retrieved bar data is mostly incorrect.
3. The indexes used for testing (load both series on the screen):
^SP500 (Kinetick: SPX.XO)
^TSX_INDEX (Kinetick: C.TX60.X)
Note: The Data Box is displaying the correct data for the these two indexes
Please help to resolve. Test indicator is attached.
Codes used for testing:
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
if(CurrentBars[0] == BarsArray[0].Count-2 && State == State.Historical)
{
ClearOutputWindow();
TriggerCustomEvent(o =>
{
for(int ibarsAgo=0; ibarsAgo<40; ibarsAgo++)
{
int ibar= BarsArray[0].Count-2 - ibarsAgo;
DateTime date_0 = BarsArray[0].GetTime(ibar); // check to see if different from Bars.GetTime(ibar)
int idx_0= BarsArray[0].GetBar(date_0);
int idx_1= BarsArray[1].GetBar(date_0);
// date_0a == date_0
DateTime date_0a = BarsArray[0].GetTime(idx_0);
// date_1a != date_0, sometimes it is the same
DateTime date_1a = BarsArray[1].GetTime(idx_1);
// dClose_0 == dClose_0a , no problem
// dClose_1 != dClose_1a, sometimes it is the same
double dClose_0 = BarsArray[0][ibarsAgo];
double dClose_1 = BarsArray[1][ibarsAgo];
double dClose_0a = BarsArray[0].GetClose(idx_0);
double dClose_1a = BarsArray[1].GetClose(idx_1);
Print("ibarsAgo = " + ibarsAgo + ", date_0 = " + date_0 + ", date_0a = " + date_0a + ", date_1a = " + date_1a);
Print("dClose_0 = " + dClose_0 + ", dClose_0a = " + dClose_0a + ", dClose_1 = " + dClose_1 + ", dClose_1a = " + dClose_1a);
Print(".");
}
}, null);
}
}
Results:
ibarsAgo = 1, date_0 = 2021-02-02 12:00:00 AM, date_0a = 2021-02-02 12:00:00 AM, date_1a = 2021-02-01 12:00:00 AM (date_1a is different)
dClose_0 = 3826.31, dClose_0a = 3826.31, dClose_1 = 1059.25, dClose_1a = 1044.68
.

Comment