Myo_LS_D 定量戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-15 14:56:03
タグ:

img

概要

Myo_LS_D定量戦略は,ロングとショートポジションをベースとした双軌追跡ストップ・プロフィート戦略である.この戦略は,移動平均値,価格突破率,リスク・リターン比率などの複数の指標を組み合わせ,取引シグナルを構築する.正確なトレンド判断の前提で高い勝利率と利益率を達成する.

原則

戦略は主にトレンド判断モジュール,ロングポジションモジュール,ショートポジションモジュール,ストップ・プロフィート・モジュールの追跡などで構成されています.

  1. トレンド判断モジュールは,Donchainチャネルを使用して全体的なトレンド方向を決定します.ロングに行くための前提条件は上昇傾向であり,ショートに行くには下落傾向が必要です.

  2. ロングポジションモジュールは,新しい高値,低値,ロング移動平均ポジションなどの要因を考慮する.ショートポジションモジュールは,新しい高値,低値,ショート移動平均ポジション,その他の要因を考慮する.これは,重要な価格ポイントを上向きまたは下向きに突破する際にポジションを開設することを保証する.

  3. 追跡ストップ・プロフィートモジュールは,異なるサイクルの2つのSMA移動平均値を使用して,価格の変化をリアルタイムで追跡します.価格が移動平均線を突破すると,ポジションは利益のために閉鎖されます.この種のリアルタイムトラッキングは,トレンドからの利益を最大化することができます.

  4. ストップ・ロスの設定は,ストップ・ロスの拡大を考慮し,ストップ・ロスのポイントをサポートレベルから遠ざけ,ノックアウトを避ける.

利点分析

この戦略の最大の利点は,長期と短期のポジションの分離とストップ・プロフィートの追跡戦略です.特に,主に以下に表されています.

  1. ロングとショートポジションを別々に設定することで,一方的なトレンド取引機会を把握することで,利益の機会を最大化できます.

  2. ストップ・プロフィートの追跡は,リアルタイム調整によりより高い利益率を得ることができます.従来のストップ・プロフィート方法と比較して,収入は大幅に改善できます.

  3. ストップを拡大すれば ノックアウトする確率が減り 損失のリスクも軽減できます

リスク と 解決策

この戦略の主なリスクは以下の点に集中しています

  1. 誤ったトレンド判断は,反対のポジションと損失を引き起こす可能性があります. 最適化は,Donchainパラメータを適切に調整するか,判断のための他の指標を追加することによって達成できます.

  2. ストップ・プロフィートの追跡は攻撃的すぎるため,利益を維持できずに利益を早急に停止する可能性があります. ストップ・プロフィートの移動平均間の間隔を適切に増加することによって最適化することができます.

  3. ストップ・ロスの範囲は小さすぎるため,ノックアウトする可能性が高まる.ストップ・ロスの大きさを適切に拡大することでリスクは軽減できる.

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

この戦略の主要な最適化方向は以下の通りである.

  1. トレンド判断モジュールを最適化して判断の精度を向上させる.MACDなどのより多くの指標を組み合わせることを検討する.

  2. ストップ・プロフィートの追跡方法を調整して,さらに利益空間を拡大します.例えば,ストップ・プロフィートの線を比例して移動します.

  3. ストップ・ロスの範囲を拡大したり 収縮ストップを考慮したりすることで ノックアウトされる確率がさらに低下します

  4. 異なる品種には異なるパラメータがあります.戦略の収益性をさらに向上させるためのトレーニングを通じて最適なパラメータの組み合わせを得ることができます.

概要

一般的に,Myo_LS_D戦略は,比較的成熟し安定した二重トラック追跡ストップ利益量的な戦略である.明らかな利点と制御可能なリスクがある.長期にわたって保持する価値のある量的なソリューションの1つです.将来の最適化は,より優れた量的な戦略になるために継続的なパフォーマンス改善を可能にします.


/*backtest
start: 2023-12-15 00:00:00
end: 2024-01-14 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © agresiynin

//@version=5
// ©Myo_Pionex
strategy(
 title                  =   "Myo_simple strategy_LS_D",
 shorttitle             =   "Myo_LS_D",
 overlay                =   true )


// var
lowest_price = ta.lowest(low, 200)
highest_price = ta.highest(high, 200)
min_800 = ta.lowest(low, 800)
max_800 = ta.highest(high, 800)
tp_target_L = min_800 + (max_800 - min_800) * math.rphi
tp_target_S = max_800 - (max_800 - min_800) * math.rphi
sl_length_L = input.int(100, "做多的止損長度", minval = 50, maxval = 300, step = 50)
sl_length_S = input.int(100, "做空的止損長度", minval = 50, maxval = 300, step = 50)
sl_L = lowest_price * (1 - 0.005)
sl_S = highest_price * (1 + 0.005)
rrr_L = tp_target_L - sl_L / sl_L
rrr_S = ta.lowest(low, 800) + ta.highest(high, 800) - ta.lowest(low, 800) * math.rphi / ta.highest(high, 200) + 0.005 * ta.highest(high, 200) - ta.lowest(low, 200) - 0.005 * ta.lowest(low, 200)
smalen1 = input.int(10, "做多追蹤止盈SMA長度1", options = [5, 10, 20, 40, 60, 80])
smalen2 = input.int(20, "做多追蹤止盈SMA長度2", options = [5, 10, 20, 40, 60, 80])
smalen1_S = input.int(5, "做空追蹤止盈SMA長度1", options = [5, 10, 20, 40, 60, 80])
smalen2_S = input.int(10, "做空追蹤止盈SMA長度2", options = [5, 10, 20, 40, 60, 80])
TrendLength_L = input.int(400, "做多趨勢線", options = [100, 200, 300, 400, 500])
TrendLength_S = input.int(300, "做空趨勢線", options = [100, 200, 300, 400, 500])
SMA1 = ta.sma(close, smalen1)
SMA2 = ta.sma(close, smalen2)
SMA1_S = ta.sma(close, smalen1_S)
SMA2_S = ta.sma(close, smalen2_S)
shortlength = input.int(20, "短期均價K線數量")
midlength = input.int(60, "中期均價K線數量")
longlength = input.int(120, "長期均價K線數量")
ShortAvg = math.sum(close, shortlength)/shortlength
MidAvg = math.sum(close, midlength)/midlength
LongAvg = math.sum(close, longlength)/longlength

// Trend
basePeriods = input.int(8, minval=1, title="趨勢基準線")
basePeriods_Short = input.int(26, "做空基準線")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
baseLine = donchian(basePeriods)
baseLine_Short = donchian(basePeriods_Short)
trend = request.security(syminfo.tickerid, "D", baseLine)
isUptrend = false
isDowntrend = false
baseLine_D = request.security(syminfo.tickerid, "D", baseLine)
plot(baseLine_D, color=#B71C1C, title="趨勢基準線")
if close[0] > baseLine_D
    isUptrend := true
if close[0] < baseLine_Short
    isDowntrend := true
// Long
// Condition
// entry
con_a = low > lowest_price ? 1 : 0
con_b = high > highest_price ? 1 : 0
con_c = close[0] > ta.sma(close, TrendLength_L) ? 1 : 0
con_d = isUptrend ? 1 : 0
con_e = rrr_L > 3 ? 1 : 0
con_a1 = close[0] > ShortAvg[shortlength] ? 1 : 0
con_b1 = close[0] > MidAvg[midlength] ? 1 : 0

// close
con_f = ta.crossunder(close, SMA1) and ta.crossunder(close, SMA2) ? 1 : 0
con_g = close < ta.lowest(low, sl_length_L)[1] * (1 - 0.005) ? 1 : 0

// exit
con_h = tp_target_L

// Main calculation
LongOpen = false
AddPosition_L = false

if con_a + con_b + con_c + con_e + con_a1 + con_b1 >= 4 and con_d >= 1
    LongOpen := true
// Short
// Condition
// entry
con_1 = high < highest_price ? 1 : 0
con_2 = low < lowest_price ? 1 : 0
con_3 = close[0] < ta.sma(close, TrendLength_S) ? 1 : 0
con_4 = isDowntrend ? 1 : 0
con_5 = rrr_S > 3 ? 1 : 0
con_11 = close[0] < ShortAvg[shortlength] ? 1 : 0
con_12 = close[0] < MidAvg[midlength] ? 1 : 0

// close
con_6 = ta.crossover(close, SMA1_S) and ta.crossover(close, SMA2_S) ? 1 : 0
con_7 = close > ta.highest(high, sl_length_S)[1] * (1 + 0.005) ? 1 : 0

// exit
con_8 = tp_target_S

// Main calculation
ShortOpen = false
AddPosition_S = false

if con_1 + con_2 + con_3 + con_4 + con_5 + con_11 + con_12 >= 5
    ShortOpen := true

//
// execute
//
strategy.initial_capital = 50000
if strategy.position_size == 0
    if LongOpen
        strategy.entry("Long Open" , strategy.long , comment= "Long Open " + str.tostring(close[0]), qty=strategy.initial_capital/close[0])

if strategy.position_size > 0
    if (con_f > 0 or con_g > 0 or ShortOpen) and close <= baseLine_D
        strategy.close_all(comment="Close Long " + str.tostring(close[0]))

if strategy.position_size == 0
    if ShortOpen
        strategy.entry("Short Open" , strategy.short , comment= "Short Open " + str.tostring(close[0]), qty=strategy.initial_capital/close[0])

if strategy.position_size < 0
    if (con_6 > 0 or con_7 > 0 or LongOpen) and close >= baseLine_D
        strategy.close_all(comment="Close Short " + str.tostring(close[0]))


plot(ta.sma(close, TrendLength_L), color=#e5c212, title="LTradeTrend")
plot(ta.sma(close, TrendLength_S), color=#1275e5, title="STradeTrend")
plot(SMA1, "SMA1", color = color.lime, linewidth = 2)
plot(SMA2, "SMA2", color = color.rgb(255, 0, 255), linewidth = 2)

もっと