Not able to add this to my AMI...
You can't add this to AMI. It is not AFL.
Below is the AFL for the same.
sZPeriod = Param("Period", 9, 2, 50, 1);
sZK = Param("Coefficient", 3, 0.1, 5, 0.1);
sZHold = Param("Hold Period", 3, 0, 10, 1);
//SafeZone stop calculation for Long
lowDelta = IIf(Ref(L,-1) < Ref(L,-2), Ref(L,-2) - Ref(L,-1), 0);
lowDeltaSum = Sum(lowDelta, sZPeriod);
LowDeltaCount = Sum(Ref(L,-1) < Ref(L,-2), sZPeriod);
sZPoint = Ref(L,-1) - sZK * IIf(LowDeltaCount != 0, lowDeltaSum / LowDeltaCount, 0);
sZStop = HHV(sZPoint, sZHold);
Plot (sZStop,"SafeZone Long Stop",colorRed,styleDashed);
//SafeZone stop calculation for Short
highDelta = IIf(Ref(H,-1) > Ref(H,-2), Ref(H,-1) - Ref(H,-2), 0);
highDeltaSum = Sum(highDelta, sZPeriod);
HighDeltaCount = Sum(Ref(H,-1) > Ref(H,-2), sZPeriod);
sZPoint = Ref(H,-1) + sZK * IIf(HighDeltaCount != 0, highDeltaSum / HighDeltaCount, 0);
sZStop = LLV(sZPoint, sZHold);
Plot (sZStop,"SafeZone Short Stop",colorRed,styleDashed);