
移動平均追跡策略は,単純移動平均に基づいてトレンド追跡策略である.この策略は,200日間の長さのシンプル移動平均を使用して,価格のトレンド方向を判断し,価格が移動平均の上を通るときに多行し,価格が移動平均を下を通るときに空きをして,トレンドの追跡を実現する.
この戦略は以下の原則に基づいています.
この戦略は主に移動平均によってトレンドの方向を判断し,均線が転じるときにタイムリーに反転操作を行い,トレンドを追跡して利益を得る.
この戦略の利点は以下の通りです.
この戦略にはいくつかのリスクがあります.
リスクに合わせて,以下のような面で最適化や改善を行うことができます.
この戦略は,以下の点でさらに最適化できます.
移動平均の周期パラメータを最適化して,最適なパラメータの組み合わせを探します. ウォーク・フォワード・アナリストなどのパラメータ最適化方法を使用できます.
短期移動平均を追加し,多平均線戦略を形成し,長期の短期的なトレンドを追跡する.
MACDなどのトレンド指数と組み合わせることで,トレンド転換を識別する能力を向上させる.
ストップ・メカニズムの加入,例えば,ストップ・トラッキング,ストップ・リストの設置など,単一損失を制御する.
複製テストを行い,異なる品種と異なる時期で戦略をテストし,安定性を向上させる.
戦略のパラメータ自在化と戦略の最適化を実現するために,機械学習などの方法を使用します.
移動平均線追跡戦略は,シンプルで実用的なトレンド追跡戦略であり,アイデアは明確で,実行しやすい.トレンドの機会を捉えることができる.しかし,この戦略には,短期的な調整に無感性,リスク管理能力が弱いなどのいくつかの問題があります.我々は,多くの点で最適化して,戦略をより堅牢に,パラメータをより最適化して,リスク管理をより完善にすることができます.全体的に,移動平均線追跡戦略は,良い応用価値があり,量化取引の重要な戦略思考です.
/*backtest
start: 2023-09-19 00:00:00
end: 2023-10-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("MA X 200 BF", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.0)
/////////////// Time Frame ///////////////
testStartYear = input(2012, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay, 0, 0)
testStopYear = input(2019, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay, 0, 0)
testPeriod() => true
///////////// MA 200 /////////////
slowMA = sma(close, input(200))
/////////////// Strategy ///////////////
long = close > slowMA
short = close < slowMA
last_long = 0.0
last_short = 0.0
last_long := long ? time : nz(last_long[1])
last_short := short ? time : nz(last_short[1])
long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)
/////////////// Execution ///////////////
if testPeriod()
strategy.entry("Long Entry", strategy.long, when=long_signal)
strategy.entry("Short Entry", strategy.short, when=short_signal)
strategy.exit("Long Ex", "Long Entry")
strategy.exit("Short Ex", "Short Entry")
/////////////// Plotting ///////////////
plot(slowMA, color = long ? color.lime : color.red, linewidth=2)
bgcolor(strategy.position_size > 0 ? color.lime : strategy.position_size < 0 ? color.red : color.white, transp=80)
bgcolor(long_signal ? color.lime : short_signal ? color.red : na, transp=30)