Maybe, this question was asked previously and I have also searched the thread but without much success. A help would be appreciated.
I would like to calculate only the Daily Range, for that I need to know the High and Low price. I'm writing the following code and trying two methods. Which one is more efficient? I find Range function is cleaner but throws an error. Am I doing something wrong?
for (int Loop = 1; Loop <= 10; Loop++) {
if (Bars.GetDayBar(Loop) != null) {
if (Bars.GetDayBar(Loop).High > Bars.GetDayBar(Loop).Low) { //bear day
_ADR = Bars.GetDayBar(Loop).High - Bars.GetDayBar(Loop).Low;
}
elseif (Bars.GetDayBar(Loop).High < Bars.GetDayBar(Loop).Low) { //bull day
_ADR = Bars.GetDayBar(Loop).Low - Bars.GetDayBar(Loop).High;
}
_DebugStr = "#" + Loop.ToString() + " Date: " + Bars.GetDayBar(Loop).Time.ToString("DD-MMM-YYYY") + " High:" + Bars.GetDayBar(Loop).High.ToString() +
" Low:" + Bars.GetDayBar(Loop).Low.ToString();
Print(_DebugStr);
_DebugStr = Range(Closes[1])[Loop].ToString();
//throws an error Error on calling 'OnBarUpdate' method for indicator 'IndicatorName' on bar 24: Index was outside the bounds of the array.
Print(_DebugStr);
}
}
Also, I would like to know about the possibility of writing some code based on Session Change instead of OnBarUpdate() event? Because, my calculation is based on Daily Bar and I doesn't need to calculate on every tick. If this is not possible any other ideas would be appreciated. I may be plotting this indicator on 5 minute chart or 1 minute.
Cheers
YFx
Comment