逆Kラインブレイクアウト短期取引戦略


作成日: 2023-11-21 17:03:32 最終変更日: 2023-11-21 17:03:32
コピー: 0 クリック数: 555
1
フォロー
1617
フォロワー

逆Kラインブレイクアウト短期取引戦略

概要

この戦略は,ショートライン反転取引の機会を捕捉するために使用される.それは,連続N根K線が上昇した後に空白を打つ,連続M根K線が低下した後に平仓を打つ.同時に,この戦略は,期間制限と止損停止機能を追加している.

原則

  1. 入力パラメータ:連続上昇K線数N,連続下降K線数M
  2. 論理を定義する
    • upsでは,K線数値が上がった.[1] は+1 で,0 でリセットします.
    • dns 統計値が下がる K 線数,price
  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)