OPEN-SOURCE SCRIPT

Stochastic Oscillator with Signals

149
//version=5
indicator("Stochastic Oscillator with Signals", overlay=true)

// Input parameters
k = input.int(14, title="%K Length")
d = input.int(3, title="%D Length")
smoothK = input.int(3, title="Smoothing")

// Calculating Stochastic Oscillator
kValue = ta.sma(ta.stoch(close, high, low, k), smoothK)
dValue = ta.sma(kValue, d)

// Overbought and Oversold levels
obLevel = 80
osLevel = 20

// Buy and Sell Conditions
buySignal = ta.crossover(kValue, dValue) and kValue < osLevel
sellSignal = ta.crossunder(kValue, dValue) and kValue > obLevel

// Plotting the Stochastic Oscillator
plot(kValue, title="%K", color=color.blue)
plot(dValue, title="%D", color=color.orange)
hline(obLevel, "Overbought", color=color.red)
hline(osLevel, "Oversold", color=color.green)

// Plot Buy and Sell Signals on Candlestick Chart
plotshape(buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy", text="Buy")
plotshape(sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell", text="Sell")

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.