OPEN-SOURCE SCRIPT

MA Crossover Strategy V6

107
//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)

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.