I have written the following function to calculate the
drawdown between two dates. Does anybody know how eliminate the loop or
make it
run faster? TIA
function
MaxDDFromTo(Array, From, To)
{
Last = LastValue(BarIndex());
Start = LastValue(ValueWhen(DateTime()
== StrToDateTime(From),
BarIndex()));
End = LastValue(ValueWhen(DateTime()
== StrToDateTime(To),
BarIndex()));
Price = Array;
MaxPrice = DD = MaxD = Bars = 0;
for(
i = Start; i < End; i++ )
{
Bars = Bars + 1;
MaxPrice = Max(MaxPrice,
HHV( Price, Bars
));
DD = 100
* ( Price[i] - MaxPrice ) / MaxPrice;
MaxD = Min(MaxD,
LLV( DD, Bars ));
}
return
MaxD;
}
_TRACE("from:
" + "12/29/2000"
+ " To: " + "12/31/2009"
+ " MaxDD: " +
MaxDDFromTo(C, "12/29/2000",
"12/31/2009") );