월스트리트 CCI 인덱스에 기초한 상관관계에 기반한 상승/하락 암호화 거래 전략

저자:차오장, 날짜: 2023-11-01 11:27:20
태그:

img

전반적인 설명

이것은 자동화 된 거래 전략으로, 월 스트리트 체이징 링 인덱스를 사용하여 그에 상관관계가 있다고 간주되는 벤치마크 암호화 통화의 계산 트렌드를 기반으로 목표 암호화 통화에 대한 긴 / 짧은 / 가까운 신호를 생성합니다.

기본 매개 변수와 ETH/USDT를 기본 기호로 사용하면 전략은 DENT/USDT, BTT/USDT, FTT/USDT, DOT/USDT 등과 같은 기호에 대한 좋은 백테스트 결과를 보여줍니다.

참고: 기본 매개 변수를 가진 전략은 4h 시간 프레임을 위해 의도됩니다. 다른 시간 프레임에서 다른 지원 길이를 시도하십시오.

전략 이 어떻게 작동 하는가

  1. WMA는 기본 기호에 의해 계산되며, 기본적으로 길이 200입니다.

  2. WMA가 상승할 때 길게, 떨어질 때 짧게

  3. 장기/단계 및 장기/단계 StopLoss의 TakeProfit는 계산된 비율이므로 0.05 = 5% 등입니다. 또한, TakeProfit/StopLoss는 차트의 기호가 아닌 기본 기호에 의해 계산됩니다.

  4. 이 전략은 다음과 같은 논리에 근거하여 시장 입출장 명령을 사용합니다.

    • WMA가 상승하고 지위가 없는 경우, 긴 입출구

    • WMA가 떨어지고 위치가 없을 때, 짧은 진입

    • 긴 포지션 수익 >= TakeProfitLong %, 긴 폐쇄

    • 코트 포지션 수익이 >=TakeProfitShort 비율이면, 코트를 닫습니다.

    • 긴 포지션 손실 >=StopLossLong %, 긴 폐쇄

    • 코트 포지션 손실 >=StopLossShort 비율, 코트 포지션 폐쇄

  5. 토프로피트 및 스톱 로스 가격은 기본 기호 가격 변화에 따라 실시간으로 업데이트됩니다.

이점 분석

  1. 이 전략은 매개 변수를 조정하여 여러 암호화폐에서 사용할 수 있습니다.

  2. 트렌드를 결정하기 위해 월스트리트 CCI를 사용하는 것은 소음으로 인한 잘못된 거래를 피합니다. CCI는 가짜 브레이크 손실을 피하는 데 도움이되는 브레이크에서 지연합니다.

  3. 테이크프로피트 (TakeProfit) 와 스톱로스를 통합하면 트렌드를 따라가는 동시에 거래당 손실을 제어할 수 있습니다.

  4. 수동 개입 없이 완전히 자동화 된 거래는 24/7 실행 시간을 허용합니다.

위험 분석

  1. 표적 암호화폐가 기본 암호화폐와 분리되어 전략의 실패로 이어질 위험이 있습니다. 여러 기본 암호화폐를 사용하여 최적화하고 가장 높은 상관 관계를 선택할 수 있습니다.

  2. 갑작스러운 변동성 위험은 포지션을 중지합니다. StopLoss 비율을 조정하거나 후속 스톱을 사용할 수 있습니다.

  3. 위험 TakeProfit 비율은 충분한 트렌드 이윤을 포착하기에는 너무 작습니다. 트렌드 추적 또는 동적 인 이윤을 포함 할 수 있습니다.

  4. 가짜 브레이크오웃의 위험은 손실 종료로 이어집니다. CCI 매개 변수를 조정하거나 재입구 논리를 추가할 수 있습니다.

최적화 방향

  1. 여러 기본 암호에 대한 상관 분석을 사용하고 단일 기본 암호 위험을 줄이기 위해 지표를 결합하십시오.

  2. 트렌드 추적을 추가하여 변동성에 따라 TakeProfit/StopLoss를 동적으로 조정합니다.

  3. 극한의 움직임이 위치에서 멈추는 것을 방지하기 위해 단계적 정지를 추가하십시오.

  4. 재입구 논리를 추가하여 스톱 로스 출구 후 추가 트렌드를 놓치지 않도록 합니다.

  5. CCI 매개 변수 및 설정을 최적화하여 신호 효과를 향상시킵니다.

  6. 적응력을 높이기 위해 각각의 표적 암호화에 대해 매개 변수를 개별적으로 최적화합니다.

  7. 계좌 크기에 따라 포지션 크기를 최적화합니다.

요약

전체적으로 이것은 트렌드를 따르는 전형적인 전략이다. 핵심 아이디어는 월스트리트 CCI를 사용하여 벤치마크 암호화폐의 트렌드 방향을 결정하고 그에 따라 표적 암호화폐를 거래하는 것이다. 이 전략은 몇 가지 장점이 있지만 주목해야 할 위험도 있다. 튜닝, 트렌드 추적, 리스크 제어 등에 대한 추가 개선은 안정성과 수익성을 향상시킬 수 있다. 요약하자면, 전략은 자동화된 체계적인 암호화폐 거래에 대한 아이디어와 참조를 제공한다.


/*backtest
start: 2022-10-25 00:00:00
end: 2023-10-31 00:00:00
period: 1d
basePeriod: 1h
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/
// © levieux

//@version=5
strategy(title='Correlation Strategy', shorttitle='Correlation Strategy', initial_capital=1000, overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)

supportLength = input.int(200, minval=1, title='Support Length')
supportSymbol = input('BTC_USDT:swap', title='Correlated Symbol')
supportSource = input(hlc3, title='Price Source')
takeprofitLong = input.float(0.2, 'Take Profit Long', step=0.01)
takeprofitShort = input.float(0.15, 'Take Profit Short', step=0.01)
stoplossLong = input.float(0.1, 'Stop Loss Long', step=0.01)
stoplossShort = input.float(0.04, 'Stop Loss Short', step=0.01)
start = input(defval = timestamp("01 Jan 2016 00:00 +0000"), title = "Start Time")
end = input(defval = timestamp("31 Dec 2050 23:59 +0000"), title = "End Time")

supportTicker = request.security(supportSymbol, timeframe.period, supportSource, lookahead=barmerge.lookahead_off)  //input(close, title="Source")
supportLine = ta.wma(supportTicker, supportLength)

window() => true

if not window()
    strategy.cancel_all()

supportLongPrice = close
supportShortPrice = close

if strategy.position_size > 0
    supportLongPrice := supportLongPrice[1]
if strategy.position_size < 0
    supportShortPrice := supportShortPrice[1]

longCondition = ta.rising(supportLine, 5) and window() and strategy.position_size <= 0
shortCondition = ta.falling(supportLine, 5) and window() and window() and strategy.position_size > 0
takeprofitLongCondition = takeprofitLong > 0 and window() and strategy.position_size > 0 and supportTicker > supportLongPrice * (1 + takeprofitLong)
stoplossLongCondition = stoplossLong > 0 and window() and strategy.position_size > 0 and supportTicker < supportLongPrice * (1 - stoplossLong)
takeprofitShortCondition = takeprofitShort > 0 and window() and strategy.position_size < 0 and supportTicker > supportShortPrice * (1 + takeprofitShort)
stoplossShortCondition = stoplossShort > 0 and window() and strategy.position_size < 0 and supportTicker < supportShortPrice * (1 - stoplossShort)

if longCondition
    strategy.entry('Long', strategy.long)
    supportLongPrice := supportTicker

if shortCondition
    strategy.entry('Short', strategy.short)
    supportShortPrice := supportTicker

if takeprofitLongCondition
    strategy.close('Long')
if stoplossLongCondition
    strategy.close('Long')
if takeprofitShortCondition
    strategy.close('Short')
if stoplossShortCondition
    strategy.close('Short')

///////////////////
// MONTHLY TABLE //

new_month = month(time) != month(time[1])
new_year  = year(time)  != year(time[1])

eq = strategy.equity

bar_pnl = eq / eq[1] - 1
bar_bh = (close-close[1])/close[1]

cur_month_pnl = 0.0
cur_year_pnl  = 0.0
cur_month_bh = 0.0
cur_year_bh  = 0.0

// Current Monthly P&L
cur_month_pnl := new_month ? 0.0 : 
                 (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1 
cur_month_bh := new_month ? 0.0 : 
                 (1 + cur_month_bh[1]) * (1 + bar_bh) - 1

// Current Yearly P&L
cur_year_pnl := new_year ? 0.0 : 
                 (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1
cur_year_bh := new_year ? 0.0 : 
                 (1 + cur_year_bh[1]) * (1 + bar_bh) - 1

// Arrays to store Yearly and Monthly P&Ls
var month_pnl  = array.new_float(0)
var month_time = array.new_int(0)
var month_bh  = array.new_float(0)

var year_pnl  = array.new_float(0)
var year_time = array.new_int(0)
var year_bh  = array.new_float(0)

end_time = false

end_time:= time_close + (time_close - time_close[1]) > timenow or barstate.islastconfirmedhistory

if (not na(cur_month_pnl[1]) and (new_month or end_time))
    if (end_time[1])
        array.pop(month_pnl)
        array.pop(month_time)
        
    array.push(month_pnl , cur_month_pnl[1])
    array.push(month_time, time[1])
    array.push(month_bh , cur_month_bh[1])

if (not na(cur_year_pnl[1]) and (new_year or end_time))
    if (end_time[1])
        array.pop(year_pnl)
        array.pop(year_time)
        
    array.push(year_pnl , cur_year_pnl[1])
    array.push(year_time, time[1])
    array.push(year_bh , cur_year_bh[1])

// Monthly P&L Table    
var monthly_table = table(na)

getCellColor(pnl, bh)  => 
    if pnl > 0
        if bh < 0 or pnl > 2 * bh
            color.new(color.green, transp = 20)
        else if pnl > bh
            color.new(color.green, transp = 50)
        else
            color.new(color.green, transp = 80)
    else
        if bh > 0 or pnl < 2 * bh
            color.new(color.red, transp = 20)
        else if pnl < bh
            color.new(color.red, transp = 50)
        else
            color.new(color.red, transp = 80)

if end_time
    monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, border_width = 1)

    table.cell(monthly_table, 0,  0, "",     bgcolor = #cccccc)
    table.cell(monthly_table, 1,  0, "Jan",  bgcolor = #cccccc)
    table.cell(monthly_table, 2,  0, "Feb",  bgcolor = #cccccc)
    table.cell(monthly_table, 3,  0, "Mar",  bgcolor = #cccccc)
    table.cell(monthly_table, 4,  0, "Apr",  bgcolor = #cccccc)
    table.cell(monthly_table, 5,  0, "May",  bgcolor = #cccccc)
    table.cell(monthly_table, 6,  0, "Jun",  bgcolor = #cccccc)
    table.cell(monthly_table, 7,  0, "Jul",  bgcolor = #cccccc)
    table.cell(monthly_table, 8,  0, "Aug",  bgcolor = #cccccc)
    table.cell(monthly_table, 9,  0, "Sep",  bgcolor = #cccccc)
    table.cell(monthly_table, 10, 0, "Oct",  bgcolor = #cccccc)
    table.cell(monthly_table, 11, 0, "Nov",  bgcolor = #cccccc)
    table.cell(monthly_table, 12, 0, "Dec",  bgcolor = #cccccc)
    table.cell(monthly_table, 13, 0, "Year", bgcolor = #999999)


    for yi = 0 to array.size(year_pnl) - 1
        table.cell(monthly_table, 0,  yi + 1, str.tostring(year(array.get(year_time, yi))), bgcolor = #cccccc)
        
        y_color = getCellColor(array.get(year_pnl, yi), array.get(year_bh, yi))
        table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100)) + " (" + str.tostring(math.round(array.get(year_bh, yi) * 100)) + ")", bgcolor = y_color)
        
    for mi = 0 to array.size(month_time) - 1
        m_row   = year(array.get(month_time, mi))  - year(array.get(year_time, 0)) + 1
        m_col   = month(array.get(month_time, mi)) 
        m_color = getCellColor(array.get(month_pnl, mi), array.get(month_bh, mi))
        
        table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100)) + " (" + str.tostring(math.round(array.get(month_bh, mi) * 100)) +")", bgcolor = m_color)

더 많은