
이 전략은 선형 회귀선과 이동 평균을 기반으로 간단한 트렌드 추적 거래 시스템을 설계했다. 선형 회귀선 위에 이동 평균을 통과할 때 더하고, 선형 회귀선 아래에 이동 평균을 통과할 때 공백을했다. 동시에 선형 회귀선의 기울기를 결합하여 일부 거래 신호를 필터링하고, 트렌드 방향이 일치했을 때만 출전한다.
Trend Following Regression Trading Strategy (트렌드 추적 회귀 거래 전략)
이 전략은 다음과 같은 핵심 요소들을 포함하고 있습니다.
선형 회귀선은 최근 기간 동안의 트렌드 방향에 잘 적합합니다. 이것은 전체 트렌드의 방향을 판단하는 데 도움이 될 수 있습니다. 가격이 SMA 라인을 돌파 할 때, 우리는 선형 회귀선의 방향이 그 돌파구와 일치하는지 여부를 추가로 판단해야합니다. 두 가지 방향이 일치 할 때만 거래 신호가 생성됩니다. 이것은 일부 가짜 돌파구를 필터링 할 수 있습니다.
또한, 전략은 손실을 중지하는 장치를 설정합니다. 가격이 중지 라인을 만질 때, 평소 위치 손실을 중지합니다. 또한, 중지 라인을 설정하여 수익의 일부를 잠금합니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
이러한 위험들에 대해, 우리는 다음과 같은 몇 가지 측면에서 최적화할 수 있습니다:
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
이 전략은 이동 평균의 트렌드 추적 기능과 선형 회귀의 트렌드 판단 기능을 통합하여 비교적 간단하고 쉬운 트렌드 추적 거래 시스템을 형성한다. 트렌드가 뚜렷한 시장에서 이 전략은 더 나은 효과를 얻을 수 있다. 또한 우리는 파라미터와 규칙에 대한 많은 피드백과 최적화를 수행하고 위험을 잘 제어해야 하며, 이 전략은 안정적인 투자 수익을 얻을 수 있어야 한다.
/*backtest
start: 2023-11-17 00:00:00
end: 2023-12-05 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="Regression Trading Strategy", shorttitle="RTS", overlay=true)
// Input parameters
n = input(14, title="SMA Period")
stop_loss_percentage = input(2, title="Stop Loss Percentage")
take_profit_percentage = input(2, title="Take Profit Percentage")
// Calculate the SMA
sma = sma(close, n)
// Linear regression function
linear_regression(src, length) =>
sumX = 0.0
sumY = 0.0
sumXY = 0.0
sumX2 = 0.0
for i = 0 to length - 1
sumX := sumX + i
sumY := sumY + src[i]
sumXY := sumXY + i * src[i]
sumX2 := sumX2 + i * i
slope = (length * sumXY - sumX * sumY) / (length * sumX2 - sumX * sumX)
intercept = (sumY - slope * sumX) / length
line = slope * length + intercept
line
// Calculate the linear regression
regression_line = linear_regression(close, n)
// Plot the SMA and regression line
plot(sma, title="SMA", color=color.blue)
plot(regression_line, title="Regression Line", color=color.red)
// Trading strategy conditions
long_condition = crossover(close, sma) and close > regression_line
short_condition = crossunder(close, sma) and close < regression_line
// Exit conditions
stop_loss_price = close * (1 - stop_loss_percentage / 100)
take_profit_price = close * (1 + take_profit_percentage / 100)
// Plot entry and exit points on the chart
plotshape(series=long_condition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=short_condition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
plotshape(series=crossunder(close, stop_loss_price), title="Stop Loss", location=location.abovebar, color=color.red, style=shape.labeldown, text="SL")
plotshape(series=crossover(close, take_profit_price), title="Take Profit", location=location.belowbar, color=color.green, style=shape.labelup, text="TP")
// Strategy orders
strategy.entry("Long", strategy.long, when = long_condition)
strategy.entry("Short", strategy.short, when = short_condition)
strategy.exit("Exit", from_entry = "Long", when = crossover(close, stop_loss_price) or crossover(close, take_profit_price))
strategy.exit("Exit", from_entry = "Short", when = crossunder(close, stop_loss_price) or crossunder(close, take_profit_price))