ストカスティック指標と組み合わせた二重移動平均戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-12 11:16:52
タグ:

img

概要

この記事では,二重移動平均戦略とストキャスティック指標を組み合わせた定量的な取引戦略を紹介する.この戦略は,移動平均のトレンドフォロー能力とストキャスティックの過買い過売特性を利用して取引信号を生成する.

戦略原則

戦略は2つの部分からなる.

  1. 2重移動平均戦略

    高速・低速移動平均は,黄金・クロス・バイ・シグナルと低速・デッド・クロス・セール・シグナルを生成する. 高速移動平均は価格傾向の変化をより早く捉えることができ,低速平均は偽のシグナルをフィルタリングする.

  2. ストカスティック指標

    ストキャストの振動特性を利用して,過剰購入と過剰販売の状況を識別する.スローラインよりも高いストキャストは過剰購入の信号を示し,スローラインよりも低いストキャストは過剰販売の信号を示します.

両方の部分からのシグナルが組み合わせて最終的な取引シグナルを形成します. 双向移動平均戦略は主要な傾向を追跡し,ストカスタスは不利な市場条件を避けるのに役立ちます.

利点分析

  • 二重移動平均値とストカスティック平均値の利点を組み合わせ,より安定しています.
  • 動向平均は傾向を追跡する ストカスティックは確認する 良い効果です
  • パーソナライズ可能なパラメータは,異なる市場状況に適応します.

リスク分析

  • 二重移動平均は 簡単に誤った信号を生成します
  • ストカストティックパラメータの設定が正しくない場合,トレンドが見逃される可能性があります.
  • 市場変化に適応するためにパラメータを調整する必要があります.

パラメータの組み合わせを最適化し,ストップ・ロスをコントロール・ロスに追加することでリスクは軽減できる.

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

戦略は以下の側面で最適化できます.

  1. 異なる移動平均パラメータの戦略への影響をテストする.
  2. 戦略の安定性に対する 異なるストカストティックパラメータの影響をテストする.
  3. トレンドフィルタリングインジケーターを追加して 勝率を向上させる
  4. 損失を制御する ダイナミックなストップ・ロスト・メカニズムを構築する

概要

この戦略は,二重移動平均値とストカスティックの利点を組み合わせます.主要市場トレンドを追跡しながら,不利な逆転を避けます.パラメータ最適化によってより良い戦略結果を得ることができます.ストップとトレンドフィルターを追加することで,戦略をより堅牢にすることができます.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 24/11/2020
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// As the name suggests, High low bands are two bands surrounding the underlying’s 
// price. These bands are generated from the triangular moving averages calculated 
// from the underlying’s price. The triangular moving average is, in turn, shifted 
// up and down by a fixed percentage. The bands, thus formed, are termed as High 
// low bands. The main theme and concept of High low bands is based upon the triangular 
// moving average. 
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

    
HLB(Length, PercentShift) =>
    pos = 0.0
    xTMA = sma(sma(close, Length), Length)
    xHighBand = xTMA + (xTMA * PercentShift / 100)
    xLowBand = xTMA - (xTMA * PercentShift / 100)
    pos :=iff(close > xHighBand, 1,
           iff(close <xLowBand, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & High Low Bands", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
Length_HLB = input(14, minval=1)
PercentShift = input(1, minval = 0.01, step = 0.01)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posHLB = HLB(Length_HLB, PercentShift)
pos = iff(posReversal123 == 1 and posHLB == 1 , 1,
	   iff(posReversal123 == -1 and posHLB == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )

もっと