ドンチアン運河からの脱出戦略

作者: リン・ハーンチャオチャン,日付: 2023-09-14 14:44:44
タグ:

戦略の論理

ドンキアン・チャネル・ブレークアウト戦略は,ドンキアン・チャネルをベースとしたトレンドフォロー戦略である.ロング・ショートポジションのエントリー・ストップ・ロストポイントを特定するために,指定された期間の最高高値と最低低値を使用する.

入場規則は,価格がバックバック期間の最高値 (例えば20日) を突破するとロング (long) になり,価格が他のバックバック期間の最低値 (例えば10日) を突破するとショート (short) します.

EXITのルールは,ロングポジションはチャネルの中または下帯で停止し,ショートポジションは中または上帯で停止する.中帯は,指定された期間 (例えば10日) の最高値と最低値の平均である.

例えば,以下のようなパラメータを持つ BTCUSDTの取引:

  • ロング エントリー リビュー 期間: 20 日
  • 長期ストップ損失回顧期間: 10日
  • 中央帯でのストップ損失: はい
  • 短いエントリー回顧期間: 10日
  • 短期ストップ損失回顧期間: 20日
  • 中央帯でのストップ損失: はい

入力・停止のルールは次のとおりです

  • 価格が20日間の高値を超えるとロングする
  • 長期ストップ損失 10 日間の高値と低値の真ん中点
  • 価格が10日間の低値を下回るとショート
  • ストップ・ロスのショート 20 日高値と低値の中央点

振り返り期間を動的に調整することで,戦略は市場サイクル全体で最適化され,より良い報酬/リスクのトレンドを把握することができます.

利点

  • ブレイクアウトは傾向の方向性を早期に特定することができます
  • 価格に近いストップ損失はリスク管理に役立ちます
  • 柔軟なパラメータにより,異なるサイクルに最適化できます.

リスク

  • ブレイクアウトは,ウィップソーに易い,有効性を確認する必要があります
  • ストップ損失を閉じ,不安定な市場でのシェイクアウトを受けやすい
  • パラメータの調節が不十分である場合,過剰な取引または不十分なストップにつながる可能性があります.

概要

ドンチアン・チャネル・ブレイクアウトは,トレンドを特定するためにブレイクアウトを使用し,チャネルミッドポイント/バンドはリスクを制御するためのストップとして使用する.バックバック期間を最適化することで,強い動きでトレンドの捕獲を改善することができます.しかし,ブレイクアウトの有効性やシェイクアウトについては注意が必要です.全体的にこの戦略は中長期トレンド取引に適していますが,不安定な市場で苦労する可能性があります.


/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Donchian Channel Strategy", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.036)

//Long optopns
buyPeriodEnter = input(10, "Channel Period for Long enter position")
buyPeriodExit = input(10, "Channel Period for Long exit position")
isMiddleBuy = input(true, "Is exit on Base Line? If 'no' - exit on bottom line")
takeProfitBuy = input(2.5, "Take Profit (%) for Long position")
isBuy = input(true, "Allow Long?")

//Short Options
sellPeriodEnter = input(20, "Channel Period for Short enter position")
sellPeriodExit = input(20, "Channel Period for Short exit position")
isMiddleSell = input(true, "Is exit on Base Line? If 'no' - exit on upper line")
takeProfitSell = input(2.5, "Take Profit (%) for Short position")
isSell = input(true, "Allow Short?")

// Test Start
startYear = input(2005, "Test Start Year")
startMonth = input(1, "Test Start Month")
startDay = input(1, "Test Start Day")
startTest = timestamp(startYear,startMonth,startDay,0,0)

//Test End
endYear = input(2050, "Test End Year")
endMonth = input(12, "Test End Month")
endDay = input(30, "Test End Day")
endTest = timestamp(endYear,endMonth,endDay,23,59)

timeRange = time > startTest and time < endTest ? true : false

// Long&Short Levels
BuyEnter = highest(buyPeriodEnter)
BuyExit = isMiddleBuy ? ((highest(buyPeriodExit) + lowest(buyPeriodExit)) / 2): lowest(buyPeriodExit)

SellEnter = lowest(sellPeriodEnter)
SellExit = isMiddleSell ? ((highest(sellPeriodExit) + lowest(sellPeriodExit)) / 2): highest(sellPeriodExit)

// Plot Data
plot(BuyEnter, style=plot.style_line, linewidth=2, color=color.blue, title="Buy Enter")
plot(BuyExit, style=plot.style_line, linewidth=1, color=color.blue, title="Buy Exit", transp=50)
plot(SellEnter, style=plot.style_line, linewidth=2, color=color.red, title="Sell Enter")
plot(SellExit, style=plot.style_line, linewidth=1, color=color.red, title="Sell Exit", transp=50)

// Calc Take Profits
TakeProfitBuy = 0.0
TakeProfitSell = 0.0
if strategy.position_size > 0
    TakeProfitBuy := strategy.position_avg_price*(1 + takeProfitBuy/100)
    
if strategy.position_size < 0
    TakeProfitSell := strategy.position_avg_price*(1 - takeProfitSell/100)

// Long Position    
if isBuy and timeRange
    strategy.entry("Long", strategy.long, stop = BuyEnter, when = strategy.position_size == 0) 
    
strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TakeProfitBuy, when = strategy.position_size > 0)

// Short Position
if isSell and timeRange
    strategy.entry("Short", strategy.short, stop = SellEnter, when = strategy.position_size == 0) 
    
strategy.exit("Short Exit", "Short", stop=SellExit, limit = TakeProfitSell, when = strategy.position_size < 0)

// Close & Cancel when over End of the Test
if time > endTest
    strategy.close_all()
    strategy.cancel_all()


もっと