How to write algo for Stoch Crossover System?

How to write algo for Stoch Crossover System?

Condition:
Stochastic is an oscillator that measures the position of a stock compared with its recent trading range indicating overbought OR oversold conditions. It displays current Day price at a percentage relative to it’s trading range over the specified period of time. In a Slow Stochastic, the highs AND lows are averaged over a slowing period. The default is usually 3 for slow AND 1 for fast. The line can then be smoothed using an exponential moving average, Weighted, OR simple moving average. Confirming Buy/Sell signals can be read at intersections of the %D with the %K as well.
The Stochastic Oscillator always ranges between 0% AND 100%.
• A reading of 0% shows that the security’s Close was the Lowest price that the security has traded during the preceding x-time periods.
• A reading of 100% shows that the security’s Close was the Highest price that the security has traded during the preceding x-time periods.
• When the closing price is near the top of the recent trading range (above 80%), the security is in an overbought condition AND may Signal for a possible correction.
• Oversold condition exists at a point below %20. The security is in an oversold condition AND may Signal for a possible upmove.
• Whenever stoch makes a crossover we will initiate the trades accordingly.