OPEN-SOURCE SCRIPT
MA Crossover Strategy V6

//version=6
strategy("MA Crossover Strategy V6", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === Inputs ===
shortLength = input.int(9, title="Short MA Length", minval=1)
longLength = input.int(21, title="Long MA Length", minval=1)
useEMA = input.bool(false, title="Use EMA Instead of SMA")
// === Moving Averages ===
shortMA = useEMA ? ta.ema(close, shortLength) : ta.sma(close, shortLength)
longMA = useEMA ? ta.ema(close, longLength) : ta.sma(close, longLength)
// === Plot MAs ===
plot(shortMA, color=color.orange, title="Short MA", linewidth=2)
plot(longMA, color=color.blue, title="Long MA", linewidth=2)
// === Entry Conditions ===
longCondition = ta.crossover(shortMA, longMA)
shortCondition = ta.crossunder(shortMA, longMA)
// === Strategy Logic ===
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// === Optional: Plot Buy/Sell Signals ===
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
strategy("MA Crossover Strategy V6", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === Inputs ===
shortLength = input.int(9, title="Short MA Length", minval=1)
longLength = input.int(21, title="Long MA Length", minval=1)
useEMA = input.bool(false, title="Use EMA Instead of SMA")
// === Moving Averages ===
shortMA = useEMA ? ta.ema(close, shortLength) : ta.sma(close, shortLength)
longMA = useEMA ? ta.ema(close, longLength) : ta.sma(close, longLength)
// === Plot MAs ===
plot(shortMA, color=color.orange, title="Short MA", linewidth=2)
plot(longMA, color=color.blue, title="Long MA", linewidth=2)
// === Entry Conditions ===
longCondition = ta.crossover(shortMA, longMA)
shortCondition = ta.crossunder(shortMA, longMA)
// === Strategy Logic ===
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// === Optional: Plot Buy/Sell Signals ===
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.