
이 전략은 평균 회귀의 원칙에 기초하여, 가격이 이동 평균에서 벗어난 경우를 사용하여 거래 결정을 내립니다. 가격이 상향으로 이동 할 때 공백을하고, 하향으로 이동 할 때 더 많이하고, 가격이 이동 평균으로 돌아가는 경우 평점입니다. 이 전략의 핵심은 가격이 항상 평균 수준으로 돌아간다는 가정입니다.
평균 회귀 전략은 수학적 원리에 기반한 정량 거래 전략으로 가격의 평균 회귀를 구축하여 거래 결정을 내린다. 이 전략의 논리는 간단하고 명확하게 실행되지만 품종의 선택과 매개 변수의 최적화에 주의를 기울여야 한다. 실제 응용에서는 전략의 안정성과 수익성을 높이기 위해 추세, 거래 비용, 위험 제어 등의 요소를 고려해야 한다.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Mean Regression Strategy", overlay=true)
// Define the lookback period for the moving average
length = input.int(20, title="Moving Average Length")
mult = input.float(1.5, title="Standard Deviation Multiplier")
// Calculate the moving average and standard deviation
ma = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
// Calculate upper and lower bands
upper_band = ma + dev
lower_band = ma - dev
// Plot the moving average and bands
plot(ma, color=color.blue, linewidth=2, title="Moving Average")
plot(upper_band, color=color.red, linewidth=2, title="Upper Band")
plot(lower_band, color=color.green, linewidth=2, title="Lower Band")
// Entry conditions
long_condition = ta.crossover(close, lower_band)
short_condition = ta.crossunder(close, upper_band)
// Exit conditions
exit_long_condition = ta.crossunder(close, ma)
exit_short_condition = ta.crossover(close, ma)
// Strategy orders
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
if (exit_long_condition)
strategy.close("Long")
if (exit_short_condition)
strategy.close("Short")
// Plot signals on the chart
plotshape(series=long_condition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=short_condition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")