The Market State Indicator was created by John Ehlers (Stocks & Commodities V. 38:06 (8–15)) and this is technically part of three indicators in one so I'm splitting each one to a separate script. This particular indicator was designed for the market state which acts as a trend direction and tells you whether the trend is strong in either direction. Keep in mind that when the indicator rapidly switches then the market is choppy and when it is a steady line then it is a very strong trend. Essentially buy when the indicator line is green and sell when it is red.
Let me know if you would like me to publish other scripts or if you want something custom done!
Note: I'm republishing this because the original script couldn't be found in searches so this will fix that.