모멘텀과 트렌드 판단을 결합한 다중 요인 양적 거래 전략


생성 날짜: 2023-11-23 14:58:57 마지막으로 수정됨: 2023-11-23 14:58:57
복사: 0 클릭수: 644
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

모멘텀과 트렌드 판단을 결합한 다중 요인 양적 거래 전략

개요

이 전략은 동력 지표와 경향 지표를 결합한 다인자 판단형 수치 거래 전략이다. 전략은 여러 평균의 수학적 조합을 계산하여 시장의 전반적인 경향과 동력 방향을 판단하고, 하락 조건에 따라 거래 신호를 낸다.

전략 원칙

  1. 여러 그룹의 평균과 동력 지표를 계산한다
    • 하모닉스 평균, 단기 평균, 중기 평균, 장기 평균과 같은 여러 그룹의 평균을 계산합니다.
    • 가격 변화 경향을 반영하는 각 평균 사이의 차이를 계산합니다.
    • 각 평균의 1차 계수를 계산하여 가격 변화의 동력을 반영합니다.
    • 동향을 판단하기 위한 시노드/아스노드 지표를 계산합니다.
  2. 종합 판단 거래 신호
    • 동력 지표, 트렌드 지표 등의 여러 요인을 가중계로 계산합니다.
    • 현재 시장을 판단하기 위한 결과값은 시점과 매우 가깝습니다.
    • 이 신호는 상위 100달러를 차지하는 것을 의미합니다.

우위 분석

  1. 다중 요소 판단, 신호 정확도 향상
    • 가격, 트렌드, 동력 등 여러 요소들을 종합적으로 고려하는 것
    • 다른 요소에 다른 무게를 부여할 수 있습니다.
  2. 다른 시장에 적응할 수 있는 변수
    • 평균 변수, 거래 구역 간 경계를 사용자 정의할 수 있습니다.
    • 다른 주기 및 시장 환경에 적응
  3. 코드 구조는 명확하고 이해하기 쉽습니다.
    • 명명규정, 코멘트 완전
    • 2차 개발 및 최적화

위험 분석

  1. 변수를 최적화하기 어려운 경우
    • 가장 최적의 변수를 찾기 위해 많은 양의 역사 데이터를 추적해야 합니다.
  2. 거래 빈도가 너무 높을 수 있습니다.
    • 여러 요소의 조합으로 인해 과도한 거래가 발생할 수 있습니다.
  3. 효과와 시장 관련성이 높다
    • 트렌드를 판단하는 전략, 비이성적인 행동의 영향을 받기 쉬운 방법

최적화 방향

  1. Stop Loss 로직을 추가합니다.
    • 비합리적인 행동으로 인한 더 큰 손실을 피할 수 있습니다.
  2. 최적화 변수 설정
    • 전략적 안정성을 높이기 위한 최적의 요소 조합을 찾는 것
  3. 기계 학습 요소를 추가합니다.
    • 현재 시장 상황을 판단하고 전략적 의사결정을 지원하기 위해 딥러닝을 사용합니다.

요약하다

이 전략은 동력 지표와 트렌드 지표의 다인자 조합을 통해 시장 상태를 판단하고 설정된 임계값에 따라 거래 신호를 발송한다. 전략의 장점은 구성성이 강하고, 다양한 시장 환경에 적합하며, 이해하기 쉽다는 것이다. 전략의 단점은 매개 변수를 최적화하는 데 어려움이 많고, 거래 빈도가 너무 높고, 효과는 시장과 관련이 강하다. 향후에는 중지 손실, 매개 변수 최적화 및 기계 학습 등의 수단을 추가하여 추가적으로 최적화 할 수 있다.

전략 소스 코드
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 14/03/2017
// This is modified version of Dale Legan's "Confluence" indicator written by Gary Fritz.
// ================================================================
// Here is Gary`s commentary:
// Since the Confluence indicator returned several "states" (bull, bear, grey, and zero), 
// he modified the return value a bit:
// -9 to -1 = Bearish
// -0.9 to 0.9 = "grey" (and zero)
// 1 to 9 = Bullish
// The "grey" range corresponds to the "grey" values plotted by Dale's indicator, but 
// they're divided by 10.
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////

strategy(title="Confluence", shorttitle="Confluence")
Harmonic = input(10, minval=1)
BuyBand = input(9)
SellBand = input(-9)
reverse = input(false, title="Trade reverse")
hline(SellBand, color=red, linestyle=line)
hline(BuyBand, color=green, linestyle=line)

Price = close

STL = round((Harmonic * 2) - 1 - 0.5)
ITL = round((STL * 2) - 1 - 0.5)
LTL = round((ITL * 2) - 1 - 0.5)
HOFF = round(Harmonic / 2 - 0.5)
SOFF = round(STL / 2 - 0.5)
IOFF = round(ITL / 2 - 0.5)

xHavg = sma(Price, Harmonic)
xSavg = sma(Price, STL)
xIavg = sma(Price, ITL)
xLavg = sma(Price, LTL)

xvalue2 = xSavg - xHavg[HOFF]
xvalue3 = xIavg - xSavg[SOFF]
xvalue12 = xLavg - xIavg[IOFF]

xmomsig = xvalue2 + xvalue3 + xvalue12

xLavgOHLC = sma(ohlc4, LTL - 1)

xH2 = sma(Price, Harmonic - 1)
xS2 = sma(Price, STL - 1)
xI2 = sma(Price, ITL - 1)
xL2 = sma(Price, LTL - 1)

DerivH = (xHavg * 2) - xHavg[1]
DerivS = (xSavg * 2) - xSavg[1]
DerivI = (xIavg * 2) - xIavg[1]
DerivL = (xLavg * 2) - xLavg[1]
SumDH = Harmonic * DerivH
SumDS = STL * DerivS
SumDI = ITL * DerivI
SumDL = LTL * DerivL

LengH = Harmonic - 1
LengS = STL - 1
LengI = ITL - 1
LengL = LTL - 1

N1H = xH2 * LengH
N1S = xS2 * LengS
N1I = xI2 * LengI
N1L = xL2 * LengL

DRH = SumDH - N1H
DRS = SumDS - N1S
DRI = SumDI - N1I
DRL = SumDL - N1L

SumH = xH2 * (Harmonic - 1)
SumS = xS2 * (STL - 1)
SumI = xI2 * (ITL - 1)
SumL = xLavgOHLC * (LTL - 1)

xvalue5 = (SumH + DRH) / Harmonic
xvalue6 = (SumS + DRS) / STL
xvalue7 = (SumI + DRI) / ITL
xvalue13 = (SumL + DRL) / LTL

value9 = xvalue6 - xvalue5[HOFF]
value10 = xvalue7 - xvalue6[SOFF]
value14 = xvalue13 - xvalue7[IOFF]
xmom = value9 + value10 + value14

HT = sin(xvalue5 * 2 * 3.14 / 360) + cos(xvalue5 * 2 * 3.14 / 360)
HTA = sin(xHavg * 2 * 3.14 / 360) + cos(xHavg * 2 * 3.14 / 360)
ST = sin(xvalue6 * 2 * 3.14 / 360) + cos(xvalue6 * 2 * 3.14 / 360)
STA = sin(xSavg * 2 * 3.14 / 360) + cos(xSavg * 2 * 3.14 / 360)
IT = sin(xvalue7 * 2 * 3.14 / 360) + cos(xvalue7 * 2 * 3.14 / 360)
ITA = sin(xIavg * 2 * 3.14 / 360) + cos(xIavg * 2 * 3.14 / 360)

xSum = HT + ST + IT
xErr = HTA + STA + ITA

Condition2 = (((xSum > xSum[SOFF]) and (xHavg < xHavg[SOFF])) or ((xSum < xSum[SOFF]) and (xHavg > xHavg[SOFF])))
Phase = iff(Condition2 , -1 , 1)
xErrSum = (xSum - xErr) * Phase
xErrSig = sma(xErrSum, SOFF)

xvalue70 = xvalue5 - xvalue13
xvalue71 = sma(xvalue70, Harmonic)


ErrNum = iff (xErrSum > 0 and xErrSum < xErrSum[1] and xErrSum < xErrSig, 1,
          iff (xErrSum > 0 and xErrSum < xErrSum[1] and xErrSum > xErrSig, 2, 
           iff (xErrSum > 0 and xErrSum > xErrSum[1] and xErrSum < xErrSig, 2,
             iff (xErrSum > 0 and xErrSum > xErrSum[1] and xErrSum > xErrSig, 3,
              iff (xErrSum < 0 and xErrSum > xErrSum[1] and xErrSum > xErrSig, -1,
               iff (xErrSum < 0 and xErrSum < xErrSum[1] and xErrSum > xErrSig, -2,
                 iff (xErrSum < 0 and xErrSum > xErrSum[1] and xErrSum < xErrSig, -2,
                  iff (xErrSum < 0 and xErrSum < xErrSum[1] and xErrSum < xErrSig, -3, 0))))))))


momNum = iff (xmom > 0 and xmom < xmom[1] and xmom < xmomsig , 1,
          iff (xmom > 0 and xmom < xmom[1] and xmom > xmomsig, 2,
           iff (xmom > 0 and xmom > xmom[1] and xmom < xmomsig, 2,
             iff (xmom > 0 and xmom > xmom[1] and xmom > xmomsig, 3,
              iff (xmom < 0 and xmom > xmom[1] and xmom > xmomsig, -1,
               iff (xmom < 0 and xmom < xmom[1] and xmom > xmomsig, -2,
                 iff (xmom < 0 and xmom > xmom[1] and xmom < xmomsig, -2,
                  iff (xmom < 0 and xmom < xmom[1] and xmom < xmomsig, -3, 0))))))))

TCNum =  iff (xvalue70 > 0 and xvalue70 < xvalue70[1] and xvalue70 < xvalue71, 1,
          iff (xvalue70 > 0 and xvalue70 < xvalue70[1] and xvalue70 > xvalue71, 2,
           iff (xvalue70 > 0 and xvalue70 > xvalue70[1] and xvalue70 < xvalue71, 2,
             iff (xvalue70 > 0 and xvalue70 > xvalue70[1] and xvalue70 > xvalue71, 3,
              iff (xvalue70 < 0 and xvalue70 > xvalue70[1] and xvalue70 > xvalue71, -1,
               iff (xvalue70 < 0 and xvalue70 < xvalue70[1] and xvalue70 > xvalue71, -2,
                 iff (xvalue70 < 0 and xvalue70 > xvalue70[1] and xvalue70 < xvalue71, -2,
                  iff (xvalue70 < 0 and xvalue70 < xvalue70[1] and xvalue70 < xvalue71, -3,0))))))))

value42 = ErrNum + momNum + TCNum
Confluence = iff (value42 > 0 and xvalue70 > 0, value42,
              iff (value42 < 0 and xvalue70 < 0, value42,
               iff ((value42 > 0 and xvalue70 < 0) or (value42 < 0 and xvalue70 > 0), value42 / 10, 0)))
Res1 = iff (Confluence >= 1, Confluence, 0)
Res2 = iff (Confluence <= -1, Confluence, 0)
Res3 = iff (Confluence == 0, 0, iff (Confluence > -1 and Confluence < 1, 10 * Confluence, 0))
pos = iff(Res2 >= SellBand and Res2 != 0, -1,
	     iff(Res1 <= BuyBand and Res1 != 0, 1, 
	       iff(Res3 != 0, 0, nz(pos[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("Long", when = possig == 0)	 
    strategy.close("Short", when = possig == 0)	 
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(Res1, color=green, title="Confluence", linewidth=3, style = histogram)
plot(Res2, color=red, title="Confluence", linewidth=3, style = histogram)
plot(Res3, color=gray, title="Confluence",  linewidth=3, style = histogram)