OPEN-SOURCE SCRIPT

Valtoro Adaptive Momentum

139
//version=5
strategy("Valtoro Adaptive Momentum", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === Inputs ===
lengthFast = input.int(14, title="Fast EMA")
lengthSlow = input.int(28, title="Slow EMA")
rsiPeriod = input.int(14, title="RSI Period")
atrPeriod = input.int(14, title="ATR Period")
riskMultiplier = input.float(1.5, title="Volatility Threshold Multiplier", step=0.1)
rsiOB = input.int(70, title="RSI Overbought")
rsiOS = input.int(30, title="RSI Oversold")

// === Indicators ===
fastEMA = ta.ema(close, lengthFast)
slowEMA = ta.ema(close, lengthSlow)
rsi = ta.rsi(close, rsiPeriod)
atr = ta.atr(atrPeriod)
avgATR = ta.sma(atr, atrPeriod)

// === Conditions ===
longCond = ta.crossover(fastEMA, slowEMA) and rsi < rsiOB and atr > avgATR * riskMultiplier
shortCond = ta.crossunder(fastEMA, slowEMA) and rsi > rsiOS and atr > avgATR * riskMultiplier

// === Risk Management ===
longSL = close * 0.98 // 2% Stop Loss
longTP = close * 1.05 // 5% Take Profit
shortSL = close * 1.02
shortTP = close * 0.95

// === Strategy Entries and Exits ===
if (longCond)
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)

if (shortCond)
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)

// === Visuals ===
plot(fastEMA, title="Fast EMA", color=color.blue)
plot(slowEMA, title="Slow EMA", color=color.red)
hline(rsiOB, "RSI Overbought", color=color.red)
hline(rsiOS, "RSI Oversold", color=color.green)

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。