定量戦略: MA の強さと弱さのトレンド追跡


作成日: 2024-01-19 16:50:13 最終変更日: 2024-01-19 16:50:13
コピー: 3 クリック数: 609
1
フォロー
1617
フォロワー

定量戦略: MA の強さと弱さのトレンド追跡

概要

この戦略は,複数の時間帯の移動平均 (((MA) の強弱を計算することによって,市場トレンドの強弱を評価し,トレンドの判断と追跡を実現する.短期MA指標が連続して上昇し,高点を記録し,MA強度指標を形成する.この指標がそれ自身の長期MAを超えると,買入シグナルを生成する.戦略は,長期短期MAの組み合わせを配置し,異なる周期のトレンドを追跡する.

戦略原則

  1. 5日,10日,20日など複数のMAを計算し,価格がそれぞれのMAを上方へ突破するか判断し,突破記号を積分してMA強度を形成する.
  2. MA強度に移動平均を適用し,平均線指標を形成し,平均線が空っぽであることを判断し,取引信号を生成する.
  3. 設定可能な追跡周期パラメータ:短期MA群数,長期平均線周期,ポジション開設条件など.

この戦略は,主に平均線指標の多空を判定し,平均線指標がMA線群の平均強さを反応する.MA線群は,トレンドの方向と強さを集中的に判定し,平均線指標は継続性を判定する.

優位分析

  1. トレンドの強さを評価する多次元モデル.単一のMA線では十分な強度が判定できない.この戦略は多MA突破を測定し,十分な強度が確認された後に信号を発信し,信頼性が高い.
  2. 設定可能な追跡周期。短期MAパラメータを調整することで,異なるレベルのトレンドを捉えることができる.長期MAパラメータを調整することで,出場ペースを制御できる。ユーザーは,市場に応じて周期を調整することができる。
  3. 策略は多すぎれば反転の損失を減らすことができます.

リスク分析

  1. 撤回リスクがある。短線平均線の下を通る長線平均線で,より大きな撤回リスクがある。単一損失を止めて減らすことができる。
  2. 逆転リスクがある。市場が長期にわたって運行する際には必ず調整が必要であり,戦略はExitingを早期に停止しなければならない。波段,通路などの技術と組み合わせて大周期の終わりを判断し,逆転リスクを制御することが推奨されている。
  3. パラメータリスク。不適切なパラメータ配置により誤信号が与えられる。パラメータを異なる品種に適した形で調整して,パラメータの安定性を確保する。

最適化の方向

  1. 複数の指標を組み合わせて入場をフィルタリングする。 交差量を組み合わせて,量的に検証可能な場合で信号を発信し,偽突破を避ける。
  2. 増減方法。移動止損,曲線止損は回調で損失を減らすことができる。止止方法も考慮できる,利益をロックし,反転を避ける。
  3. 配置先物,外貨品種を考慮する。MA線突破はトレンド型品種に適している。異なる先物品種のパラメータの安定性を評価し,最適な品種を選択する。

要約する

この戦略は,MA強度指標を計算して価格の傾向を判断し,均線交差を信号源として,トレンド追跡を行う.戦略の優点は,トレンドの強さを正確に判断することであり,信頼性が高い.主なリスクは,トレンドの逆転とパラメータの調整にある.入場信号の正確性を最適化し,ストップロスを増やし,適切な品種を選択することで,より良い利益を得ることができる.

ストラテジーソースコード
/*backtest
start: 2023-12-19 00:00:00
end: 2024-01-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed

//@version=4
strategy("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)
MAType = input(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
LookbackPeriod = input(10, step=10)

IndexMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
IndexMAPeriod = input(200, step=10)

considerTrendDirection = input(true)
considerTrendDirectionForExit = input(true)
offset = input(1, step=1)
tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)
inDateRange = true

f_getMovingAverage(source, MAType, length)=>
    ma = sma(source, length)
    if(MAType == "ema")
        ma := ema(source,length)
    if(MAType == "hma")
        ma := hma(source,length)
    if(MAType == "rma")
        ma := rma(source,length)
    if(MAType == "vwma")
        ma := vwma(source,length)
    if(MAType == "wma")
        ma := wma(source,length)
    ma
    

f_getMaAlignment(MAType, includePartiallyAligned)=>
    ma5 = f_getMovingAverage(close,MAType,5)
    ma10 = f_getMovingAverage(close,MAType,10)
    ma20 = f_getMovingAverage(close,MAType,20)
    ma30 = f_getMovingAverage(close,MAType,30)
    ma50 = f_getMovingAverage(close,MAType,50)
    ma100 = f_getMovingAverage(close,MAType,100)
    ma200 = f_getMovingAverage(close,MAType,200)

    upwardScore = 0.0
    upwardScore := close > ma5? upwardScore+1.10:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1.10:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1.10:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1.10:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1.15:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1.20:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1.25:upwardScore
    
    upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
    trendStrength = upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 6? 0.5: upwardScore < 2?-0.5:upwardScore>4?0.25:-0.25) : 0
    [trendStrength, upwardScore]
    
includePartiallyAligned = true
[trendStrength, upwardScore] = f_getMaAlignment(MAType, includePartiallyAligned)

upwardSum = sum(upwardScore, LookbackPeriod)

indexSma = f_getMovingAverage(upwardSum,IndexMAType,IndexMAPeriod)

plot(upwardSum, title="Moving Average Strength", color=color.green, linewidth=2, style=plot.style_linebr)
plot(indexSma, title="Strength MA", color=color.red, linewidth=1, style=plot.style_linebr)
buyCondition = crossover(upwardSum,indexSma) and (upwardSum > upwardSum[offset] or not considerTrendDirection) 
sellCondition = crossunder(upwardSum,indexSma) and (upwardSum < upwardSum[offset]  or not considerTrendDirection)

exitBuyCondition = crossunder(upwardSum,indexSma)
exitSellCondition = crossover(upwardSum,indexSma) 
strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when= inDateRange and buyCondition, oca_name="oca_buy")
strategy.close("Buy", when = considerTrendDirectionForExit? sellCondition : exitBuyCondition)
strategy.entry("Sell", strategy.short, when= inDateRange and sellCondition, oca_name="oca_sell")
strategy.close( "Sell", when = considerTrendDirectionForExit? buyCondition : exitSellCondition)