2つの移動平均のクロスオーバー戦略

作者: リン・ハーンチャオチャン, 日付: 2023-11-22 16:10:21
タグ:

img

概要

これは,移動平均指標に基づいた単純な定量的な取引戦略である.入口と出口信号を決定するために,高速および遅い移動平均の黄金十字と死亡十字を使用する.高速MAが下からゆっくりとしたMAを超えると,購入信号が生成される.高速MAが上からゆっくりとしたMAを下に突破すると,販売信号が生成される.

戦略の論理

この戦略は主に移動平均値のトレンドトラッキング能力を活用している.速いMAは小さいパラメータを持ち,価格変化に迅速に対応できる.遅いMAはより大きなパラメータを持ち,長期的なトレンドを表している.遅いMAの上の速いMAは短期的な動きの逆転と上昇傾向の開始をシグナルする.遅いMAの下の速いMAはダウントレンドへの逆転をシグナルする.これらのシグナルをキャプチャすることによって,我々は勢いとともに取引することができます.

具体的には,この戦略は5日 (高速) と34日 (遅い) のダブル移動平均を定義する.この2つのMAを毎日計算し,高速MAが遅いMAの上または下を横切るかチェックする.ゴールデンクロスが発生した場合,それは長い.死亡クロスが発生した場合,それはポジションを退出する.

利点分析

これは単純で理解しやすい戦略で,量子取引の初心者にも適しています.複雑な戦略と比較して,実装がはるかに簡単です.

二重MA戦略は,市場の騒音を効果的にフィルタリングし,主要なトレンドを把握することができます.MA日のパラメータを調整することで,異なる時間枠での価格変動に適応できます.

また,ストップ・ロスのメカニズムも組み込まれています.価格が方向転換し始め,MAのデス・クロスが起こると,リスクを制御するためにタイミングでポジションを終了します.

リスク分析

二重MA戦略は,停止損失や曲線フィットメントの失敗などのリスクがあります.主な問題は:

  1. MA は遅延効果があり,トレンドが既に逆転した後にしかシグナルを生成することができません.収益性の高い取引は損失に変わる可能性があります.

  2. 変動市場では,多くの誤った信号があり,不必要な取引,コスト増加,スライドが発生します.

  3. 基本的分析を組み合わせずに技術指標のみをベースにしています.市場動向を誘発するイベントでは不良なパフォーマンスを発揮することがあります.

  4. ポジションのサイズとリスク管理は考慮されません. 1つのブラック・スワンイベントは戦略を爆破させる可能性があります.

オプティマイゼーションの方向性

その強みをより良く利用し,リスクを軽減するために,以下の方法で最適化を行うことができます.

  1. MACDのようなトレンド指標と KDJのような波動指標を追加して より厳格なエントリールールを設定し 誤った信号をフィルタリングします

  2. 適切なストップ・ロスのメカニズムを組み込む. 例えば,価格が金色クロス後に一定パーセント下落した後,または価格が新しい高値/低値から一定の範囲を下落した後,退場する.

  3. 異なる時間枠における価格変動に適応するために,高速および遅いMA日組み合わせを最適化します.パラメータ最適化は最適なパラメータを見つけることができます.

  4. 一般的な市場体制を決定し,さまざまな市場での過剰取引を避けるために,幅広い市場指数を参照する.

  5. トレンドシグナルの信頼性を検証するために取引量の変更を組み込む.例えば,シグナルが起動するときに強いボリュームを必要とする.

結論

双動平均クロスオーバー戦略は,非常に典型的な定量的な取引戦略である. シンプルさ,直感性,実装の容易さなどのメリットがある. 継続的なテストとパラメータチューニングにより,良質な結果を生むことができる. しかし,遅滞信号識別や偽信号などの問題が存在する. 安定した利益を生み出す戦略になるために,追加のフィルターとリスク管理メカニズムを組み込む必要があります.


/*backtest
start: 2022-11-15 00:00:00
end: 2023-11-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
////////////////////////////////////////////////////////////
// This strategy is a modification to the "Bill Williams, Awesome Oscillator
// (AO) Backtest" strategy (Copyright by HPotter v1.0 29/12/2016)
//
// This version of the strategy by Midnight Mouse. 10/4/2018
//
// DESCRIPTION
//
// This indicator plots the oscillator as a column where periods fit for buying
// are marked as green, and periods fit for selling as orange/brown. If the
// current value of AO (Awesome Oscillator) is > the previous, the period is
// deemed fit for buying and the indicator is marked green. If the AO values is
// not over the previous, the period is deemed fit for selling and the indicator 
// is marked orange/brown.
//
// You can change long to short in the Input Settings
//
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////

strategy("Awesome Oscillator.MMouse_Lager_BCE")

// === SETTINGS ===

// Strategy start date
FromMonth   = input(defval = 1,    title = "From Month", minval = 1)
FromDay     = input(defval = 1,    title = "From Day",   minval = 1)
FromYear    = input(defval = 2017, title = "From Year",  minval = 2014)

// Strategy settings
nLengthSlow = input(34, minval=1,  title="Length Slow")
nLengthFast = input(5,  minval=1,  title="Length Fast")
allowShorts = input(false,         title="Include Short Trades")
reverse     = input(false,         title="Trade reverse")


// === BODY ===

// Use Heikin-Ashi candles for the buy/sell signal
ha_t        = heikinashi(syminfo.tickerid)
ha_high     = security(ha_t, timeframe.period, high)
ha_low      = security(ha_t, timeframe.period, low)
length      = input( 14 )
price       = open
vrsi        = rsi(price, length)

// Calc (H+L)/2 for each length
xSMA1_hl2   = sma((ha_high + ha_low)/2, nLengthFast)
xSMA2_hl2   = sma((ha_high + ha_low)/2, nLengthSlow)

// Get SMA difference (Fast - Slow)
xSMA1_SMA2  = xSMA1_hl2 - xSMA2_hl2

// Derive the color of the column
cClr = xSMA1_SMA2 > xSMA1_SMA2[1] ? #93c47d : #ad5e1d

// Determine the position to take (Long vs. Short)
pos = iff(xSMA1_SMA2 > xSMA1_SMA2[1],  1, iff(xSMA1_SMA2 < xSMA1_SMA2[1], -1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos))

// Only apply strategy from the start date
if (time >= timestamp(FromYear, FromMonth, FromDay, 00, 00))
    if (possig == 1)
        // Market is currently fit for a Long position
        strategy.entry("Long", strategy.long)

    if (possig == -1)
        // Market is currently fit for a Short position
        if(allowShorts)
            // Shorts are allowed. Record a Short position
            strategy.entry("Short", strategy.short)	   	    
        else
            // Shorts are not allowed. Closec the Long position.
            strategy.close("Long")

// Define the candle colors
//barcolor(possig == -1 ? red : 
//         possig ==  1 ? green : 
//         blue )

// Plot the oscillator
plot(xSMA1_SMA2, style=columns, linewidth=1, color=cClr)

もっと