逆転 短期間のブレイクアウト取引戦略

作者: リン・ハーンチャオチャン,日付:2023年11月21日17時03分32秒
タグ:

img

概要

この戦略は,短期間の逆転取引機会を把握することを目的としています. N 連続したアップバーの後,ショートポジションを開き,M 連続したダウンバー後,ポジションを閉じます.また,タイムフレームフィルターとストップ・ロスト/テイク・プロフィート機能も組み込みます.

論理

  1. 入力パラメータ: 連続した上行数 N,連続した下行数 M
  2. 定義:
    • ups は up-bar の数,価格>価格[1] を数える. +1 を加えた場合 0 にリセットする.
    • dnsはダウンバーの数,価格<価格[1] +1,否則0にリセットする
  3. 入力: ups≥Nで短く, dns≥Mで近く
  4. エクジット:固定ストップ・ロース/テイク・プロフィートまたはタイムフレーム終了

利点

  1. 短期取引に適した逆転取引機会を把握する
  2. 柔軟な時間枠設定 異なる取引計画に対応する
  3. リスク管理を容易にする 組み込みストップ・ロース/得益

リスク

  1. 短期的な逆転は失敗し,再び逆転して損失をもたらす可能性があります.
  2. 合理的な N,M パラメータが必要,大きすぎるか小さすぎる
  3. 不適切な停止時間は,時間の損失を停止することができない可能性があります

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

  1. トレンド・インジケーターと組み合わせて,トレンド・トレードに対して回避する
  2. パラメータのダイナミック調整 N,M
  3. ストップ・ロスのメカニズムを最適化

結論

この戦略は,統計的なK線パターンを通じて短期間の取引機会を把握する.合理的なパラメータ調整とリスク管理措置は安定した利益にとって不可欠である.傾向分析とダイナミックパラメータ調整を組み合わせるさらなる改善は,さらに優れたパフォーマンスをもたらす可能性がある.


/*backtest
start: 2023-11-13 00:00:00
end: 2023-11-20 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Strategy
strategy("Up/Down Short Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)

// There will be no short entries, only exits from long.
strategy.risk.allow_entry_in(strategy.direction.short)

consecutiveBarsUp = input(1, title='Consecutive Bars Up')
consecutiveBarsDown = input(1, title='Consecutive Bars Down')

price = close

ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0

dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0

// Strategy Backtesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true

//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = (time(timeframe.period, startendtime))
timetoclose = na(time(timeframe.period, startendtime))

// Stop Loss & Take Profit Tick Based
enablesltp = input(false, title='Enable Take Profit & Stop Loss')
stopTick = input(5.0, title='Stop Loss Ticks', type=input.float) / 100
takeTick = input(10.0, title='Take Profit Ticks', type=input.float) / 100

longStop = strategy.position_avg_price - stopTick
shortStop = strategy.position_avg_price + stopTick
shortTake = strategy.position_avg_price - takeTick
longTake = strategy.position_avg_price + takeTick

plot(strategy.position_size > 0 and enablesltp ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesltp ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enablesltp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enablesltp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")

// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
message_takeprofit = input("", title="Take Profit message")
message_stoploss = input("", title="Stop Loss message")

// Strategy Execution
if (ups >= consecutiveBarsUp) and time_cond and timetobuy
    strategy.entry("Long", strategy.long, stop = high + syminfo.mintick, alert_message = message_enterlong)
    
if (dns >= consecutiveBarsDown) and time_cond and timetobuy
    strategy.entry("Short", strategy.short, stop = low + syminfo.mintick, alert_message = message_entershort)
    
if strategy.position_size > 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closeshort)
    
if strategy.position_size > 0 and enablesltp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_takeprofit)
if strategy.position_size < 0 and enablesltp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_stoploss)






もっと