
この戦略は,平均回帰の原理に基づいて,価格が移動平均から偏った状況を利用して取引決定を行う.価格が上位から上位に偏ると空売り,下位から下位に偏ると多売り,価格が移動平均に戻ると平売りする.この戦略の核心は,価格が常に平均レベルに戻ると仮定する.
平均回帰策は,統計学原理に基づく量化取引策で,価格の平均値の上下を構成して取引決定を行う.この策の論理は単純で,実行は明確だが,品種の選択とパラメータの最適化に注意する.実用的な応用では,戦略の安定性と収益性を高めるために,傾向,取引コスト,リスク管理などの要因も考慮する必要がある.要するに,平均回帰策は,量化取引の分野でよくある,深く研究に値する策である.
/*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")