I'm trying to calculate the average daily range of the last 10 days without weekend data and display it on a non daily time frame.
This is my code. Any ideas what is wrong? I've loaded 50 days of M5 data. The indicator displays only the current day's range.
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
Add(PeriodType.Day,1);
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= 15 || CurrentBars[1] <= 15) return;
int i, c = 0;
double hi = 0, lo = 0, sum = 0;
for (i=1; i>=15; i++)
{
hi = Highs[1][i];
lo = Lows[1][i];
if (Times[1][i].DayOfWeek == DayOfWeek.Saturday || Times[1][i].DayOfWeek == DayOfWeek.Sunday) continue;
else
{
sum = sum + (hi - lo);
c++;
if (c>=10) break;
}
}
hi = CurrentDayOHL().CurrentHigh[0];
lo = CurrentDayOHL().CurrentLow[0];
if (i>0)
{
string objtext = "ADR = " + (sum/c/TickSize).ToString("N1") + " (" + c + " days) Today = " + ((hi-lo)/TickSize).ToString("N1");
DrawTextFixed("ADR", objtext, TextPosition.TopLeft);
}
}
Comment