I have coded the following to get strategy results that go long when k is in the overbought area and crossed d and the opposite for shorting.
More details added within the code comment.
//@version=5
strategy("Stochastic Strategy", overlay=true)
//Stochastic Inputs
length = input.int(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
//Rule to define crossover /crossunder
co = ta.crossover(k,d)
cu = ta.crossunder(k,d)
if (not na(k) and not na(d))
//code to define if k is in overbought zone and k crossover d and enter a long trade
if (co and k < OverSold)
strategy.entry("StochLE", strategy.long, comment="StochLE")
//code to define if k is in oversold zone and k crossunder d and enters a short trade
if (cu and k > OverBought)
strategy.entry("StochSE", strategy.short, comment="StochSE")