移動平均クロスオーバーと平均真の範囲のハイブリッド戦略


作成日: 2023-09-26 17:22:21 最終変更日: 2023-09-26 17:22:21
コピー: 7 クリック数: 976
1
フォロー
1617
フォロワー

概要

この戦略は,平均線交差と平均真波幅の2つの技術指標を組み合わせ,トレンド中の平均線交差信号を識別し,より高い勝利率を得ます.

原則

  • ATR指標を用いて大周期価格変動を判断し,上昇傾向にあることを確認
  • 短周期で,速平均線と遅平均線を計算し,速線上を通るときは多行,速線下を通るときは空行
  • ATR指標は,大周期の平均真波幅を計算し,全体的なトレンドを判定する.均線交差は,小周期内の具体的な入場点を判定する
  • ATR指標はRMA平滑移動平均で計算され,長さと滑り度は調整可能
  • 均線交差は,長さが調整可能な2つのSMA均線計算によって構成される

利点

  • ATR指標は,不確実なトレンドを効果的にフィルターして,無駄な取引を回避します.
  • 平均線交差は小周期的な傾向を正確に判断する.
  • RMAはATRを計算することで曲線を減らし,大周期的な動きをより安定的に判断できる.
  • この2つが合わされば,震を回避することも,具体的な機会を捉えることもできます.
  • パラメータは調整可能で,異なる品種と時間周期に最適化できます
  • 全体的に見ると,この戦略は成功率が高いし,安定した収益を期待できる.

リスク

  • ATR指標は,主動トレンドが遅れていると判断し,トレンドの開始を逃す可能性があります.
  • 平均線交差は複数の調整の確率があり,Sell信号が多く
  • パラメータチューニングは非常に重要で,不適切な設定により,取引が頻繁すぎたり,保守的になる可能性があります.
  • 特定の品種を対象とした歴史データを分析し,最適なパラメータの組み合わせを探します.
  • 順次開設により,資金の充足と単一損失の管理が推奨されます.

最適化の方向

  • 傾向の強さを判断するブリン帯のような他の指標を補完または代替する
  • 均線交差型は,EMA,運動量指標などの他の組み合わせに拡張できます.
  • 突破確認のメカニズムに追加して偽突破を防ぐ
  • 最適化パラメータの設定順序:ATR長さと滑り > 平均線長さ > 止損ストップの設定
  • 固定株,動的ポジションなどの資金管理戦略を考慮する
  • リアルタイムの長期反省,戦略の安定性,最大撤退の評価

要約する

この戦略は,ATRと均線交差のそれぞれの優位性を充分に活用し,トレンドの方向と特定の入場時刻を共同判断する.パラメータ調整により,異なる市場環境に適応できる.実用検証は,この戦略がより高い勝率と安定した収益を得ることができることを示す.しかし,リスク管理に注意し,慎重に操作する必要があります.後続データが戦略の効果を検証し続ける場合,さらなる拡張と改善が価値あり,安定した信頼性の高い定量化取引システムになる.

ストラテジーソースコード
/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 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/
// © Phoenix085

//@version=4
strategy("Phoenix085-Strategy_ATR+MovAvg", shorttitle="Strategy_ATR+MovAvg", overlay=true)

// // ######################>>>>>>>>>>>>Inputs<<<<<<<<<<<#########################
// // ######################>>>>>>>>>>>>Strategy Inputs<<<<<<<<<<<#########################

TakeProfitPercent = input(50, title="Take Profit %", type=input.float, step=.25)
StopLossPercent = input(5, title="Stop Loss %", type=input.float, step=.25)

ProfitTarget = (close * (TakeProfitPercent / 100)) / syminfo.mintick
LossTarget = (close * (StopLossPercent / 100)) / syminfo.mintick

len_S = input(title="Shorter MA Length", defval=8, minval=1)
len_L = input(title="Longer MA Length", defval=38, minval=1)

TF = input(defval="", title="Session TF for calc only", type=input.session,options=[""])
TF_ = "1"

if TF == "3"
    TF_ == "1"
else 
    if TF == "5" 
        TF_ == "3"
    else 
        if TF == "15"
            TF_ == "5"
        else 
            if TF == "30"
                TF_ == "15"
            else 
                if TF == "1H"
                    TF_ == "30"
                else 
                    if TF == "2H"
                        TF_ == "1H"
                    else 
                        if TF == "4H"
                            TF_ == "3H"
                        else 
                            if TF == "1D"
                                TF_ == "4H"
                            else
                                if TF == "1W"
                                    TF_ == "1H"
                                else 
                                    if TF == "1M"
                                        TF_ == "1W"
                                    else
                                        if TF =="3H"
                                            TF_ == "2H"

Src = security(syminfo.tickerid, TF, close[1], barmerge.lookahead_on)

Src_ = security(syminfo.tickerid, TF_, close, barmerge.lookahead_off)

// ######################>>>>>>>>>>>>ATR Inputs<<<<<<<<<<<#########################
length = input(title="ATR Length", defval=4, minval=1)
smoothing = input(title="ATR Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])


// //######################>>>>>>>>>>>>Custom Functions Declarations<<<<<<<<<<<#########################



// ######################>>>>>>>>>>>>ATR<<<<<<<<<<<#########################

ma_function(source, length) =>
	if smoothing == "RMA"
		rma(Src, length)
	else
		if smoothing == "SMA"
			sma(Src, length)
		else
			if smoothing == "EMA"
				ema(Src, length)
			else
				wma(Src, length)

ATR=ma_function(tr(true), length)


// //######################>>>>>>>>>>>>Conditions<<<<<<<<<<<#########################
ATR_Rise = ATR>ATR[1] and ATR[1]<ATR[2] and ATR[2]<ATR[3]

longCondition = crossover(sma(Src_, len_S), sma(Src_, len_L)) and sma(Src_, len_L) < sma(Src_, len_S) and (sma(Src_, len_S) < Src_[1])
shortCondition = crossunder(sma(Src_, len_S), sma(Src_, len_L)) and sma(Src_, len_L) > sma(Src_, len_S) 

plot(sma(Src_, len_S), color=color.lime, transp=90)
col = longCondition ? color.lime : shortCondition ? color.red : color.gray
plot(sma(Src_, len_L),color=col,linewidth=2)


bool IsABuy = longCondition 
bool IsASell = shortCondition

// // ######################>>>>>>>>>>>>Strategy<<<<<<<<<<<#########################

testStartYear = input(2015, "Backtest Start Year", minval=1980)
testStartMonth = input(1, "Backtest Start Month", minval=1, maxval=12)
testStartDay = input(1, "Backtest Start Day", minval=1, maxval=31)
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear = input(9999, "Backtest Stop Year", minval=1980)
testStopMonth = input(12, "Backtest Stop Month", minval=1, maxval=12)
testStopDay = input(31, "Backtest Stop Day", minval=1, maxval=31)
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false
inDateRange = true

bgcolor(inDateRange ? color.green : na, 90)
// //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

// // ######################>>>>>>LongEntries<<<<<<<#########################
if inDateRange and ATR_Rise and IsABuy 
    strategy.entry("longCondition",true,when = longCondition)
    strategy.close("shortCondition")
    strategy.exit("Take Profit or Stop Loss", "longCondition",trail_points = close * 0.05 / syminfo.mintick ,trail_offset = close * 0.05 / syminfo.mintick, loss = LossTarget)
// strategy.risk.max_drawdown(10, strategy.percent_of_equity)
    
// // ######################>>>>>>ShortEntries<<<<<<<#########################
if inDateRange and ATR_Rise and IsASell  
    strategy.entry("shortCondition",false,when = shortCondition)
    strategy.exit("Take Profit or Stop Loss", "shortCondition",trail_points = close * 0.05 / syminfo.mintick ,trail_offset = close * 0.05 / syminfo.mintick, loss = LossTarget)
    strategy.close("longCondition")