ATR 및 이동 평균 크로스오버 하이브리드 전략

저자:차오장, 날짜: 2023-09-26 17:22:21
태그:

전반적인 설명

이 전략은 평균 진정한 범위 (ATR) 지표와 이동 평균 크로스오버를 결합하여 높은 승률을위한 트렌드 신호를 식별합니다.

논리

  • 상승 추세를 확인하기 위해 더 높은 시간 프레임에서 가격 변동성을 결정하기 위해 ATR를 사용하십시오.
  • 빠른 및 느린 이동 평균을 계산 하 고 시간 프레임, 빠른 MA는 느린 MA를 넘어서면 긴 이동, 빠른 MA는 느린 MA를 넘어서면 짧은 이동
  • ATR는 더 긴 시간 프레임에서 전반적인 경향을 나타냅니다. MA 크로스오버는 더 짧은 시간 프레임에서 특정 입점 지점을 식별합니다.
  • ATR은 RMA 평형, 길이 및 평형 조절을 통해 계산됩니다.
  • MA 크로스오버는 두 개의 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")

더 많은