コンボトレンド逆転移動平均クロスオーバー戦略

作者: リン・ハーンチャオチャン開催日:2023年11月28日 13:47:05
タグ:

img

概要

これは,より正確な取引信号を生成するために,トレンド逆転と移動平均クロスオーバー戦略を組み合わせるコンボ戦略です.

戦略の論理

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

  1. 123 逆転戦略: 閉じる価格が2日連続で上昇し,9日間のスローストカスティックは50を下回るとロング; 閉じる価格が2日連続で低下し,9日間の急速ストカスティックは50を超えるとショート.

  2. ビル・ウィリアムズ平均戦略: 13,8 日,および 5 日間の中位価格移動平均を計算し,速いMAsが遅いMAsを横切るときに長引く.速いMAsが遅いMAsを下回るときに短引く.

最後に,実際の取引信号は,両方の戦略が方向に合意した場合にのみ生成されます.そうでなければ取引はありません.

利点分析

コンボ戦略は二重トレンド検証を使用してノイズをフィルターし,信号の精度を向上させる.さらに,移動平均値はノイズの一部をフィルターする.

リスク分析

リスクは次のとおりです

  1. ダブルフィルターは良い取引を見逃すかもしれない
  2. 誤ったMA設定は,トレンドを誤って判断する可能性があります.
  3. 逆転戦略自体には損失リスクがあります

リスクは,MAパラメータやエントリー/アウトリースロジックを最適化することで軽減できる.

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

戦略を最適化するには

  1. 最適なパラメータを見つけるために異なるMA組み合わせをテストする
  2. ストップ・ロスの追加
  3. 信号の質を識別するための音量を組み込む
  4. 自動最適化のための機械学習を使用

結論

この戦略は,ダブルトレンドフィルターとMAを組み合わせて,ノイズを効果的にフィルタリングし,意思決定の正確性を向上させる.しかし,リスクは存在し,安定した収益性を得る前に論理の継続的な最適化が必要です.


/*backtest
start: 2023-10-28 00:00:00
end: 2023-11-27 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 18/06/2019
// This is combo strategies for get 
// a cumulative signal. Result signal will return 1 if two strategies 
// is long, -1 if all strategies is short and 0 if signals of strategies is not equal.
//
// 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
// This indicator calculates 3 Moving Averages for default values of
// 13, 8 and 5 days, with displacement 8, 5 and 3 days: Median Price (High+Low/2).
// The most popular method of interpreting a moving average is to compare 
// the relationship between a moving average of the security's price with 
// the security's price itself (or between several moving averages).
//
// 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

BillWilliamsAverages(LLength, MLength,SLength, LOffset,MOffset, SOffset ) =>
    xLSma = sma(hl2, LLength)[LOffset]
    xMSma = sma(hl2, MLength)[MOffset]
    xSSma = sma(hl2, SLength)[SOffset]
    pos = 0
    pos := iff(close < xSSma and xSSma < xMSma and xMSma < xLSma, -1,
    	   iff(close > xSSma and xSSma > xMSma and xMSma > xLSma, 1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Bill Williams Averages. 3Lines", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
LLength = input(13, minval=1)
MLength = input(8,minval=1)
SLength = input(5,minval=1)
LOffset = input(8,minval=1)
MOffset = input(5,minval=1)
SOffset = input(3,minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posBillWilliamsAverages = BillWilliamsAverages(LLength, MLength,SLength, LOffset, MOffset, SOffset)
pos = iff(posReversal123 == 1 and posBillWilliamsAverages == 1 , 1,
	   iff(posReversal123 == -1 and posBillWilliamsAverages == -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 ? red: possig == 1 ? green : blue ) 

もっと