편차 매트릭스 추세 추종 전략


생성 날짜: 2023-12-12 17:05:27 마지막으로 수정됨: 2023-12-12 17:05:27
복사: 0 클릭수: 643
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

편차 매트릭스 추세 추종 전략

개요

격리 매트릭스 트렌드 추적 전략은 트렌드, 격리 및 평행선을 결합한 양적 거래 전략이다. 이 전략은 쌍 RSI 지표를 사용하여 시장의 경향 방향을 판단하고, 매트릭스 평행선과 결합하여 진입 신호를 설정한다. 매트릭스 평행선은 가격의 격리 정도에 따라 포지션 규모를 조정한다. 전체적으로, 이 전략의 장점은 거래 신호를 확인하는 여러 지표를 사용하여 가짜 돌파구를 효과적으로 피할 수 있으며, 동시에 매트릭스 평행선 메커니즘은 더 높은 수익을 잠금 할 수 있다.

전략 원칙

이분열 매트릭스 트렌드 추적 전략은 주로 다음과 같은 부분들로 구성됩니다.

  1. 이중 RSI 판단 트렌드

빠른 RSI와 느린 RSI를 사용하여 시장의 경향 방향을 판단하십시오. 빠른 RSI가 과매매되거나 과매매되면 느린 RSI와 결합하여 경향 방향을 판단하십시오.

  1. 매트릭스 평행선은 거래 신호를 생성합니다.

입시 가격에 따라 매트릭스 평균선을 설정하고, 가격이 특정 평균선에 닿으면 그에 따라 포지션을 조정한다. 이렇게하면 추세에서 더 많은 이익을 얻을 수 있다.

  1. 양방향 거래

기본으로 양방향 거래. 선택은 그냥 더 많이 하고 빈게 하지 말고.

거래 논리는 다음과 같습니다.

  1. 빠른 RSI를 사용하여 시장의 일시적인 과매매를 판단하십시오.

  2. 느린 RSI를 사용하여 시장의 중·장기 경향 방향을 판단하십시오.

  3. 급속한 RSI가 과매매되고, 느린 RSI가 트렌드 전환을 표시할 때, 느린 RSI의 여백 판단에 따라 해당 방향의 포지션을 수행하십시오.

  4. 창고를 세운 후, 매트릭스 평균선이 설정된다. 이 매트릭스 평균선은 입시 가격 설정을 둘러싸고, 간격 크기는 매트릭스 영역 사이의 비율 파라미트가 설정된다.

  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. 코드 구조를 최적화한다. 확장성, 유지보수성 및 실행 효율성을 계속 향상시킨다.

요약하다

격리 매트릭스 트렌드 추적 전략은 여러 메커니즘을 포함하는 정량 거래 전략이다. 이 전략은 주로 트렌드 방향을 판단하는 이중 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')