I am trying to build a simple strategy for a stochastic entry/exit. I've pretty much copy-pasted the stochastic formula from the inbuilt indicator. The problem I'm having is that the long and short boolean signals seem to be having some issues.
While a cross-under with k >= 75 using a 'goshort' boolean works perfectly fine for me, when I try to evaluate a cross-over with k <= 25 using a 'golong' boolean, it causes the short signals to vanish. I am not using the 'golong' boolean in the sell entry strategy at all.
I've kept the 'golong' boolean as cross-over with k <= 75 in the below code which is not a real stochastic strategy at all but if I do that, the short signals appear fine. If I change this to k <= 25, somehow it impacts the short signals.
//@version=4
strategy("Stochastic Slow Strategy", overlay=true)
periodK = input(8, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
OverSold = 20
OverBought = 80
co = k >= d and k[1] <= d[1] ? true : false
cu = k <= d and k[1] >= d[1] ? true : false
golong=co and k <= 75? true: false // <--This is the line where I have a problem
goshort=cu and k >= 75? true: false
strategy.entry("Sell", strategy.short, comment="Sell", when=goshort==true)
strategy.entry("Buy", strategy.long, comment="Buy", when=golong==true)