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

作者: リン・ハーンチャオチャン, 日時: 2023-09-26 17:22:21
タグ:

概要

この戦略は,平均値 True Range (ATR) 指標と移動平均値のクロスオーバーを組み合わせて,より高い勝利率のためのトレンド信号を特定します.

論理

  • ATR を使用して,上昇傾向を確認するために,より長い時間枠で価格変動を決定します.
  • 低タイムフレームで高速および遅い移動平均を計算します.高速MAが遅いMAを超えると長引く.高速MAが遅いMAを下回ると短引く.
  • ATRは,より長い時間枠における全体的な傾向を示し,MAクロスオーバーは,より短い時間枠における特定のエントリーポイントを特定します.
  • ATRはRMAの滑らか,長さと滑らかさ調整で計算されます.
  • MAクロスオーバーは2つのSMAで構成され,長さは調整可能

利点

  • ATRは不規則な動きを効果的にフィルタリングし,不必要な取引を回避します
  • MAクロスオーバーは短期トレンド変換点を正確に決定します
  • ATRのRMAスムーズ化により,が減り,より高いタイムフレームトレンドでより安定した判断
  • 組み合わせた利用は 失敗を回避し 機会を掴む
  • 異なる製品と時間枠で最適化するために調整可能なパラメータ
  • 安定した利益に対する予想される全体的なより高い利益率

リスク

  • ATR トレンド判断は遅延しやすいし,初期トレンド開始が遅れる可能性がある
  • MAのクロスオーバーは多重調整を受けやすく,売る信号が増える
  • パラメータ調整が極めて重要で,不正な設定は,取引の過度/過小に繋がります
  • 製品ごとに最適なパラメータを設定するために,過去のデータ分析を必要とする.
  • 損失を制限するために十分な資金を確保

増進 の 機会

  • ATR に代わる追加指標/代替指標,例えばトレンド強度に関するボリンジャー・バンドを調査する.
  • 他の組み合わせ (EMA,モメントインジケーターなど) とMAのクロスオーバーを拡張する
  • 偽のブレイクを防ぐためにブレイク確認メカニズムを組み込む
  • パラメータ最適化順序:ATR長/スムーズ>MA長>ストップ損失/収益
  • 資本管理戦略を統合することを検討する.例えば,固定分数,動的なポジションサイズ
  • 戦略の安定性と最大利用率を評価するための広範なバックテスト

結論

この戦略は,トレンド方向とエントリーポイントを特定するためにATRとMAクロスオーバーの強みを完全に活用している.パラメータチューニングを通じて,異なる市場環境に適応することができる.ライブテストは一貫した収益性と高い勝利率を証明している.しかし,慎重な運用にはリスク管理が不可欠である.さらなるデータ検証は,それを拡張し,堅牢な量子システムに精製する必要があります.


/*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")

もっと