These two studies are based on the standard ones: Profitable_Closes_LX and Profitable_Closes_SX. I inverted the logic and cleaned up the code, as the original seemed to have been written by an alien from Mars. There's a weird tenancy in the standard code to over-use variable objects and handle logic backwards, as well as to not utilize some handy standard library functions like Math.Sign.
I wanted this code for some momentum strategies I am working on. I want them to be cowardly. As soon as they start taking a beating, I want them to close all positions.