
平均回帰突破策は,典型的なトレンドを追跡する量化取引策である.この策は,移動平均と標準差チャネルを使用して,市場の動きを判断し,価格が標準差チャネルを破るときに取引シグナルを生成する.
この戦略は,まず,N日 (デフォルト50日) のシンプル移動平均SMAを計算し,その後,SMAをベースに,この周期の価格の標準差StdDevを計算します. 中央軸はSMAで,上下はStdDevの2倍で,上下軌を構成する標準差チャネルです. 上向きに走る時,空を空にする. 下向きに走る時,多めにする.
市場に入ると,戦略はストップ・ロスの位置を設定する.具体的には,オーバーの後に,ストップ・ロスのラインは,入場時の閉店価格の ((100 - ストップ・ロスのパーセント);空白の後に,ストップ・ホールドラインは,入場時の閉店価格の ((100 + ストップ・ホールドのパーセント) になる.
この戦略の利点は以下の通りです.
この戦略にはいくつかのリスクがあります.
リスクに対応する解決策は以下の通りです.
この戦略をさらに改善する余地があります.
複数の時間周期の均線を用いて検証し,曲線を過度に敏感にしない.
MACDなどの他の指標と組み合わせた判断傾向と偏差現象.
機械学習アルゴリズムの動的最適化パラメータを導入する.
均線回帰突破戦略は全体的に非常に実用的な量化取引戦略である. それは,トレンドを追跡し,撤回を制御する利点を持ち,単純に,量化取引の必要性に適した実現する. 同時に,いくつかのパラメータ選択と止損設定の問題にも注意する必要がある. 多時間軸分析とパラメータ最適化と組み合わせて,より良い戦略パフォーマンスを得ることができる.
/*backtest
start: 2023-02-16 00:00:00
end: 2024-02-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Standard Deviation Bands with Buy/Sell Signals", overlay=true)
// Input for the number of standard deviations
deviationMultiplier = input.float(2.0, title="Standard Deviation Multiplier")
// Input for the length of the moving average
maLength = input.int(50, title="Moving Average Length")
// Input for the stop loss percentage
stopLossPercentage = input.float(12, title="Stop Loss Percentage")
// Calculate the moving average
sma = ta.sma(close, maLength)
// Calculate the standard deviation of the price
priceDeviation = ta.stdev(close, maLength)
// Calculate the upper and lower bands
upperBand = sma + (priceDeviation * deviationMultiplier)
lowerBand = sma - (priceDeviation * deviationMultiplier)
// Plot the bands
plot(upperBand, color=color.green, title="Upper Band")
plot(lowerBand, color=color.red, title="Lower Band")
// Plot the moving average
plot(sma, color=color.blue, title="SMA", linewidth=2)
// Buy Signal
buyCondition = ta.crossover(close, lowerBand)
sellCondition = ta.crossunder(close, upperBand)
// Calculate stop loss level
stopLossLevelBuy = close * (1 - stopLossPercentage / 100)
stopLossLevelSell = close * (1 + stopLossPercentage / 100)
// Create Buy and Sell Alerts
alertcondition(buyCondition, title="Buy Signal", message="Buy Signal - Price Crossed Below Lower Band")
alertcondition(sellCondition, title="Sell Signal", message="Sell Signal - Price Crossed Above Upper Band")
// Plot Buy and Sell Arrows on the chart
plotshape(buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green, title="Buy Signal Arrow")
plotshape(sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red, title="Sell Signal Arrow")
// Exit Long and Short Positions
var float stopLossBuy = na
var float stopLossSell = na
if ta.crossover(close, sma)
stopLossBuy := stopLossLevelBuy
if ta.crossunder(close, sma)
stopLossSell := stopLossLevelSell
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.exit("Stop Loss/Take Profit Buy", from_entry = "Buy", stop = stopLossBuy)
strategy.entry("Sell", strategy.short, when = sellCondition)
strategy.exit("Stop Loss/Take Profit Sell", from_entry = "Sell", stop = stopLossSell)