Squeeze and Stoch
Squeeze and Stoch
Squeeze and Stoch
// Squeeze Conditions
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC) // Squeeze is on
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC) // Squeeze is off
noSqz = not sqzOn and not sqzOff // No Squeeze
// Momentum Calculation
highAvg = highest(high, lengthKC)
lowAvg = lowest(low, lengthKC)
avgHighLow = avg(highAvg, lowAvg)
smaClose = sma(close, lengthKC)
avgValue = avg(avgHighLow, smaClose)
sourceMinusAvg = source - avgValue
val = linreg(sourceMinusAvg, lengthKC, 0)
// Squeeze Colors
bcolor = valScaled > 0 ?
(valScaled > nz(valScaled[1]) ? color.green : color.new(color.green,
50)) :
(valScaled < nz(valScaled[1]) ? color.red : color.new(color.red, 50))
scolor = noSqz ? color.blue : (sqzOn ? color.black : color.gray)
// Stochastic Calculation
k = sma(stoch(close, high, low, kLength), smoothK)
d = sma(k, dLength)
// Stochastic Plots
hline(stochOverbought, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(stochOversold, "Oversold", color=color.green, linestyle=hline.style_dashed)
plot(k, color=color.blue, linewidth=2, title="%K")
plot(d, color=color.orange, linewidth=2, title="%D")