Use the "Formula Profiler" in MetaStock 14 and above. It tells you exactly which line of your code is slowing down the scan.