Well, I've never tried TimePeriod=0 in MaxVal or MinVal, and don't see that there's any default in the manual. With TimePeriod=0, won't HighATR and LowATR always be 0? Have you tried any debug printf's to see what's going on?

Do you want the Max and Min over the 14? So it should be HighATR=MaxVal(StopCal,14) and similarly for LowATR?