이동평균 교차 및 평균 진범위 하이브리드 전략


생성 날짜: 2023-09-26 17:22:21 마지막으로 수정됨: 2023-09-26 17:22:21
복사: 7 클릭수: 976
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 평균선 교차와 평균 실제 파장 두 가지의 기술 지표를 활용하여 트렌드에 있는 평균선 교차 신호를 식별하여 더 높은 승률을 얻습니다.

원칙

  • ATR 지표를 사용하여 대주기 가격 변동성을 판단하여 상승 추세에 있음을 확인합니다.
  • 소주기 동안, 빠른 평균선과 느린 평균선을 계산하고, 빠른 선에서 느린 선을 통과할 때 더하고, 빠른 선 아래의 느린 선을 통과할 때 공백을 다.
  • ATR 지표는 큰 주기 동안의 평균 실제 파장을 계산하여 전체 트렌드를 결정합니다. 평균선 교차는 작은 주기 내에 특정 시장 진입 지점을 결정합니다.
  • ATR 지표는 RMA 평평한 이동 평균으로 계산되며, 길이와 평면은 조정할 수 있다.
  • 평균선 교차는 두 개의 SMA 평균선 계산으로 구성되며, 길이는 조정할 수 있습니다.

장점

  • ATR 지표는 불투명한 트렌드를 효과적으로 필터링하여 무의미한 거래를 방지할 수 있습니다.
  • 평균선 교차는 소주기 트렌드를 정확하게 판단한다 Conversion Points
  • RMA 계산 ATR은 곡선을 줄여서 대주기 움직임을 더 안정적으로 판단할 수 있다.
  • 이 두가지가 합쳐지면, 위기를 피할 수 있고, 기회를 잡을 수 있습니다.
  • 다양한 품종과 시간 주기에 최적화 가능한 변수
  • 전체적으로, 이 전략은 높은 승률을 보이며 안정적인 수익을 얻을 수 있을 것으로 예상됩니다.

위험

  • ATR 지표는 주 트렌드가 늦어졌다고 판단하여 트렌드 시작을 놓칠 수 있습니다.
  • 평균선 교차에 여러 조정이 있을 확률이 있고, Sell 신호가 더 많다.
  • 파라미터 튜닝은 매우 중요하며, 잘못된 설정으로 인해 너무 자주 또는 보수적으로 거래 될 수 있습니다.
  • 종별로 역사적 데이터를 분석하여 최적의 변수 조합을 찾아내야 합니다.
  • 단계적으로 포지션을 개시하여 자금을 충분히 확보하고 단독 손실을 통제하는 것이 좋습니다.

최적화 방향

  • 트렌드 강도를 판단하는 브린 밴드 같은 다른 지표를 보완하거나 대체하기 위해 ATR을 시도하십시오.
  • 평선 교차 유형은 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")