
Die Strategie ist ein Handelssystem, das eine Kombination aus Bewegung der Trend-Tracking-Medien und Bewegung der Stop-Losses. Es verwendet MACD (Moving Average Convergence Spread Indicator), um die Preisbewegung zu erfassen, EMA (Index Moving Average) für die Trendbestätigung und ATR (Real Tide Range Indicator) für die Bewegung der Stop-Loss-Position. Diese mehrdimensionale Analyse ermöglicht es, die Marktchancen zeitnah zu erfassen und die Risiken effektiv zu kontrollieren.
Die Kernlogik der Strategie besteht aus drei Dimensionen:
Die Strategie baut ein vollständiges Handelssystem auf, indem sie Trendverfolgung, Dynamikanalyse und dynamische Risikokontrolle kombiniert. Ihre Hauptmerkmale sind die effektive Erfassung von Marktchancen und die dynamische Kontrolle von Handelsrisiken bei gleichzeitiger strategischer Stabilität. Obwohl es einige inhärente Risiken gibt, hat die Strategie durch vernünftige Parameter-Einstellungen und kontinuierliche Optimierung einen guten Einsatzwert.
/*backtest
start: 2024-09-25 00:00:00
end: 2025-02-19 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("MACD + ATR Dynamic Stop-Loss Strategy", overlay=true)
// Input parameters
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalSmoothing = input.int(9, title="MACD Signal Smoothing")
atrLength = input.int(14, title="ATR Length")
stopLossMultiplier = input.float(1.0, title="Stop-Loss ATR Multiplier")
useTrailingStop = input.bool(true, title="Use Trailing Stop")
trailATRMultiplier = input.float(2.0, title="Trailing Stop ATR Multiplier")
emaLength = input.int(20, title="EMA Length")
// Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalSmoothing)
// Calculate ATR
atr = ta.atr(atrLength)
// Calculate 20-period EMA
ema20 = ta.ema(close, emaLength)
// Entry Conditions
buyCondition = ta.crossover(macdLine, signalLine) and close > ema20
sellCondition = ta.crossunder(macdLine, signalLine)
// Plot Buy and Sell Signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Dynamic Stop-Loss and Trailing Stop Logic
var float stopLossLevel = na
var float trailingStopLevel = na
if (buyCondition)
stopLossLevel := close - atr * stopLossMultiplier
trailingStopLevel := close - atr * trailATRMultiplier
if (strategy.position_size > 0)
if (useTrailingStop)
trailingStopLevel := math.max(trailingStopLevel, close - atr * trailATRMultiplier)
stopLossLevel := trailingStopLevel
strategy.exit("Trailing Stop", stop=stopLossLevel)
// Execute Trades
if (buyCondition)
strategy.entry("Long", strategy.long)
if (sellCondition)
strategy.close("Long")
// Plot Stop-Loss Level
plot(stopLossLevel, title="Stop-Loss Level", color=color.red, linewidth=1, style=plot.style_linebr)