//@version=5
strategy("Gold Trading Strategy", overlay=true)

// Input parameters
k_period = input(14, title="Stochastic %K Period")
d_period = input(3, title="Stochastic %D Period")
smooth_k = input(3, title="Stochastic Smoothing")

sma_50 = ta.sma(close, 50)
sma_200 = ta.sma(close, 200)

= ta.stoch(k_period, d_period, smooth_k)

// Buy condition
buy_condition = ta.crossover(k, d) and k < 20 and close > sma_50 and close > sma_200
if (buy_condition)
strategy.entry("Buy", strategy.long)

// Sell condition
sell_condition = ta.crossunder(k, d) and k > 80 and close < sma_50 and close < sma_200
if (sell_condition)
strategy.entry("Sell", strategy.short)

// Plotting
plot(sma_50, color=color.blue, title="SMA 50")
plot(sma_200, color=color.red, title="SMA 200")
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.