전략에 따른 격차 매트릭스 트렌드

저자:차오장, 날짜: 2023-12-12 17:05:27
태그:

img

전반적인 설명

디버전스 매트릭스 트렌드 추적 전략 (Divergence Matrix Trend Following Strategy) 은 트렌드, 디버전스 및 이동 평균 분석을 결합한 양적 거래 전략이다. 이 전략은 시장 트렌드 방향을 판단하기 위해 이중 RSI 지표와 엔트리 신호를 생성하기 위해 매트릭스 이동 평균을 사용합니다. 매트릭스 이동 평균은 가격의 차원의 차이에 따라 포지션 사이즈를 조정합니다. 전반적으로이 전략의 장점은 여러 지표로 거래 신호를 확인하는 것입니다. 이는 잘못된 파장을 효과적으로 피할 수 있습니다. 한편, 매트릭스 메커니즘은 더 높은 수익을 잠금 할 수 있습니다.

전략 논리

디버전스 매트릭스 트렌드 다음 전략은 다음과 같은 주요 부분으로 구성됩니다.

  1. 트렌드 판단을 위한 이중 RSI

    빠른 RSI와 느린 RSI를 사용하여 시장 트렌드 방향을 결정하십시오. 빠른 RSI가 과소매 또는 과소매 수준을 표시하면 느린 RSI를 트렌드 방향을 확인하십시오.

  2. 거래 신호에 대한 매트릭스 이동 평균

    입력 가격에 기초한 행렬 이동 평균의 그룹을 설정합니다. 가격이 이동 평균 라인을 만지면 그에 따라 위치를 조정합니다. 이것은 트렌드에 더 많은 이익을 얻을 수 있습니다.

  3. 양방향 거래

    기본적으로는 양방향 거래입니다.

구체적인 거래 논리는 다음과 같습니다.

  1. 빠른 RSI를 사용하여 시장에서 일시적인 과반 구매/ 과반 판매 수준을 감지합니다.

  2. 느린 RSI를 사용하여 시장의 중장기 트렌드 방향을 결정합니다.

  3. 빠른 RSI가 극한을 나타내고 느린 RSI가 트렌드 반전을 신호하면 느린 RSI로 긴 / 짧은 트렌드를 기반으로 포지션을 취합니다.

  4. 포지션을 입력 한 후 행렬 이동 평균의 그룹을 설정합니다. 이 행렬 선은 입력 가격 주위를 기반으로하며, Matrix Interval % 매개 변수에서 정의된 간격 크기로 구성됩니다.

  5. 가격이 매트릭스 라인에 닿을 때, 그에 따라 포지션 크기를 조정합니다. 예를 들어, 상향 브레이크오프에서 로그를 늘리고, 하향 브레이크오프에서 쇼트를 줄입니다.

  6. 가격이 큰 변화를 볼 때, 포지션은 초기 수준으로 다시 설정됩니다.

위의 설명은 이 전략의 주요 거래 논리를 설명합니다. 매트릭스 메커니즘은 더 많은 트렌드 이윤을 잠금 할 수 있습니다.

장점

디버전스 매트릭스 트렌드 추적 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 이중 RSI 신호는 더 신뢰할 수 있습니다. 빠른 RSI는 잘못된 브레이크오프를 피하고 느린 RSI는 주요 트렌드가 올바르다는 것을 보장합니다.

  2. 매트릭스 이동 평균은 트렌드로부터 이익을 얻습니다. 가격 차이에 따라 포지션 크기를 조정하면 지속적인 이익을 얻을 수 있습니다.

  3. 양방향 거래를 지원합니다. 기본은 양방향 거래이지만 또한 길게 갈 수 있습니다. 이것은 더 많은 시장 환경에 적응합니다.

  4. 포지션 재설정 메커니즘은 위험을 제어합니다. 가격이 큰 조정을 볼 때 포지션을 재설정하면 적시에 손실을 막을 수 있습니다.

  5. 유연한 매개 변수 설정. 사용자는 역사적 데이터, 거래 도구 등을 기반으로 최적의 매개 변수 조합을 선택할 수 있습니다.

  6. 깨끗한 코드 구조. 책임의 명확한 분리가 코드를 이해하기 쉽고 최적화하고 확장 할 수 있습니다.

요약하자면 이 전략의 가장 큰 장점은 여러 메커니즘을 통해 신호 품질을 향상시키는 동시에 통제된 위험 하에서 더 높은 수익을 추구하는 것입니다. 이것은 위험과 보상을 균형 잡는 전략입니다.

위험성

이차성 행렬 추세 추후 전략은 다음과 같은 영역에서 주로 몇 가지 위험을 가지고 있습니다.

  1. 듀얼 RSI 신호의 실패 위험. 시장이 범위에 묶여있을 때, RSI는 종종 잘못된 신호를 제공합니다. 매개 변수를 조정하거나 거래를 중단하기 위해 수동 개입이 필요합니다.

  2. 부적절한 매트릭스 이동 평균 위험. 매트릭스 매개 변수가 올바르게 설정되지 않으면 위치 조정이 너무 공격적이 될 수 있으며 이로 인해 손실이 커질 수 있습니다. 보수적인 매개 변수 테스트는 필수적입니다.

  3. 과잉 레버레이드 된 지점의 위험. 과도한 지점 크기 조정 또한 손실을 증가시킬 것입니다. 최대 지점 크기 매개 변수를 신중하게 설정해야합니다.

  4. 트렌드 역전 위험. 트렌드 역전 시 즉시 포지션을 닫지 않으면 큰 손실이 발생할 수 있습니다. 이것은 장기 트렌드 지표를 모니터링해야합니다.

  5. 제한된 최적화 공간 위험. 이 전략은 이미 상당히 성숙하다. 지속적인 최적화 잠재력은 제한되어 있다. 시장 체제가 급격히 변화할 경우 주요 업그레이드가 필요할 수 있다.

전략의 평가와 최적화는 이러한 위험을 완화하는 데 핵심입니다. 매개 변수를 조정하고 장기 지표 등을 모니터링하면 어느 정도 위험을 완화 할 수 있습니다.

더 나은 기회

이차성 매트릭스 트렌드는 다음 전략에 따라 더욱 강화될 수 있습니다.

  1. 이중 RSI 매개 변수를 최적화 합니다. 더 많은 매개 변수 조합을 테스트하고 가장 높은 정확도로 RSI 기간을 선택 합니다.

  2. 사용자 정의 가능한 행렬 라인. 사용자가 다른 기기에 기반하여 행렬 설정을 매개 변수화하여 그들의 특성에 더 적합하도록 허용합니다.

  3. 스톱 로스 메커니즘을 추가합니다. 예를 들어, 가격이 그 라인을 깨는 경우 포지션을 중지하기 위해 출구 라인을 설정하십시오.

  4. 더 많은 과학적 위치 사이즈 규칙을 추가합니다. 과도한 레버링을 방지하기 위해 더 점진적인 방식으로 위치 사이즈 조정을 관리하십시오.

  5. 다른 지표를 포함합니다. 신호의 정확성을 향상시키기 위해 MACD, KD 등과 같은 추가 지표를 도입합니다.

  6. 코드 구조를 최적화합니다. 코드의 확장성, 유지보수성 및 실행 효율성을 더욱 향상시킵니다.

결론

디버전스 매트릭스 트렌드 추적 전략 (Divergence Matrix Trend Following Strategy) 은 여러 메커니즘을 결합한 정교한 양적 거래 전략이다. 트렌드 방향과 매트릭스 라인을 트렌드로부터 이익을 얻기 위해 이중 RSI를 사용합니다. 단일 지표 전략과 비교하면 더 안정적이고 효율적인 거래 신호를 제공합니다. 매개 변수 조정 및 최적화 확장으로이 전략은 더 많은 시장 조건과 체제에 적응할 수 있으며 매우 다재다능합니다. 전반적으로이 전략은 위험과 수익 사이의 좋은 균형을 이루며 투자자들의 적극적인 응용과 지속적인 향상과 자격이 있습니다.


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

//@version=3
strategy("The Matrix 7.0 Strategy", overlay=false)

//Matrix Settings 
entry_size = input(title="Entry Size", defval = 1)
max_size = input(title="Max Size", defval = 10000)
matrix = input(title="Matrix Interval %", defval = 2)
matrix_price_overwrite = input(title="Matrix Overwrite $", defval = 0.0)
adjustment = input(title="Adjustment Size", defval = 1000)
trade_short = input(title="Trade Short", type=bool, defval = true)

//RSI Settings
periods = input(title="RSI Periods", defval = 14)
overbought_short = input(title="RSI Overbought", defval = 65)
oversold_short = input(title="RSI Oversold", defval = 30)

//RSI Trend Settings
resolution_long = input(title="Resolution Trend", defval = "D")
periods_long = input(title="RSI Trend Periods", defval = 14)
overbought_long = input(title="RSI Trend Overbought", defval = 64)
oversold_long = input(title="RSI Trend Oversold", defval = 30)

//Round Off to 2 decimals
round2(x) =>
    a = x * 10 * 10
    a := floor(a + 0.5)
    a := a / 10 / 10
    a

//RSI Function
RSI = rsi(close, periods)

//RSI Market Function
rsi_oversold = RSI < oversold_short
rsi_overbought = RSI > overbought_short

market_rsi = 0.0
market_rsi := if (rsi_oversold)
    RSI - oversold_short
else
    if (rsi_overbought)
        RSI - overbought_short
    else
        0

//RSI Trend Function
rsi_long = request.security(syminfo.tickerid,resolution_long,rsi(close,periods_long))
trend_rsi_long = rsi_long < oversold_long
trend_rsi_short = rsi_long > overbought_long
trend_rsi = 0
trend_rsi := if (trend_rsi_short)
    -1
else
    if (trend_rsi_long)
        1
    else
        trend_rsi[1] 

// // Shorter time resolution to make "close" crosses give faster positives.
// short_resolution = security(tickerid, "1", close)
// quick = round2(short_resolution) //ROUND OFF TO 2 DECIMAL PLACES.

//Declare Other Variables
entry_price = 0.0
entry_price := nz(entry_price[1])

position_size = 0.0
position_size := nz(position_size[1])

last_traded_price = 0.0
last_traded_price := nz(last_traded_price[1])


matrix_price = 0.0
if matrix_price_overwrite > 0.0
    matrix_price := matrix_price_overwrite
else
    matrix_price := round2((matrix/100) * entry_price)

level = 0
level := nz(level[1])

level_price = entry_price
if not na(level_price[1])
    level_price := level_price[1]

// Calculate Level
if close > level_price 
    level_change = floor((high - level_price)/matrix_price)
    level := level + level_change
else
    if close < level_price 
        level_change = ceil((low - level_price)/matrix_price)
        level := level + level_change
        
// Calculate Level Price   
level_price := (level * matrix_price) + entry_price

// Calculate Matrix Position
matrix_position = 0.0

if position_size > 0
    matrix_position :=  ((-1 * level) * adjustment) + entry_size
else
    if position_size < 0
        matrix_position :=  ((-1 * level) * adjustment) - entry_size
    
//Trend Entry or Reversal Conditions
trend_reversal_up = trend_rsi == 1 and (trend_rsi[1] == -1 or trend_rsi == 0) and position_size <= 0
trend_reversal_down = trend_rsi == -1 and (trend_rsi[1] == 1 or trend_rsi == 0) and position_size >= 0 and trade_short == true
flatten_position = trend_rsi == -1 and (trend_rsi[1] == 1 or trend_rsi == 0) and position_size >= 0 and trade_short == false

//Reset Conditions
reset_long = (position_size > 0) and (close - entry_price > matrix_price) and (market_rsi < 0) and (position_size != entry_size) 
reset_short = (position_size < 0) and (entry_price - close > matrix_price) and (market_rsi > 0) and (position_size != (-1 * entry_size)) 

//Adjustment Conditions
increase_long = (position_size > 0) and (matrix_position > position_size) and (market_rsi < 0) and (matrix_position <= max_size) 
decrease_long = (position_size > 0) and (matrix_position < position_size) and (market_rsi > 0) 
increase_short = (position_size < 0) and (matrix_position < position_size) and (market_rsi > 0) and (matrix_position >= (-1 * max_size)) 
decrease_short = (position_size < 0) and (matrix_position > position_size) and (market_rsi < 0)  

//Transactions
//Trend Reversals
if trend_reversal_up
    strategy.entry("OL", strategy.long, qty=entry_size)
    position_size := entry_size
    matrix_position := entry_size
    level := 0
else
    if trend_reversal_down 
        strategy.entry("OS", strategy.short, qty=entry_size)
        position_size := -1 * entry_size
        matrix_position := -1 * entry_size   
        level := 0
        
    //Reset Positions    
    else
        if reset_long
            order = entry_size - position_size[1]
            strategy.order("RL", strategy.long, qty=order)
            position_size := entry_size
            matrix_position := entry_size
            level := 0
        else
            if reset_short
                order = position_size[1] - (-1* entry_size)
                strategy.order("RS", strategy.short, qty=order)
                position_size := -1 * entry_size
                matrix_position := -1 * entry_size
                level := 0

    //Position Adjustments
            else    
                if increase_long
                    order = matrix_position - position_size[1]
                    strategy.order("IL", strategy.long, qty=order)
                    position_size := position_size[1] + order
                else
                    if decrease_long
                        order = position_size[1] - matrix_position
                        strategy.order("DL", strategy.short, qty=order)
                        position_size := position_size[1] - order
                    else
                        if increase_short
                            order = position_size[1] - matrix_position
                            strategy.order("IS", strategy.short, qty=order)
                            position_size := position_size[1] - order
                        else
                            if decrease_short
                                order = matrix_position - position_size[1]
                                strategy.order("DS", strategy.long, qty=order)
                                position_size := position_size[1] + order
                            else 
                                if flatten_position
                                    strategy.close_all()
                                    position_size := 0.0
                                    matrix_position := 0.0
                                    level := 0

//Grouped Actions
if trend_reversal_up or trend_reversal_down or reset_short or reset_long
    entry_price := round2(close)
    last_traded_price := round2(close)

if increase_long or decrease_long or increase_short or decrease_short
    last_traded_price := round2(close)

// //RSI Trend & Adjustment Moments. (strategy)
p1 = plot(market_rsi, color = trend_rsi > 0 ? green : red, linewidth = 4, title='Market', transp =0)
p2 = plot(trend_rsi, color = trend_rsi > 0 ? green : red, linewidth = 4, title='Trend', transp = 0)
fill(p1,p2, color=trend_rsi > 0 ? green : red, transp=0)
p3 = plot((rsi_long - 50) *2, color = white, title="Trend Index")
fill(p2,p3, color=white)
hline((overbought_long -50) * 2)
hline((oversold_long -50) * 2)

//Position Plots (strategy)
plot(matrix_position / 100, title='Matrix', color=white, linewidth = 4)
plot(position_size / 100, title='Position', color=blue, linewidth = 4)
plot(strategy.position_size / 100, title='Strategy', color=orange, linewidth = 4)

// //Price Plots (study)
// plot(level_price, title="Matrix Level Price", linewidth=4)
// plot(last_traded_price, title="Last Traded Price", linewidth=2, color=orange)
// plot(entry_price + (4 * matrix_price), title='Adjustment 4', color=white, linewidth = 1)
// plot(entry_price + (3 * matrix_price), title='Adjustment 3', color=white, linewidth = 1)
// plot(entry_price + (2 * matrix_price), title='Adjustment 2', color=white, linewidth = 1)
// plot(entry_price + matrix_price, title='Adjustment 1', color=white, linewidth = 1)
// plot(entry_price, title='Entry Price', color=white, linewidth = 3)
// plot(entry_price - matrix_price, title='Adjustment -1', color=white, linewidth = 1)
// plot(entry_price - (2 * matrix_price), title='Adjustment -2', color=white, linewidth = 1)
// plot(entry_price - (3 * matrix_price), title='Adjustment -3', color=white, linewidth = 1)
// plot(entry_price - (4 * matrix_price), title='Adjustment -4', color=white, linewidth = 1)


// //Alerts (study only)
// alertcondition(trend_reversal_up, title='Trend Reversal Up', message='Market Oversold, Lets Buy')
// alertcondition(trend_reversal_down, title='Trend Reversal Down', message='Market Overbought, Lets Sell')
// alertcondition(reset_long, title='Reset Long', message='Higher Bottom, Lets Buy')
// alertcondition(reset_short, title='Reset Short', message='Lower Top, Lets Sell')
// alertcondition(increase_long, title='Increase Long', message='Price Dropped, Lets Buy')
// alertcondition(decrease_long, title='Decrease Long', message='Price Spiked, Lets Sell')
// alertcondition(increase_short, title='Increase Short', message='Price Spiked, Lets Sell')
// alertcondition(decrease_short, title='Decrease Short', message='Price Dropped, Lets Buy')

// //Grouped Conditions
// condition_buy = trend_reversal_up or increase_long or decrease_short or reset_long
// condition_sell = trend_reversal_down or decrease_long or increase_short or reset_short
// adjustment_matrix = trend_reversal_up or increase_long or decrease_short or trend_reversal_down or decrease_long or increase_short or reset_long or reset_short

// //Grouped Alerts
// alertcondition(condition_buy, title='Condition Buy', message='You Need to Buy')
// alertcondition(condition_sell, title='Condition Sell', message='You Need to Sell!')
// alertcondition(adjustment_matrix, title='Adjustment Matrix', message='You Need to Adjust')



더 많은