//version=5
strategy("Simple Moving Average Crossover", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Input periode untuk moving average
short_period = input.int(9, title="Short MA Period", minval=1)
long_period = input.int(21, title="Long MA Period", minval=1)

// Menghitung Moving Averages
short_ma = ta.sma(close, short_period)
long_ma = ta.sma(close, long_period)

// Sinyal buy dan sell
buy_signal = ta.crossover(short_ma, long_ma)
sell_signal = ta.crossunder(short_ma, long_ma)

// Plot garis MA pada chart
plot(short_ma, color=color.blue, title="Short MA")
plot(long_ma, color=color.red, title="Long MA")

// Entry dan exit rules
if (buy_signal)
strategy.entry("Buy", strategy.long)

if (sell_signal)
strategy.exit("Sell", from_entry="Buy")

// Visualisasi sinyal buy dan sell pada chart
plotshape(series=buy_signal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sell_signal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Fundamental AnalysisTechnical IndicatorsTrend Analysis

Penafian