Hull 이동 평균 잔액 추적 전략 사용


생성 날짜: 2023-12-29 16:26:49 마지막으로 수정됨: 2023-12-29 16:26:49
복사: 2 클릭수: 589
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

Hull 이동 평균 잔액 추적 전략 사용

개요

평형 추적 전략은 Hull 이동 평균을 주요 출시 지표로 사용하여 가격 트렌드 방향을 판단한다. 동시에, 이 전략은 다른 여러 가지 지표와 결합되어있다. 예를 들어, 기준선, 확인 지표와 같은 가격 트렌드를 검증하고 가짜 신호를 필터링한다. 출시 후, 전략은 평균 실제 파장을 사용하여 동적 상실을 계산하여 트렌드를 추적한다.

전략 원칙

평균 추적 전략의 핵심은 헐 이동 평균이다. 헐 이동 평균은 가격 변화에 더 민감하여 트렌드 방향을 효과적으로 판단할 수 있다. 가격이 헐 라인을 상향으로 돌파할 때, 상승 트렌드가 형성되는 것을 확인하고, 더 많은 것을 한다. 가격이 하향으로 돌파할 때, 하향 트렌드가 형성되고, 공백을 한다.

또한, 전략은 단기 트렌드를 판단하는 기준선 지표와 가짜 브레이크를 필터링하는 확인 지표를 도입했다. 기준선과 확인 지표가 트렌드 방향을 확인했을 때만 거래 신호가 발송됩니다.

상장 후, 전략은 ATR과 Hull EMA에서 계산된 평균 실제 파장을 사용하여 중지 위치를 설정합니다. 추세가 계속됨에 따라, 중지 라인 또한 추세를 고정하기 위해 계속 상향 / 하향으로 이동합니다.

우위 분석

평형 추적 전략은 트렌드 판단과 위험 제어의 장점을 결합하여 트렌드 상황에서 더 나은 수익을 얻을 수 있습니다. 고정된 중지 전략에 비해 이동 상쇄를 통해 트렌드 운영을 추적 할 수 있으며 시장의 정상적인 변동에 의해 상쇄되지 않습니다.

많은 지표의 조합 사용은 또한 전략이 시장 변화에 더 민감하게 만들 수 있으며, 가짜 신호를 효과적으로 필터링 할 수 있습니다. 또한, 전략은 또한 여러 개의 매개 변수를 제공하여 조정할 수 있으며, 사용자는 시장에 대한 자신의 판단에 따라 최적화 할 수 있습니다.

위험 분석

이 전략은 주로 트렌드 지표에 의존하며, 정리할 때 잘못된 신호와 스톱로스가 발생하기 쉽다. 또한, 다중 지표 조합이 지표 충돌이 발생할 수도 있다. 변수 설정이 잘못되면 전략의 성능이 좋지 않을 수 있다.

전략에 추가 판단 모듈을 추가하는 것을 고려할 수 있으며, 지표가 일치하지 않을 때 거래를 중지하거나, 투표 메커니즘을 사용하여 여러 지표의 판단 결과를 통합할 수 있습니다. 매개 변수 설정 측면에서, 피트백 최적화 방법을 통해 최적의 매개 변수를 찾을 수 있습니다.

최적화 방향

평형 추적 전략은 다음과 같은 방향으로 최적화될 수 있다:

  1. 변동률 모듈과 같은 판단 모듈을 추가하고, 높은 변동률이 있을 때 거래를 중지합니다.
  2. 기계 학습 모듈을 추가하여, 기계 학습 알고리즘을 사용하여 지표의 무게를 판단합니다.
  3. 지표 변수를 최적화하여 최적의 변수 조합을 찾습니다.
  4. 이동식 상쇄 알고리즘을 최적화하여 상쇄를 트렌드를 더 잘 추적할 수 있도록 한다.
  5. 리스크 관리 모듈을 추가합니다. 예를 들어, 상반된 중지, 동적 위치 조정 등

요약하다

평형 추적 전략은 전체적으로 우수한 트렌드 추적 전략이다. 그것은 성공적으로 트렌드 판단과 동적 중지를 결합하여 트렌드를 효과적으로 추적 할 수 있다. 더 나은 전략 성능을 얻을 수 있는 더 나은 최적화를 통해 기대된다. 이 전략은 양적 거래 전략을 구축하는 데 좋은 참조를 제공합니다.

전략 소스 코드
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// © Milleman
//@version=4
strategy("MilleMachine", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.06)


// Additional settings
Mode = input(title="Mode", defval="LongShort", options=["LongShort", "OnlyLong", "OnlyShort","Indicator Mode"])
UseTP = false                               //input(false, title="Use Take Profit?")
QuickSwitch = true                          //input(true, title="Quickswitch")
UseTC = true                                //input(true, title="Use Trendchange?")

// Risk management settings
//Spacer2 = input(false, title="======= Risk management settings =======")
Risk = input(1.0, title="% Risk",minval=0)/100
RRR = 2                                     //input(2,title="Risk Reward Ratio",step=0.1,minval=0,maxval=20)
SL_Mode = false                             // input(true, title="ON = Fixed SL / OFF = Dynamic SL (ATR)")
SL_Fix = 3                                  //input(3,title="StopLoss %",step=0.25, minval=0)/100
ATR = atr(14)                               //input(14,title="Periode ATR"))
Mul = input(2,title="ATR Multiplier",step=0.1)
xATR = ATR * Mul
SL = SL_Mode ? SL_Fix : (1 - close/(close+xATR))

// INDICATORS  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Ind(type, src, len) =>
    float result = 0
    if type=="McGinley"
        result := na(result[1]) ? ema(src, len) : result[1] + (src - result[1]) / (len * pow(src/result[1], 4))
    if type=="HMA"
        result := wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
    if type=="EHMA"
        result := ema(2*ema(src, len/2)-ema(src, len), round(sqrt(len)))
    if type=="THMA"
        lend = len/2
        result := wma(wma(src, lend/3)*3-wma(src, lend/2)-wma(src,lend), lend)
    if type=="SMA" // Simple
        result := sma(src, len)
    if type=="EMA" // Exponential
        result := ema(src, len)
    if type=="DEMA" // Double Exponential
        e = ema(src, len)
        result := 2 * e - ema(e, len)
    if type=="TEMA" // Triple Exponential
        e = ema(src, len)
        result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
    if type=="WMA" // Weighted
        result := wma(src, len)
    if type=="VWMA" // Volume Weighted
        result := vwma(src, len) 
    if type=="SMMA" // Smoothed
        w = wma(src, len)
        result := (w[1] * (len - 1) + src) / len
    if type == "RMA"
        result := rma(src, len)
    if type=="LSMA" // Least Squares
        result := linreg(src, len, 0)
    if type=="ALMA" // Arnaud Legoux
        result := alma(src, len, 0.85, 6)
    if type=="Kijun" //Kijun-sen
        kijun = avg(lowest(len), highest(len))
        result :=kijun
    if type=="WWSA" // Welles Wilder Smoothed Moving Average
        result := nz(result[1]) + (close -nz(result[1]))/len
    result

// Baseline : Switch from Long to Short and vice versa
BL_Act = input(true, title="====== Activate Baseline - Switch L/S ======")
BL_type = input(title="Baseline Type", defval="McGinley", options=["McGinley","HMA","EHMA","THMA","SMA","EMA","DEMA","TEMA","WMA","VWMA","SMMA","RMA","LSMA","ALMA","Kijun","WWSA"])
BL_src = input(close, title="BL source")
BL_len = input(50, title="BL length", minval=1)
BL = Ind(BL_type,BL_src, BL_len)

// Confirmation indicator
C1_Act = input(false, title="===== Activate Confirmation indicator =====")
C1_type = input(title="C1 Entry indicator", defval="SMA", options=["McGinley","HMA","EHMA","THMA","SMA","EMA","DEMA","TEMA","WMA","VWMA","SMMA","RMA","LSMA","ALMA","Kijun","WWSA"])
C1_src = input(close, title="Source")
C1_len = input(5,title="Length", minval=1)
C1 = Ind(C1_type,C1_src,C1_len)

// Entry indicator : Hull Moving Average
Spacer5 = input(true, title="====== ENTRY indicator =======")
EI_type = input(title="EI Entry indicator", defval="HMA", options=["McGinley","HMA","EHMA","THMA","SMA","EMA","DEMA","TEMA","WMA","VWMA","SMMA","RMA","LSMA","ALMA","Kijun","WWSA"])
EI_src = input(close, title="Source")
EI_Len = input(46,title="Length", minval=1)
EI = Ind(EI_type,EI_src,EI_Len)

// Trail stop settings
TrailActivation = input(true, title="===== Activate Trailing Stop =====")
TS_type = input(title="TS Traling Stop Type", defval="EMA", options=["McGinley","HMA","EHMA","THMA","SMA","EMA","DEMA","TEMA","WMA","VWMA","SMMA","RMA","LSMA","ALMA","Kijun","WWSA"])
TrailSLScaling = 1 //input(100, title="SL Scaling", minval=0, step=5)/100
TrailingSourceLong = Ind(TS_type,low,input(5,"Smoothing Trail Long EMA", minval=1))
TrailingSourceShort = Ind(TS_type,high,input(2,"Smoothing Trail Short EMA", minval=1))

//VARIABLES MANAGEMENT
TriggerPrice = 0.0, TriggerPrice := TriggerPrice[1]
TriggerSL = 0.0, TriggerSL := TriggerSL[1]
SLPrice = 0.0, SLPrice := SLPrice[1], TPPrice = 0.0, TPPrice := TPPrice[1]
isLong = false, isLong := isLong[1], isShort = false, isShort := isShort[1]

//LOGIC
GoLong = crossover(EI,EI[1]) and (strategy.position_size == 0.0 and QuickSwitch) and (not BL_Act or BL/BL[1] > 1) and (not C1_Act or C1>C1[1]) and (Mode == "LongShort" or Mode == "OnlyLong")
GoShort = crossunder(EI,EI[1]) and (strategy.position_size == 0.0 and QuickSwitch) and (not BL_Act or BL/BL[1] < 1) and (not C1_Act or C1<C1[1]) and (Mode == "LongShort" or Mode == "OnlyShort")
ExitLong = isLong and crossunder(EI,EI[1]) and UseTC
ExitShort = isShort and crossover(EI,EI[1]) and UseTC

//FRAMEWORK
//Reset Long-Short memory
if isLong and strategy.position_size == 0.0
    isLong := false
if isShort and strategy.position_size == 0.0
    isShort := false
//Long
if GoLong
    isLong := true, TriggerPrice := close, TriggerSL := SL
    TPPrice := UseTP? TriggerPrice * (1 + (TriggerSL * RRR)) : na
    SLPrice := TriggerPrice * (1-TriggerSL)
    Entry_Contracts = strategy.equity * Risk / ((TriggerPrice-SLPrice)/TriggerPrice) / TriggerPrice
    strategy.entry("Long", strategy.long, comment=tostring(round((TriggerSL/TriggerPrice)*1000)), qty=Entry_Contracts)
    strategy.exit("TPSL","Long", limit=TPPrice, stop=SLPrice)
if isLong
    NewValSL = TrailingSourceLong * (1 - (SL*TrailSLScaling))
    if TrailActivation and NewValSL > SLPrice
        SLPrice := NewValSL
    strategy.exit("TPSL","Long", limit=TPPrice, stop=SLPrice)
if ExitLong
    strategy.close_all(comment="TrendChange")
    isLong := false

//Short
if GoShort
    isShort := true, TriggerPrice := close, TriggerSL := SL
    TPPrice := UseTP? TriggerPrice * (1 - (TriggerSL * RRR)) : na
    SLPrice := TriggerPrice * (1 + TriggerSL)
    Entry_Contracts = strategy.equity * Risk / ((SLPrice-TriggerPrice)/TriggerPrice) / TriggerPrice
    strategy.entry("Short", strategy.short, comment=tostring(round((TriggerSL/TriggerPrice)*1000)), qty=Entry_Contracts)
    strategy.exit("TPSL","Short", limit=TPPrice, stop=SLPrice)
if isShort
    NewValSL = TrailingSourceShort * (1 + (SL*TrailSLScaling))
    if TrailActivation and NewValSL < SLPrice
        SLPrice := NewValSL
    strategy.exit("TPSL","Short", limit=TPPrice, stop=SLPrice)
if ExitShort
    strategy.close_all(comment="TrendChange")
    isShort := false

//VISUALISATION
plot(BL_Act?BL:na, color=color.blue,title="Baseline")
plot(C1_Act?C1:na, color=color.yellow,title="confirmation Indicator")
EIColor = EI>EI[1] ? color.green : color.red
Fill_EI = plot(EI, color=EIColor, linewidth=1, transp=40, title="Entry Indicator EI")
Fill_EID = plot(EI[1], color=EIColor, linewidth=1, transp=40, title="Entry Indicator EID")
fill(Fill_EI,Fill_EID, title="EI_Fill", color=EIColor,transp=50)

plot(strategy.position_size != 0.0 and (isLong or isShort) ? TriggerPrice : na, title="TriggerPrice", color=color.yellow, style=plot.style_linebr)
plot(strategy.position_size != 0.0 and (isLong or isShort) ? TPPrice : na, title="TakeProfit", color=color.green, style=plot.style_linebr)
plot(strategy.position_size != 0.0 and (isLong or isShort) ? SLPrice : na, title="StopLoss", color=color.red, style=plot.style_linebr)
bgcolor(isLong[1] and cross(low,SLPrice) and low[1] > SLPrice and TriggerPrice>SLPrice ? color.yellow : na, transp=75, title="SL Long")
bgcolor(isShort[1] and cross(high,SLPrice) and high[1] < SLPrice and TriggerPrice<SLPrice ? color.yellow : na, transp=75, title="SL Short")