Price = C;
MaxPrice = Highest(Price);
BIR = IIf(Status("BarInRange") > 0, 1, 0);
CurDD =
IIf(BIR, 100 * (MaxPrice -
Price) / MaxPrice, 0);
MaxPriceDate =
IIf(BIR,ValueWhen(MaxPrice !=
Ref(MaxPrice,1),DateTime(),0),0);
MaxDD = Highest(CurDD);
RCurDD =
round(CurDD * 100) / 100;
MaxDD = Highest(CurDD);
MaxDDDate =
ValueWhen(MaxDD != Ref(MaxDD,-1),DateTime(),0);
RMaxDD =
round(MaxDD * 100) / 100;
SqrDD = CurDD ^
2;
CumDD = Cum(SqrDD);
MDD =
MaxDD==LastValue(MaxDD) AND CurDD==MaxDD;
MDDBar =
ValueWhen(MDD,BarIndex(),1);
CDDBar =
Cum(0);
CDD0 = LastValue(Highest(IIf(MDD == 1, BarIndex() - BarsSince(CurDD == 0), 0)));
CDDBar[CDD0] = 1;
MaxDDDate =
ValueWhen(MDD==1,DateTime(),1);