멀티 타임프레임 동적 백테스팅 전략

저자:차오장, 날짜: 2023-11-21 17:07:17
태그:

img

전반적인 설명

이 전략은 다양한 기간에 걸쳐 가장 높은 가격과 가장 낮은 가격을 비교하여 가격 추세를 결정하기 위해 다중 시간 프레임 역동적 역 테스트 메커니즘을 사용하며, 이로 인해 저위험 중재가 달성됩니다.

전략 논리

이 전략은 사용자 정의 함수 f_get_htfHighLow를 호출하여 서로 다른 시간 프레임에서 가장 높은 가격 (nhigh) 및 가장 낮은 가격 (nlow) 을 검색합니다. 구체적으로, 시간 기간 해상도, 시간 기간 곱기 HTFMultiplier, 백테스팅 매개 변수 룩헤드 및 격차 및 오프셋과 같은 사용자 정의 입력값을 기반으로, 보안 함수를 호출하여 서로 다른 시간 프레임에서 가장 높고 가장 낮은 가격을 얻습니다.

예를 들어, 0의 오프셋은 현재 바의 가장 높고 가장 낮은 가격을 검색하고, 1의 오프셋은 이전 바에서 그 가격을 검색합니다. 바 사이의 가격 변화를 비교함으로써 트렌드 방향이 결정됩니다.

가장 높은 가격과 가장 낮은 가격 모두 상승하면 상승 추세가 확인됩니다. 두 가격 모두 떨어지면 하락 추세가 나타납니다. 중재 거래를 구현하기 위해 트렌드 방향에 따라 긴장 또는 단축 지위가 취됩니다.

장점

  1. 멀티 타임프레임 분석을 통해 정확도를 향상
  2. 동적 백테스팅을 통해 재칠을 피합니다.
  3. 유연한 매개 변수 시장 변화에 대응
  4. 명확한 트렌드에 대한 포지션만 있는 경우 리스크 감소

위험성

  1. 여러 시간 프레임에 대한 잘못된 판단
  2. 부적절한 백테스팅 매개 변수에서 재칠
  3. 높은 비용과 과도한 거래로 인한 미끄러짐

해결책:

  1. 정확성을 위해 시간 기간을 최적화
  2. 다시 칠하는 것을 방지하기 위해 엄격한 테스트 매개 변수
  3. 조절 주파수까지 온도 높은 입수 조건

더 나은 기회

  1. 트렌드를 위해 AI를 활용하기 위해 ML을 추가하십시오.
  2. 동적 위치 크기를 위한 변동성 필터를 포함합니다.
  3. 손실을 효과적으로 제한하기 위해 정지를 도입합니다.

결론

전략 논리는 분명하며, 트렌드를 결정하고 인간 편향을 최소화하기 위해 멀티 타임프레임 동적 백테스팅을 사용합니다. 매개 변수 최적화 및 기능 확장을 통해 정제됨으로써 추가 연구와 추적에 가치가있는 안정성과 수익성을 향상시키는 중요한 잠재력을 보여줍니다.


/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
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/
// © HeWhoMustNotBeNamed

//@version=4
strategy("HTF High/Low Repaint Strategy", overlay=true, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)

i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)
inDateRange = true

resolution = input("3M", type=input.resolution)
HTFMultiplier = input(22, minval=1, step=1)
offset = input(0, minval=0, step=1)
lookahead = input(true)
gaps = false

f_secureSecurity_on_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on)
f_secureSecurity_on_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off)
f_secureSecurity_off_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_on)
f_secureSecurity_off_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_off)

f_multiple_resolution(HTFMultiplier) => 
    target_Res_In_Min = timeframe.multiplier * HTFMultiplier * (
      timeframe.isseconds   ? 1. / 60. :
      timeframe.isminutes   ? 1. :
      timeframe.isdaily     ? 1440. :
      timeframe.isweekly    ? 7. * 24. * 60. :
      timeframe.ismonthly   ? 30.417 * 24. * 60. : na)

    target_Res_In_Min     <= 0.0417       ? "1S"  :
      target_Res_In_Min   <= 0.167        ? "5S"  :
      target_Res_In_Min   <= 0.376        ? "15S" :
      target_Res_In_Min   <= 0.751        ? "30S" :
      target_Res_In_Min   <= 1440         ? tostring(round(target_Res_In_Min)) :
      tostring(round(min(target_Res_In_Min / 1440, 365))) + "D"

f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset)=>
    derivedResolution = resolution == ""?f_multiple_resolution(HTFMultiplier):resolution
    nhigh_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, high, offset) 
    nlow_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, low, offset)
    
    nhigh_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, high, offset) 
    nlow_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, low, offset)
    
    nhigh_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, high, offset) 
    nlow_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, low, offset)
    
    nhigh_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, high, offset) 
    nlow_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, low, offset)
    
    nhigh = lookahead and gaps ? nhigh_on_on :
             lookahead and not gaps ? nhigh_on_off :
             not lookahead and gaps ? nhigh_off_on :
             not lookahead and not gaps ? nhigh_off_off : na
    nlow = lookahead and gaps ? nlow_on_on :
             lookahead and not gaps ? nlow_on_off :
             not lookahead and gaps ? nlow_off_on :
             not lookahead and not gaps ? nlow_off_off : na
    [nhigh, nlow]
    
[nhigh, nlow] = f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset)
[nhighlast, nlowlast] = f_get_htfHighLow(resolution, HTFMultiplier, lookahead, gaps, offset+1)
plot(nhigh , title="HTF High",style=plot.style_circles, color=color.green, linewidth=1) 
plot(nlow , title="HTF Low",style=plot.style_circles, color=color.red, linewidth=1)

buyCondition = nhigh > nhighlast and nlow > nlowlast
sellCondition = nhigh < nhighlast and nlow < nlowlast

strategy.entry("Buy", strategy.long, when= buyCondition and inDateRange, oca_name="oca_buy")
strategy.entry("Sell", strategy.short, when= sellCondition and inDateRange, oca_name="oca_sell")


더 많은