I have a supertrend AFL formula in loop can any expert help in converting it into array:
function SuperTrend(lenATR, width)
{
nATR = ATR(lenATR);
pAvg = (H+L) / 2;
upperBand = pAvg + width * nATR;
lowerBand = pAvg - width * nATR;
isUpTrend = True;
dn = DateNum();
for (i=lenATR; i<BarCount; ++i)
{
if (C > upperBand[i-1])
isUpTrend = True;
else if (C < lowerBand[i-1])
isUpTrend = False;
else
isUpTrend = isUpTrend[i-1];
if (isUpTrend)
lowerBand = Max(lowerBand, lowerBand[i-1]);
else
upperBand = Min(upperBand, upperBand[i-1]);
}
super = IIf(isUpTrend, lowerBand, upperBand);
return super;
}
st = SuperTrend(10,3);
Thanks.
function SuperTrend(lenATR, width)
{
nATR = ATR(lenATR);
pAvg = (H+L) / 2;
upperBand = pAvg + width * nATR;
lowerBand = pAvg - width * nATR;
isUpTrend = True;
dn = DateNum();
for (i=lenATR; i<BarCount; ++i)
{
if (C > upperBand[i-1])
isUpTrend = True;
else if (C < lowerBand[i-1])
isUpTrend = False;
else
isUpTrend = isUpTrend[i-1];
if (isUpTrend)
lowerBand = Max(lowerBand, lowerBand[i-1]);
else
upperBand = Min(upperBand, upperBand[i-1]);
}
super = IIf(isUpTrend, lowerBand, upperBand);
return super;
}
st = SuperTrend(10,3);
Thanks.