
이 전략은 여러 기술 지표들을 결합한 트렌드 추적 거래 시스템이다. RSI (대비적으로 강한 지표), MACD (이동 평균 동향 분산), SMA (단순 이동 평균) 와 같은 여러 기술 지표를 통합하여 시장 추세가 명확할 때 거래한다. 전략은 또한 더 나은 자금 관리를 위해 스톱, 스톱 손실 및 스톱 손실 추적과 같은 위험 관리 메커니즘을 포함한다.
이 전략은 다음과 같은 핵심 조건에 따라 거래됩니다.
위의 조건이 동시에 충족되면, 시스템은 여러 신호를 낸다. 동시에, 전략은 5%의 중지 목표, 3%의 중지 손실 제한, 그리고 2%의 추적 중지 손실을 설정하여 이미 얻은 이익을 보호한다. 이러한 다층 거래 조건 디자인은 거래의 정확성과 안전을 높이는 데 도움이됩니다.
이 전략은 여러 기술 지표의 조합 사용으로 비교적 완벽한 거래 시스템을 구축한다. 그것은 트렌드 추적의 핵심 논리를 포함 할뿐만 아니라 위험 관리의 고려사항을 통합한다. 최적화가 필요한 일부 지역이 있지만 전체 프레임 워크는 좋은 확장성과 적응력을 가지고 있다. 전략의 성공적인 사용은 실제 시장 상황에 따라 거래자가 변수 최적화와 전략 개선을 필요로한다.
/*backtest
start: 2024-12-03 00:00:00
end: 2024-12-10 00:00:00
period: 45m
basePeriod: 45m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Flexible Swing Trading Strategy with Trailing Stop and Date Range", overlay=true)
// Input parameters
rsiPeriod = input.int(14, title="RSI Period")
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalSmoothing = input.int(9, title="MACD Signal Smoothing")
smaShortPeriod = input.int(20, title="Short-term SMA Period")
smaLongPeriod = input.int(50, title="Long-term SMA Period")
takeProfitPercent = input.float(5.0, title="Take Profit Percentage")
stopLossPercent = input.float(3.0, title="Stop Loss Percentage")
trailingStopPercent = input.float(2.0, title="Trailing Stop Percentage")
// Date range inputs
startDate = input(timestamp("2023-01-01 00:00"), title="Start Date")
endDate = input(timestamp("2023-12-31 23:59"), title="End Date")
// Calculate RSI
rsi = ta.rsi(close, rsiPeriod)
// Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalSmoothing)
// Calculate SMAs
smaShort = ta.sma(close, smaShortPeriod)
smaLong = ta.sma(close, smaLongPeriod)
// Buy condition
buyCondition = ta.crossover(macdLine, signalLine) and rsi < 70 and close > smaShort and smaShort > smaLong
// Execute buy orders within the date range
if (buyCondition )
strategy.entry("Buy", strategy.long)
// Calculate take profit and stop loss levels
takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPercent / 100)
stopLossLevel = strategy.position_avg_price * (1 - stopLossPercent / 100)
// Set take profit, stop loss, and trailing stop
strategy.exit("Take Profit", "Buy", limit=takeProfitLevel)
strategy.exit("Stop Loss", "Buy", stop=stopLossLevel)
strategy.exit("Trailing Stop", "Buy", trail_price=close * (1 - trailingStopPercent / 100), trail_offset=trailingStopPercent / 100)
// Plot Buy signals
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
// Plot SMAs
plot(smaShort, color=color.blue, title="20 SMA")
plot(smaLong, color=color.red, title="50 SMA")
// Plot MACD and Signal Line
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// Plot RSI
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
plot(rsi, color=color.purple, title="RSI")
// Debugging plots
plotchar(buyCondition , char='B', location=location.belowbar, color=color.green, size=size.small)
plotchar(strategy.opentrades > 0, char='T', location=location.abovebar, color=color.blue, size=size.small)
plot(stopLossLevel, color=color.red, title="Stop Loss Level")
plot(takeProfitLevel, color=color.green, title="Take Profit Level")