Myo_LS_D 양적 전략

저자:차오장, 날짜: 2024-01-15 14:56:03
태그:

img

전반적인 설명

Myo_LS_D 양적 전략은 긴 포지션과 짧은 포지션을 기반으로 한 이중 트랙 추적 스톱-프로프트 전략이다. 전략은 이동 평균, 가격 돌파구 및 위험 수익률 등 여러 지표를 결합하여 거래 신호를 구축합니다. 정확한 트렌드 판단의 전제에서 높은 승률과 수익률을 달성합니다.

원칙

이 전략은 주로 트렌드 판단 모듈, 장기 포지션 모듈, 단기 포지션 모듈, 스톱프로프트 추적 모듈 등으로 구성됩니다.

  1. 트렌드 판단 모듈은 전체 트렌드 방향을 결정하기 위해 Donchain 채널을 사용합니다. 장기간 거래의 전제 조건은 상승 추세이며 단기 거래는 하락 추세를 요구합니다.

  2. 긴 포지션 모듈은 새로운 최고, 최저, 긴 이동 평균 포지션 등과 같은 요인을 고려합니다. 짧은 포지션 모듈은 새로운 최고, 최저, 짧은 이동 평균 포지션 및 기타 요인을 고려합니다. 이것은 중요한 가격 지점을 위쪽으로 또는 아래로 넘을 때 포지션을 개설하는 것을 보장합니다.

  3. 추적 스톱 이윤 모듈은 다른 주기의 두 개의 SMA 이동 평균을 사용하여 실시간으로 가격 변화를 추적합니다. 가격이 이동 평균 라인을 넘으면 수익을 위해 포지션이 폐쇄됩니다. 이러한 실시간 추적은 트렌드에서 수익을 극대화 할 수 있습니다.

  4. 스톱 로스 설정은 스톱 로스를 확장하여 스톱 로스 포인트를 지지 수준에서 멀리 떨어져 유지하여 노크 아웃을 피하도록 고려합니다.

이점 분석

이 전략의 가장 큰 장점은 긴 포지션과 짧은 포지션을 분리하고 스톱 이윤 전략을 추적하는 것입니다. 구체적으로, 그것은 주로 다음과 같이 구현됩니다.

  1. 긴 포지션과 짧은 포지션을 분리하면 일방적인 트렌드 거래 기회를 포착함으로써 수익 기회를 극대화 할 수 있습니다.

  2. 스톱프로피트 추적은 실시간 조정으로 더 높은 이익 마진을 얻을 수 있습니다. 전통적인 스톱프로피트 방법과 비교하면 수익이 크게 향상 될 수 있습니다.

  3. 확장된 스톱은 노크아웃 될 확률을 줄이고 손실의 위험을 줄일 수 있습니다.

위험 과 해결책

이 전략의 주요 위험은 다음과 같은 부분으로 집중됩니다.

  1. 잘못된 트렌드 판단은 반대 위치 및 손실로 이어질 수 있습니다. 최적화는 Donchain 매개 변수를 적절히 조정하거나 판단을 위해 다른 지표를 추가하여 달성 할 수 있습니다.

  2. 스톱프로피트 추적은 너무 공격적이며, 수익을 유지할 수 없이 수익을 조기에 중단할 수 있다. 최적화는 스톱프로피트 이동 평균 사이의 간격을 적절히 증가시킴으로써 달성될 수 있다.

  3. 스톱 로스 범위는 너무 작아서 노카우트 될 확률을 높일 수 있습니다. 스톱 로스 규모를 적절히 확장하면 위험을 완화 할 수 있습니다.

최적화 방향

이 전략의 주요 최적화 방향은 다음과 같습니다.

  1. 추세 판단 모듈을 최적화하여 판단 정확도를 향상시킵니다. MACD와 같은 더 많은 지표를 결합하는 것을 고려하십시오.

  2. 스톱프로프트 트래킹 방법을 조정하여 수익 공간을 더욱 넓히기 위해, 예를 들어 스톱프로프트 라인을 비율로 이동시키는 것입니다.

  3. 스톱 손실 범위를 확장하거나 수축 스톱을 고려하면 노크 아웃 될 확률을 더욱 줄일 수 있습니다.

  4. 다른 품종은 다른 매개 변수를 가지고 있습니다. 전략 수익을 더 향상시키기 위해 훈련을 통해 최적의 매개 변수 조합을 얻을 수 있습니다.

요약

일반적으로 Myo_LS_D 전략은 비교적 성숙하고 안정적인 이중 트랙 추적 스톱-프로프트 양적 전략이다. 명백한 장점과 통제 가능한 위험이 있다. 장기적으로 보유할 가치가 있는 양적 솔루션 중 하나이다. 미래 최적화는 더욱 뛰어난 양적 전략으로 만들기 위해 지속적인 성능 향상을 가능하게 할 수 있다.


/*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)

더 많은