動的移動平均の二重戦略

作者: リン・ハーンチャオチャン開催日:2023年12月13日16時37分05秒
タグ:

img

概要

この戦略は,移動平均値 (MA) の傾斜とモメントインジケーターの傾斜を取引決定に使用する.この戦略は,MA傾斜とモメント傾斜を設定された値と比較し,両方の傾斜が値を超えると取引シグナルを生成する.この戦略には,市場変動が低いときにシグナルを生成するために異なるMAを使用する低波動性フィルターも含まれています.

戦略の論理

この戦略の核心は,傾斜曲線を2つ比較することにある.まずは,MAとモメントインジケーターの傾斜を計算する.傾斜は曲線の変化率と方向を反映する.その後,2つの値が使用され,MA傾斜とモメント傾斜の両方が対応する値を超えると,取引信号が生成される.

例えば,MA傾斜とモメント傾斜の両方が上線を超えると,購入信号が生成され,両曲線が下線を下回ると,販売信号が生成されます.これはいくつかの偽信号をフィルタリングすることができます.

低波動性フィルターは,市場波動性を決定するために長期MAを使用する.波動性が低い場合,異なる市場状態に適応するために異なるパラメータを持つMAを使用して取引信号を生成する.

利点分析

この戦略には以下の利点があります.

  1. トレーディング・シグナルを設定するためのダブルフィルターは,ノイズをフィルタリングし,信号の質を向上させることができます.

  2. 低波動性フィルターは,戦略が柔軟性をもって異なる市場条件に適応できるようにします.

  3. 異なるパラメータに対する高度なカスタマイズ性は,異なる製品に最適化できます.

  4. カーブ・フィッティングによる衝撃を減らすための塗装機能はありません.

リスク分析

この戦略にはいくつかのリスクもあります:

  1. ダブルフィルターは,実際の信号をフィルタリングし,機会を逃す可能性があります. これはパラメータを調整することによって最適化できます.

  2. 低揮発性フィルターの値決定は,慎重に試験する必要があります.不適切な設定は信号偏差を引き起こす可能性があります.

  3. MAとモメント指標のパラメータ設定は,特定の製品に最適化され,普遍的なパラメータを決定することは困難です.

  4. 再塗装なしの機能はバックテスト曲線フィッティング問題を完全に回避することはできません.そして実際の取引パフォーマンスはまだ検証が必要です.

  5. 高度なカスタマイズ可能性は,パラメータ空間の複雑性と最適化の難易性を増加させる.

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

戦略は以下の方向で最適化できる:

  1. 最適なマッチングインジケーターを見つけるために,MAとモメントインジケーターの組み合わせをテストする.

  2. MAの長さパラメータとモメントインジケーターを最適化して遅延とノイズを均衡させる.

  3. 傾きを計算するパラメータを最適化して,より安定した指標組み合わせを見つけます.

  4. 弾性の向上のために,異なる低揮発性指標とパラメータを試験する.

  5. 最適な適用範囲を見つけるため,異なる製品と時間枠でテストする.

  6. パラメータ適応メカニズムを構築し,手動最適化作業量を削減する.

結論

これは非常に柔軟でカスタマイズ可能なダブルMA戦略である.意思決定のために価格とモメント情報の両方を参照し,誤ったシグナルを効果的にフィルタリングすることができます.低変動性フィルタはまた,市場変化に適応するための戦略をより弾性的にします.

パラメータ最適化と指標選択の改善により,この戦略は実生活での取引に有効な選択肢になり得る.MAとモメント指標を使用して取引決定のための参照テンプレートを提供します.


/*backtest
start: 2023-11-12 00:00:00
end: 2023-12-12 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/
// © Allenlk
//@version=4
strategy("DRSI DMA Scalping Strategy", shorttitle="DRSIDMA", overlay=false, initial_capital=1000, pyramiding=2, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

//Inputs
matype             = input(7, minval=1, maxval=8, title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3", group="Moving Average")
masrc              = input(close, title="MA Source", group="Moving Average")
malen              = input(5, title="Moving Average Length - LookBack Period", group="Moving Average")
factorT3           = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0, group="Moving Average")
maderiv            = input(3, title="MA Slope Lookback", minval=1, group="Moving Average")
masmooth           = input(5, title="MA Slope Smoothing", minval=1, group="Moving Average")
momtype            = input(3, minval=1, maxval=3, title="1=RSI, 2=CCI, 3=RSI/ROC", group="Momentum Moving Average")
momsrc             = input(close, title="Momentum Source", group="Momentum Moving Average")
momlen             = input(3, title="Momentum Length", minval=1, group="Momentum Moving Average")
momderiv           = input(8, title="Momentum Slope Lookback", minval=1, group="Momentum Moving Average")
momsmooth          = input(7, title="Momentum Slope Smoothing", minval=1, group="Momentum Moving Average")
higherTf           = input("1", title="Higher timeframe?", type = input.resolution, group="Time Resolution")
higherTfmult       = input(130, title="MA Slope multiplier for Alternate Resolutions (Make the waves of the blue line similar size as the orange line)", group="Time Resolution")
buffup             = input(0.02, title="Buy when both slopes cross this line", step=0.01, group="Buy and Sell Threshold")
bufflow            = input(-0.03, title="Sell when both slopes cross this line", step=0.01, group="Buy and Sell Threshold")
lowVolMALength     = input(28, title="Big MA Length", minval=1, group="Low Volatility Function")
MAlength           = input(10, title="Low Volatility Moving Average Length", minval=1, group="Low Volatility Function")
MAThresh           = input(0.05, title="Low Volatility Buy and Sell Threshold", step=0.01, group="Low Volatility Function")
Volminimum         = input(2.5, title="Minimum volatility to trade", minval=0, step=0.01, group="Low Volatility Function")

//Low Volatility Function
//When Volatility is low refer to the slope of a long moving average
low_vol_MA         = sma(close, lowVolMALength)
low_vol_down       = (low_vol_MA[3] - low_vol_MA[1]) > MAThresh
low_vol_up         = (low_vol_MA[3] - low_vol_MA[1]) < MAThresh * -1
percent_volatility = (1 - (low / high)) * 100
chng_MA            = sma(percent_volatility, MAlength)
bad_vol            = chng_MA < Volminimum

//No repaint function
nrp_funct(_symbol, _res, _src) => security(_symbol, _res, _src[barstate.isrealtime ? 1 : 0])

//hull ma definition
hullma = wma(2*wma(masrc, malen/2)-wma(masrc, malen), round(sqrt(malen)))

//TEMA definition
ema1 = ema(masrc, malen)
ema2 = ema(ema1, malen)
ema3 = ema(ema2, malen)
tema = 3 * (ema1 - ema2) + ema3

//Tilson T3
factor = factorT3 *.10
gd(masrc, malen, factor) => ema(masrc, malen) * (1 + factor) - ema(ema(masrc, malen), malen) * factor 
t3(masrc, malen, factor) => gd(gd(gd(masrc, malen, factor), malen, factor), malen, factor) 
tilT3 = t3(masrc, malen, factor) 
 
//MA Type 
avg = matype == 1 ? sma(masrc,malen) : matype == 2 ? ema(masrc,malen) : matype == 3 ? wma(masrc,malen) : matype == 4 ? hullma : matype == 5 ? vwma(masrc, malen) : matype == 6 ? rma(masrc,malen) : matype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3

//MA Slope Percentage
DeltaAvg      = (avg / avg[maderiv]) - 1
SmoothedAvg   = sma(DeltaAvg, masmooth) 
MAout         = nrp_funct(syminfo.tickerid, higherTf, SmoothedAvg) * higherTfmult

//Momentum indicators
Momentum = momtype == 1 ? rsi(momsrc, momlen) : momtype == 2 ? cci(momsrc, momlen) : momtype == 3 ? rsi(roc(momsrc,momlen),momlen) : na

//Momentum Slope Percentage
Deltamom = (Momentum / Momentum[momderiv]) - 1
SmoothedMom = sma(Deltamom, momsmooth) 
Momout   = nrp_funct(syminfo.tickerid, higherTf, SmoothedMom)

//Plottings
plot(buffup, color=color.green, title="Buy line")
plot(bufflow, color=color.red, title="Sell line")
plot(MAout, color=color.blue, linewidth=2, title="MA Slope")
plot(Momout, color=color.orange, linewidth=2, title="Momentum Slope")

longCondition = bad_vol ? low_vol_up : MAout > buffup and Momout > buffup
if (longCondition)
    strategy.entry("Buy", strategy.long)

shortCondition = bad_vol ? low_vol_down : MAout < bufflow and Momout < bufflow
if (shortCondition)
    strategy.entry("Sell", strategy.short)

もっと