多時間枠ダイナミックバックテスト戦略

作者: リン・ハーンチャオチャン開催日:2023年11月21日 17:07:17
タグ:

img

概要

この戦略は,複数のタイムフレームのダイナミックバックテストメカニズムを使用して,異なる時間帯における最高価格と最低価格を比較して価格動向を決定し,低リスクの仲介を実現します.

戦略の論理

この戦略は,カスタム関数 f_get_htfHighLow を呼び出し,異なるタイムフレームで最高価格 (nhigh) と最低価格 (nlow) を取得する.特に,ユーザーによって定義されたインプットである時間帯解像度,時間帯倍数 HTFMultiplier,バックテストパラメータlookheadとギャップ,およびオフセットに基づいて,セキュリティ関数を呼び出し,異なるタイムフレームで最高値と最低値を取得する.

例えば,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")


もっと