
Chiến lược này dựa trên nguyên tắc quay trở lại giá trị trung bình, sử dụng các trường hợp giá lệch khỏi đường trung bình di chuyển để đưa ra quyết định giao dịch. Khi giá lệch lên từ đường lên, hãy làm cho nó trống rỗng, khi giá lệch xuống từ đường xuống, hãy làm nhiều hơn, khi giá quay trở lại đường trung bình di chuyển.
Chiến lược quay trở trung bình là một chiến lược giao dịch định lượng dựa trên các nguyên tắc thống kê, đưa ra quyết định giao dịch bằng cách xây dựng giá trị trung bình lên và xuống. Lập luận của chiến lược đơn giản, thực hiện rõ ràng, nhưng hãy chú ý đến lựa chọn và tối ưu hóa các tham số của giống. Trong ứng dụng thực tế, cũng cần xem xét các yếu tố như xu hướng, chi phí giao dịch, kiểm soát rủi ro để nâng cao sự ổn định và lợi nhuận của chiến lược. Nói tóm lại, chiến lược quay trở trung bình là một chiến lược phổ biến và đáng nghiên cứu sâu sắc trong lĩnh vực giao dịch định lượng.
/*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")