vars StopCal = series(ATR(14));
var HighATR = MaxVal(StopCal,14);
var LowATR = MinVal(StopCal,14);
but why add .25 of the difference between high and low atr values to the gap between price and sma:
(HighATR-LowATR)*.25
Not sure what this adds to your stop & trail, it's likely to be a very small % of ATR.