Sorry to bother you but I appear to be banging my head against a wall on this one, so thought that I would seek help.
I am trying to create a strategy that uses three time frames, one for daily, one for weekly, and the third for monthly. I think that I have managed that ok.
When I try and access the CurrentBar in the daily chart (in OnBarUpdate()) they do not start at one, it has been 5 or 20, (I think that the differing values might be to do with the start date of the chart that I am using), but I cannot get the values to begin at one. I use the CurrentBar value to get values from the chart and put them into an array, then carry out processing on them. The problem is that if currentBar value is bigger than the array it is accessing, the program fails (obviously)
I think I can get around the CurrentBar not beginning at one, (as I think this has something to do with the additional periodtypes) but I would just like to get to the bottom of it.
Also, do you know if it is possible to delete/remove periodTypes e.g. the opposite of Add(PeriodType.Day,1); ?
I'm sorry if this is not as clear as I mean it to be, but if you require any further information, please just let me know.
TIA,
Graham.
SAmple code below
protected override void Initialize()
{
// Add(PeriodType.Day,1);
Add(PeriodType.Week,1);
Add(PeriodType.Month,1);
CalculateOnBarClose = true;
BarsRequired = 0;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
int i;
i = BarsArray.Length;
// BarsArray[BarsInProgress].Period.Id == "Day"
// LTTR = CalcRSI();
// AofT.Add(LTTR);
// i = AofT[CurrentBar].CalcRSIReturnFlag;
if (BarsInProgress == 0){
i = CurrentBar;
// LTTR = CalcRSI();
return;
}
if (BarsInProgress == 1 ) {
i = CurrentBar;
// LTTR = CalcRSI();
return;
}
if (BarsInProgress == 2) {
i = CurrentBar;
// LTTR = CalcRSI();
return;
}
Comment