I added the Weekly data series using AddDataSeries(BarsPeriodType.Week, 1) during Configure state, and I am running the indicator on Daily chart (symbol CAT, Kinetick source).
I noticed that the start of the week provided by the weekly data series is off by a week.
So, for 12-Dec-2022 (Monday), the weekly open I get is from the 05-Dec-2022 and I see this repeating for 13th, 14th and 15th Dec. However, for 16th Dec, I get the correct weekly open of 12-Dec.
public class TestMTF : Indicator { bool currentTfUpdated = false; // Keep track of tick of current TF is received. bool weeklyTfUpdated = false; // Keep track of tick of Weekly TF. protected override void OnStateChange() { if (State == State.SetDefaults) { // Skipped boilerplate code. } else if (State == State.Configure) { // Adding Weekly data-series of the same instrument. AddDataSeries(BarsPeriodType.Week, 1); } } protected override void OnBarUpdate() { if( BarsInProgress == 0 ) currentTfUpdated = true; else if( BarsInProgress == 1 ) weeklyTfUpdated = true; if( currentTfUpdated && weeklyTfUpdated ) // Print only if we have received update of current and weekly TF. { double weeklyOpenPrice = BarsArray[1].GetOpen(CurrentBars[1]); DateTime weeklyCandleTime = BarsArray[1].GetTime(CurrentBars[1]); Print(string.Format("BarsInProgress = {0}, Time[0] = {1}, Close[0] = {2}, WeeklyTime = {3}, WeeklyOpen = {4}", BarsInProgress, Time[0].ToString("yyyy.MM.dd"), Close[0].ToString(), weeklyCandleTime.ToString("yyyy.MM.dd"), weeklyOpenPrice.ToString())); } } }
Now notice the output window, for 12th Dec (2022.12.13) and 13th Dec (2022.12.14), 14th and 15th. The weekly open price is 234.8, which is actually the open price of previous Monday (5th Dec).
If I open the weekly chart, and check the weekly open price in the data-box of 12th Dec, it is shown as 227.55 (which is correct).
BarsInProgress = 0, Time[0] = 2022.12.09, Close[0] = 230.92, WeeklyTime = 2022.12.02, WeeklyOpen = 233.94
BarsInProgress = 0, Time[0] = 2022.12.10, Close[0] = 227.29, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 1, Time[0] = 2022.12.10, Close[0] = 227.29, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 0, Time[0] = 2022.12.13, Close[0] = 233.06, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 0, Time[0] = 2022.12.14, Close[0] = 235.49, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 0, Time[0] = 2022.12.15, Close[0] = 234.48, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 0, Time[0] = 2022.12.16, Close[0] = 230.66, WeeklyTime = 2022.12.09, WeeklyOpen = 234.8
BarsInProgress = 0, Time[0] = 2022.12.17, Close[0] = 232.72, WeeklyTime = 2022.12.16, WeeklyOpen = 227.55
BarsInProgress = 1, Time[0] = 2022.12.17, Close[0] = 232.72, WeeklyTime = 2022.12.16, WeeklyOpen = 227.55
What am I doing wrong and how do I fix this ?
Comment