
이 전략은 이동 평균 (MA), 상대적으로 강한 지수 (RSI) 및 평균 실제 파장 (ATR) 과 같은 기술적 분석 도구를 결합하여 시장의 유행 기회를 잡기 위해 고안되었습니다. 이 전략은 쌍평등 선의 교차를 통해 트렌드 방향을 판단하고 RSI 지표를 사용하여 거래 신호에 대한 동력을 필터링하며 ATR을 손실 기준으로 사용하여 위험을 제어합니다.
이 전략의 핵심은 두 개의 다른 기간의 이동 평균 ((빠른 선과 느린 선) 의 교차를 사용하여 시장의 흐름을 판단하는 것입니다. 빠른 선에서 느린 선을 통과하면 상승 추세를 나타냅니다. 전략은 다중 신호를 생성합니다. 반대로 빠른 선 아래에 느린 선을 통과하면 하향 추세를 나타냅니다. 전략은 공백 신호를 생성합니다.
거래 신호의 신뢰성을 높이기 위해, 전략은 동력 필터로 RSI 지표를 도입했다. RSI가 특정 한계 값 (예: 50) 보다 높을 때만 더 많은 포지션을 열 수 있으며, RSI가 그 한계 값보다 낮을 때만 빈 포지션을 열 수 있다.
또한, 전략은 ATR을 손실 근거로 사용하고, 최근 기간 동안의 가격 변동에 따라 스톱 포스를 동적으로 조정하여 다른 시장 상태에 적응합니다. 이러한 적응적 인 스톱 방식은 추세가 불명확할 때 신속하게 중지하고 철회를 제어 할 수 있습니다. 추세가 강할 때 더 많은 수익 공간을 제공하고 전략 수익을 높일 수 있습니다.
이 전략은 트렌드 추적과 동력 필터링의 유기적인 결합을 통해 시장의 트렌디한 기회를 포착하면서 위험을 더 잘 제어한다. 전략 논리는 명확하고 구현 및 최적화하기 쉽습니다. 그러나 실제 응용에서는 여전히 흔들림 시장 위험과 변수 위험에 주의를 기울이고 시장 특성과 자체 요구에 따라 유연하게 조정 및 최적화 전략이 필요합니다.
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend-Following Strategy with MACD and RSI Filter", overlay=true)
// Input variables
fastLength = input(12, title="Fast MA Length")
slowLength = input(26, title="Slow MA Length")
signalLength = input(9, title="Signal Line Length")
stopLossPct = input(1.0, title="Stop Loss %") / 100
rsiLength = input(14, title="RSI Length")
rsiThreshold = input(50, title="RSI Threshold")
// Moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)
// RSI
rsi = ta.rsi(close, rsiLength)
// Entry conditions with RSI filter
bullishSignal = ta.crossover(macdLine, signalLine) and rsi > rsiThreshold
bearishSignal = ta.crossunder(macdLine, signalLine) and rsi < rsiThreshold
// Calculate stop loss levels
longStopLoss = ta.highest(close, 10)[1] * (1 - stopLossPct)
shortStopLoss = ta.lowest(close, 10)[1] * (1 + stopLossPct)
// Execute trades
strategy.entry("Long", strategy.long, when=bullishSignal)
strategy.entry("Short", strategy.short, when=bearishSignal)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
strategy.exit("Exit Short", "Short", stop=shortStopLoss)
// Plotting signals
plotshape(bullishSignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bullish Signal")
plotshape(bearishSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bearish Signal")
// Plot MACD
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// Plot RSI
hline(rsiThreshold, "RSI Threshold", color=color.gray)
plot(rsi, color=color.purple, title="RSI")