二重移動平均戦略とストキャスティクス指標の組み合わせ


作成日: 2024-01-12 11:16:52 最終変更日: 2024-01-12 11:16:52
コピー: 0 クリック数: 567
1
フォロー
1617
フォロワー

二重移動平均戦略とストキャスティクス指標の組み合わせ

概要

この記事では,双均線戦略とランダムな指標を組み合わせた量化取引戦略について説明します. この戦略は,移動均線のトレンド追跡能力とランダムな指標の超買い超売り特性を統合して取引信号を形成します.

戦略原則

この戦略は2つの部分から構成されています.

  1. 双方向戦略

急速移動平均線とゆっくり移動平均線を使って金叉買入信号と死叉売出信号を形成する.急速平均線は価格変化のトレンドをより早く捉え,ゆっくり移動平均線は偽波信号をする.

  1. ランダムな指標

ランダムな指標の振動特性を利用して,オーバーバイのオーバーセールを識別する.ランダムな指標が慢線より高いときはオーバーバイの信号,ランダムな指標が慢線より低いときはオーバーセルの信号である.

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 )