ストップ損失追跡戦略のダイナミック価格チャネル

作者: リン・ハーンチャオチャン,日付: 2024-02-01 10:52:33
タグ:

img

概要

この戦略は,ドンキアン価格チャネル指標に基づいて開発されている.この指標は,特定の期間の最高価格と最低価格を計算することによって価格チャネルを形成する.この戦略は,価格チャネルを利用して双方向取引を実施し,ストップ損失と利益を取ること価格を設定する.ストップ損失価格は価格チャネルの中間線に固定され,利益を取ること価格は価格チャネルの上下限を超えて一定のパーセントに設定される.この戦略は,ストップ損失と利益を取ることを追跡することも実装する.

戦略原則

まず,戦略は,パラメータpclenに基づいて価格チャネルの上限hと下限lを計算します. 中間線の中心は価格チャネルの上限と下限の平均です. その後,長期と短期の取利益パラメータtpに従って取利益価格tplとtpsが計算されます.ストップ損失価格は価格チャネルの中間線の中心に固定されます. 価格チャネルを突破すると,さまざまな方向の取引ポジションはリスクサイズのリスクロングとリスクショートポジションに応じて計算されます. 戦略は価格がチャネルに戻ると閉じる. さらに,時間フィルタリングは指定された日付範囲内でのみ取引するように設定されています.

具体的な取引論理は:

ロングエントリー信号: 価格がチャネル上限 h を超えてチャネルに戻るとロングを開く

ロング エクシート シグナル: 価格がチャネルの中央線の中央より低いとき (ストップ・ロース) または利益を得る価格 (tpl) より高いときロングを閉じる.

ショートエントリー信号: 価格がチャネル下限1を下回りチャネルに戻るとショートオープン

ショートアウトシグナル: 価格がチャネルの中央線中心より高く (ストップ損失) または利益率より低く (利益率より低い) 時ショート閉じる

利点分析

この戦略の利点は次のとおりです.

  1. 双方向取引は価格動向の逆転を捉える
  2. 価格チャネルを使用してトレンド方向を決定し,誤ったブレイクを避ける
  3. リスクをコントロールするためにストップ・ロスを設定し,利益を取ります
  4. 制御可能なリスクを達成するために,リスクサイズに関連したポジションサイズを計算する
  5. ストップ・ロスのトラッキングを実施し,より多くの利益をロックするために利益を取ります

リスク分析

この戦略にはいくつかのリスクもあります:

  1. 価格チャネルのパラメータの設定が不適切である場合,取引頻度が高すぎたり,取引機会が逃れることもあります.
  2. ストップ・ロスの価格が幅が大きすぎるとリスクリスクが増加する可能性があります
  3. 高波動期間の利益を追跡が早急に発生する可能性があります

これらのリスクは,パラメータの調整と手動監視によって軽減され制御できます.

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

この戦略は,次の側面でも最適化できます.

  1. 範囲限定市場での頻繁な開閉を避けるため,より多くの指標フィルターを追加します.
  2. ATRストップロスのように,異なるストップロスのアルゴリズムと利益を取ることができる.
  3. 傾向の方向性を決定するために,より長い時間枠を使用したクロスタイムフレーム取引システムに拡張する
  4. 資本利用率に基づいてポジションを調整するポジションサイズ化モジュールを追加
  5. 偽のブレイクを避けるために価格ブレイクの成功率を判断するための機械学習モデルを組み込む

結論

結論として,これは価格チャネル指標を使用して両方向取引を実施するための効果的な戦略です.適切なストップ・ロスト,テイク・プロフィート,ポジションサイズのコントロールモジュールにより,リスクは適切に制御できます.いくつかの最適化と調整により,強力な定量的な取引戦略になることができます.


/*backtest
start: 2023-01-31 00:00:00
end: 2024-01-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2020

//@version=4
strategy(title = "Noro's RiskDonchian Strategy", shorttitle = "RiskDonchian str", overlay = true, default_qty_type = strategy.percent_of_equity, initial_capital = 100, default_qty_value = 100, commission_value = 0.1)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
tp = input(defval = 20.0, minval = 1, title = "Take-profit, %")
tptype = input(defval = "2. Fix", options = ["1. None", "2. Fix", "3. Trailing"], title = "Take-profit type")
sltype = input(defval = "2. Center", options = ["1. None", "2. Center"], title = "Take-profit type")
risklong  = input(5.0, minval = 0.0, maxval = 99.9, title = "Risk size for long, %")
riskshort = input(5.0, minval = 0.0, maxval = 99.9, title = "Risk size for short, %")
pclen = input(50, minval = 1, title = "Price Channel Length")
showll = input(true, defval = true, title = "Show lines")
showbg = input(false, defval = false, title = "Show Background")
showof = input(true, defval = true, title = "Show Offset")
showlabel = input(true, defval = true, title = "Show label")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Price Channel
h = highest(high, pclen)
l = lowest(low, pclen)
center = (h + l) / 2

//Take-profit
tpl = 0.0
tpl := tptype == "2. Fix" and strategy.position_size > 0 ? tpl[1] : h * (100 + tp) / 100

//Stop-loss
tps = 0.0
tps := tptype == "2. Fix" and strategy.position_size < 0 ? tps[1] : l * (100 - tp) / 100

//Lines
tplcol = showll and needlong and tptype != "1. None" ? color.lime : na
pclcol = showll and needlong ? color.blue : na
sllcol = showll and needlong and sltype != "1. None" ? color.red : na
tpscol = showll and needshort and tptype != "1. None" ? color.lime : na
pcscol = showll and needshort ? color.blue : na
slscol = showll and needshort and sltype != "1. None" ? color.red : na
offset = showof ? 1 : 0
plot(tpl, offset = offset, color = tplcol, title = "TP Long")
plot(h, offset = offset, color = pclcol, title = "Channel High")
plot(center, offset = offset, color = sllcol, title = "SL Long")
plot(center, offset = offset, color = slscol, title = "SL Short")
plot(l, offset = offset, color = pcscol, title = "Channel Low")
plot(tps, offset = offset, color = tpscol, title = "TP Short")

//Background
size = strategy.position_size
bgcol = showbg == false ? na : size > 0 ? color.lime : size < 0 ? color.red : na
bgcolor(bgcol, transp = 70)

//Lot size
risksizelong = -1 * risklong
risklonga = ((center / h) - 1) * 100
coeflong = abs(risksizelong / risklonga)
lotlong = (strategy.equity / close) * coeflong
risksizeshort = -1 * riskshort
riskshorta = ((center / l) - 1) * 100
coefshort = abs(risksizeshort / riskshorta)
lotshort = (strategy.equity / close) * coefshort

//Trading
truetime = time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)
mo = 0
mo := strategy.position_size != 0 ? 0 : high >= center[1] and low <= center[1] ? 1 : mo[1]

if h > 0
    longlimit = tptype == "1. None" ? na : tpl
    longstop = sltype == "1. None" ? na : center
    strategy.entry("Long", strategy.long, lotlong, stop = h, when = strategy.position_size <= 0 and needlong and truetime and mo)
    strategy.exit("TP Long", "Long", limit = longlimit, stop = longstop)
    shortlimit = tptype == "1. None" ? na : tps
    shortstop = sltype == "1. None" ? na : center
    strategy.entry("Short", strategy.short, lotshort, stop = l, when = strategy.position_size >= 0 and needshort and truetime and mo)
    strategy.exit("Exit Short", "Short", limit = shortlimit, stop = shortstop)
if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()
    strategy.cancel("Long")
    strategy.cancel("Short")
    
if showlabel

    //Drawdown
    max = 0.0
    max := max(strategy.equity, nz(max[1]))
    dd = (strategy.equity / max - 1) * 100
    min = 100.0
    min := min(dd, nz(min[1]))
    
    //Label
    min := round(min * 100) / 100
    labeltext = "Drawdown: " + tostring(min) + "%"
    var label la = na
    label.delete(la)
    tc = min > -100 ? color.white : color.red
    osx = timenow + round(change(time)*10)
    osy = highest(100)

もっと