動的移動平均値に基づくトレンド取引戦略

作者: リン・ハーンチャオチャン開催日:2023年12月21日11時35分50秒
タグ:

img

概要

この戦略は,動的移動平均値に基づいて,株価が上昇するときにロングに,価格が下がるときにポジションを閉じます.モメント指標と移動平均値の利点を組み合わせることで,安定した利益を得るために中期価格動向を追跡することを目的としています.

原則

この戦略は主に3つのHull Moving Average (HMA) の変数通常のHMA,重量化されたHMA (WHMA) および指数的なHMA (EHMA) に基づいています.コードが示すように,ユーザーは3つのHull MAの間に切り替えることができます.

HMAの式は次のとおりです.

HMA = WMA ((2*WMA ((近,n/2)-WMA ((近,n),平方))

WMAは重度の移動平均値であり,nは周期パラメータである.SMAと比較して,HMAは価格変化により速く反応する.

WHMA と EHMA の式は似ています.HMA はデフォルトオプションとして選択されます.

HMAを計算した後,戦略はHMAのミッドライン値を取引信号として使用する.価格はHMAミッドラインを超えるとロングになり,価格はラインを下回るとポジションを閉じる.したがって,利益のためにHMAミッドラインを使用して中期トレンドを追跡する.

利点

この戦略は,従来のMA戦略と比較して,以下の優位性があります.

  1. 迅速な応答と,タイミングでエントリーやストップを行う傾向を追跡する能力
  2. 不必要な取引頻度を低くし,急上昇や停止を避ける
  3. 柔軟なHMAパラメータにより多くの市場環境に適応する
  4. 適用範囲を拡大するための切り替え可能なHMA変種

リスク

リスクもあります:

  1. 範囲限定の市場において複数の誤った信号を生成し,取引頻度とスライプコストを増加させる
  2. HMA パラメータが正しく設定されていない場合,トレンド逆転ポイントが欠けているため,損失のリスクが増加します.
  3. 低流動性株の取引における流動性リスクと大きな滑り

解決策:

  1. 最適値のためのHMAパラメータを最適化
  2. トレンド逆転点を決定するために他の指標を追加する
  3. 平均日額量が大きい流動株を選択する

改善

戦略は,次の側面からも強化される.

  1. 信号の信頼性を確保するために音量または他のフィルタを追加
  2. MACDとKDJを組み合わせて より良いタイミングを設定し 勝率を向上させる
  3. HMA 期間をリアル・トレードバックテストに基づいて調整する
  4. 特定の株に対して最も効率的なWHMAまたはEHMAに切り替える
  5. 単一の取引損失を制御するためにストップ・ロスのメカニズムを追加する

概要

ダイナミックなMA取引戦略は,中期価格動向を効果的に追跡するためのHMAの迅速な対応を統合している.適切なタイミングでロングポジションを開設し,閉じるストップにより,良好なバックテスト結果を示している.パラメータ調整とストックフィルタリングのさらなる改善により,より安定した過剰収益につながる.これは実行しやすい,リスク制御可能な定量戦略である.


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

//@version=5
strategy('Position Investing by SirSeff', overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0)
strat_dir_input = input.string(title='Strategy Direction', defval='long', options=['long', 'short', 'all'])
strat_dir_value = strat_dir_input == 'long' ? strategy.direction.long : strat_dir_input == 'short' ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
//////////////////////////////////////////////////////////////////////
// Testing Start dates
testStartYear = input(2000, 'Backtest Start Year')
testStartMonth = input(1, 'Backtest Start Month')
testStartDay = input(1, 'Backtest Start Day')
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)
//Stop date if you want to use a specific range of dates
testStopYear = input(2030, 'Backtest Stop Year')
testStopMonth = input(12, 'Backtest Stop Month')
testStopDay = input(30, 'Backtest Stop Day')
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)


testPeriod() => true
// Component Code Stop
//////////////////////////////////////////////////////////////////////
//INPUT
src = input(close, title='Source')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'])
length = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)')
switchColor = input(true, 'Color Hull according to trend?')
candleCol = input(false, title='Color candles based on Hull\'s Trend?')
visualSwitch = input(true, title='Show as a Band?')
thicknesSwitch = input(1, title='Line Thickness')
transpSwitch = input.int(40, title='Band Transparency', step=5)

//FUNCTIONS
//HMA
HMA(_src, _length) =>
    ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
//EHMA    
EHMA(_src, _length) =>
    ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length)))
//THMA    
THMA(_src, _length) =>
    ta.wma(ta.wma(_src, _length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)

//SWITCH
Mode(modeSwitch, src, len) =>
    modeSwitch == 'Hma' ? HMA(src, len) : modeSwitch == 'Ehma' ? EHMA(src, len) : modeSwitch == 'Thma' ? THMA(src, len / 2) : na

//OUT
HULL = Mode(modeSwitch, src, length)
MHULL = HULL[0]
SHULL = HULL[2]

//COLOR
hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800

//PLOT
///< Frame
Fi1 = plot(MHULL, title='MHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)
Fi2 = plot(visualSwitch ? SHULL : na, title='SHULL', color=hullColor, linewidth=thicknesSwitch, transp=50)
///< Ending Filler
fill(Fi1, Fi2, title='Band Filler', color=hullColor, transp=transpSwitch)
///BARCOLOR
barcolor(color=candleCol ? switchColor ? hullColor : na : na)


if HULL[0] > HULL[2] and testPeriod()
    strategy.entry('Invest', strategy.long)
if HULL[0] < HULL[2] and testPeriod()
    strategy.entry('Pause', strategy.short)



もっと