ドンチアン・トレンド 戦略を踏む

作者: リン・ハーンチャオチャン,日付: 2024-01-31 16時53分31秒
タグ:

img

概要

ドンキアン・トレンドフォローリング戦略は,記事"ブラックボックス・トレンドフォローリング"で説明されたドンキアン・チャネル原理に基づいて開発されています.この戦略は,トレンド方向を決定するためにドンキアン・チャネルを使用して,価格が新しい高値または低値に達するとロングまたはショートポジションを確立します.

戦略の論理

この戦略は,トレンド方向を判断するためにドンチアンチャネル指標に基づいています.ドンチアンチャネルは,より長い期間チャネルとより短い期間チャネルで構成されています.価格がより長い期間チャネルを突破すると,トレンドの始まりをシグナルします.価格がより短い期間チャネルを突破すると,トレンドの終わりをシグナルします.

具体的には,長期チャネル長さは50日または20日,短期間チャネル長さは50日,20日または10日である.価格が50日間の最高価格に等しい場合,ロングポジションが開かれる.価格が50日間の最低価格に等しい場合,ショートポジションが開かれる.価格が20日または10日間の最低価格に等しい場合,ロングポジションは閉鎖される.価格が20日または10日間の最高価格に等しい場合,ショートポジションは閉鎖される.

異なる期間の2つのドンキアンチャネルを組み合わせることで,トレンドが始まるときにポジションを確立する方向性を決定し,トレンドが終わるときにタイムリーストップロスを実現することができます.

利点分析

この戦略の主な利点は以下の通りです.

  1. トレンドを把握する能力は強い.ドンチアン・チャネルのブレイクを使用してトレンドの始まりと終わりを効果的に特定することによってトレンドを追跡することができます.

  2. 適切なリスク管理です. 移動ストップ損失を使用して単一の取引損失を制御します.

  3. 柔軟なパラメータ調整 異なる製品や市場環境に適応するために,チャネル期間の組み合わせを自由に選択できます.

  4. シンプルで明快な取引論理です 分かりやすく実行できます

リスク分析

この戦略のリスクは以下のとおりです.

  1. 市場に適応できない.トレンドが不明確である場合,連続して小さなストップ損失を被る.

  2. ブレイク失敗リスク 価格がチャネルを突破して後退し,ストップ損失を引き起こす可能性があります

  3. 期間の選択リスク チャンネルの期間の設定が不適切であれば,ノイズ取引が起こる可能性があります.

  4. シェルプ比率減少リスク ストップロスを調整せずにポジションサイズを拡大すると,シェルプ比率が低下する可能性があります.

解決策は次のとおりです

  1. 適切なチャネル周期組み合わせを選択するためにパラメータを最適化します.
  2. リスクを制御するために ポジションサイズとストップロスを適切に調整します
  3. この戦略を 明らかな傾向のある製品や市場に適用してください

オプティマイゼーションの方向性

この戦略の最適化方向は:

  1. フィルター条件を追加して,ブレイクを避ける.例えば,音量を組み合わせて,真のブレイクを判断する.

  2. チャンネルの期間組み合わせとポジションサイズを最適化して利益率を増加させる.適応ストップロスは導入できる.

  3. 最適なパラメータセットを見つけるために ブレイクポイント最適化を試みています.

  4. 機械学習アルゴリズムを 増やして 動的最適化とパラメータの調整を

結論

ドンチアントレンドフォロー戦略は,ダブルチャネルを使用して価格トレンドの開始と終止を特定し,効果的なシングルトレード損失制御を伴うトレンドフォロートレードスタイルを採用する.この戦略は柔軟なパラメータ調整と簡単な実装を有し,非常に実践的なトレンドフォロー戦略である.しかし,レンジバインド市場での収益性が不十分であり,パラメータ選択によるリスクは注目に値する.さらなる最適化はより良い戦略パフォーマンスにつながります.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title="Donchian", overlay=true,
     pyramiding=0, initial_capital=1000,
     commission_type=strategy.commission.cash_per_order,
     commission_value=2, slippage=2)

// =============================================================================
// VARIABLES
// =============================================================================

donch_string = input.string(title="Length", options = ['20/10','50/20', '50/50', '20/20', '100/100'], defval='50/50')
permit_long  = input.bool(title = 'Permit long', defval = true)
permit_short  = input.bool(title = 'Permit short', defval = true)
risk_percent = input.float(title="Position Risk %", defval=0.5, step=0.25)
stopOffset = input.float(title="ATR mult", defval=2.0, step=0.5)
atrLen = input.int(title="ATR Length", defval=20)
close_in_end  = input.bool(title = 'Close in end', defval = true)
permit_stop  = input.bool(title = 'Permit stop', defval = false)

// =============================================================================
// CALCULATIONS
// =============================================================================

donch_len_big = 
 donch_string == '50/20' ? 50 : 
 donch_string == '50/50' ? 50 : 
 donch_string == '20/20' ? 20 : 
 donch_string == '20/10' ? 20 : 
 donch_string == '100/100' ? 100 : 
 na
donch_len_small = 
 donch_string == '50/20' ? 20 : 
 donch_string == '50/50' ? 50 : 
 donch_string == '20/20' ? 20 : 
 donch_string == '20/10' ? 10 : 
 donch_string == '100/100' ? 100 : 
 na

big_maxclose = ta.highest(close, donch_len_big)
big_minclose = ta.lowest(close, donch_len_big)
small_maxclose = ta.highest(close, donch_len_small)
small_minclose = ta.lowest(close, donch_len_small)

atrValue = ta.atr(atrLen)[1]

tradeWindow  = true

// =============================================================================
// NOTOPEN QTY
// =============================================================================

risk_usd = (risk_percent / 100) * strategy.equity
atr_currency = (atrValue * syminfo.pointvalue)
notopen_qty = risk_usd / (stopOffset * atr_currency)

// =============================================================================
// LONG STOP
// =============================================================================

long_stop_price = 0.0
long_stop_price := 
 strategy.position_size > 0 and na(long_stop_price[1]) ? strategy.position_avg_price - stopOffset * atrValue : 
 strategy.position_size > 0 and strategy.openprofit > risk_usd ? strategy.position_avg_price:
 strategy.position_size > 0 ? long_stop_price[1] : 
 na

// =============================================================================
// SHORT STOP
// =============================================================================

short_stop_price = 0.0
short_stop_price := 
 strategy.position_size < 0 and na(short_stop_price[1]) ? strategy.position_avg_price + stopOffset * atrValue : 
 strategy.position_size < 0 and strategy.openprofit > risk_usd ? strategy.position_avg_price :
 strategy.position_size < 0 ? short_stop_price[1] : 
 na

// =============================================================================
// PLOT VERTICAL COLOR BAR
// =============================================================================

cross_up = strategy.position_size <= 0 and close == big_maxclose and close >= syminfo.mintick and tradeWindow and permit_long
cross_dn =  strategy.position_size >= 0 and close == big_minclose and close >= syminfo.mintick and tradeWindow and permit_short
bg_color = cross_up ? color.green : cross_dn ? color.red : na
bg_color := color.new(bg_color, 70)
bgcolor(bg_color)

// =============================================================================
// PLOT DONCHIAN LINES
// =============================================================================

s1 = cross_up ? na : cross_dn ? na : strategy.position_size != 0 ? strategy.position_avg_price : na
s2 = cross_up ? na : cross_dn ? na : strategy.position_size > 0 ? small_minclose : strategy.position_size < 0 ? small_maxclose : na
s3 = cross_up ? na : cross_dn ? na : not permit_stop ? na : 
 strategy.position_size > 0 ? long_stop_price : strategy.position_size < 0 ? short_stop_price : na

plot(series=big_maxclose, style=plot.style_linebr, color=color.black, linewidth=1, title="Donch Big Maxclose Black")
plot(series=big_minclose, style=plot.style_linebr, color=color.black, linewidth=1, title="Donch Big Minclose Black")

plot(series=s1, style=plot.style_linebr, color=color.yellow, linewidth=2, title="Entry Yellow")
plot(series=s2, style=plot.style_linebr, color=color.red, linewidth=1, title="Donch Small Red")
plot(series=s3, style=plot.style_linebr, color=color.fuchsia, linewidth=2, title="Stop Fuchsia")

// =============================================================================
// ENTRY ORDERS
// =============================================================================

if strategy.position_size <= 0 and close == big_maxclose and close >= syminfo.mintick and tradeWindow and permit_long
    strategy.entry("Long", strategy.long, qty=notopen_qty)

if strategy.position_size >= 0 and close == big_minclose and close >= syminfo.mintick and tradeWindow and permit_short
    strategy.entry("Short", strategy.short, qty=notopen_qty)

// =============================================================================
// EXIT ORDERS
// =============================================================================

if strategy.position_size > 0 and permit_stop
    strategy.exit(id="Stop", from_entry="Long", stop=long_stop_price)

if strategy.position_size < 0 and permit_stop
    strategy.exit(id="Stop", from_entry="Short", stop=short_stop_price)

// ==========

if strategy.position_size > 0 and close == small_minclose and not barstate.islast
    strategy.close(id="Long", comment='Donch')

if strategy.position_size < 0 and close == small_maxclose and not barstate.islast
    strategy.close(id="Short", comment='Donch')

// ==========

if close_in_end
    if not tradeWindow
        strategy.close_all(comment='Close in end')

// =============================================================================
// END
// =============================================================================

もっと