CCI 평균 역전 채널 전략

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

img

전반적인 설명

이 전략은 CCI 지표에 기반한 유연한 트렌드 트레이딩 시스템으로 설계되었습니다. CCI 제로 라인 크로스오버 또는 사용자 정의 상부/하부 밴드 크로스오버에 기반한 거래 신호를 생성 할 수 있습니다. 이 전략은 고정 스톱 로스 및 영업 비율을 설정하고 특정 시간 프레임에서 거래하는 것을 허용합니다.

전략 논리

  1. CCI 제로 라인 크로스오버를 사용하여 시장 트렌드를 결정합니다. CCI 제로 이상의 크로스오버는 상승 신호이고 아래의 크로스오버는 하락 신호입니다.

  2. 사용자 지정 CCI 상위 및 하위 대역을 설정하십시오. 상위 대역 위의 CCI 교차는 상승하고 하위 대역 아래의 교차는 하락합니다. 대역 크로스오버는 정지 역할을합니다.

  3. 특정 시간 프레임에서만 거래하고 그 기간 이외의 모든 포지션을 닫을 수 있습니다. 또한 고정 된 일일 시간 프레임에서 거래 할 수 있습니다.

  4. 고정된 스톱 로스를 설정하고 수익률을 취합니다.

  5. 입구와 출구 신호를 위한 사용자 정의 가능한 경보 메시지

  6. 조정 가능한 CCI 매개 변수, 대역, 정지 등으로 매우 사용자 정의 가능한 전략

이점 분석

  1. CCI는 가격 변화에 민감하고, 트렌드 반전을 감지하는데 좋다.

  2. 사용자 정의 대역은 다른 시장에 맞게 조정 할 수 있습니다. 대역 크로스 스톱은 위험을 조절하는 데 도움이됩니다.

  3. 특성에 기반한 최적화된 매개 변수로 다른 시간 프레임에서 거래를 지원합니다.

  4. 일정한 스톱 로스/프로프트 취득, 미리 설정된 리스크/어워드 비율 및 리미트 리스크

  5. 완전히 사용자 정의 가능한 매개 변수는 다양한 제품과 시장 조건에 대한 전략을 최적화합니다.

위험 분석

  1. CCI는 잘못된 신호에 취약한 경우 더 긴 시간 프레임 표시를 가진 신호를 확인해야 합니다.

  2. 고정된 스톱/테이크 비율은 변화하는 시장 조건에 적응할 수 없습니다.

  3. 일정한 시간 프레임에서 거래하면 범위 기간 동안 기회를 놓칠 위험이 있습니다.

  4. 매개 변수를 자주 최적화하면 거래가 과잉되거나 빠질 수 있습니다.

  5. 거시적 요인을 고려해야 합니다. 최적화만으로는 위험을 제거할 수 없습니다.

최적화 방향

  1. CCI 신호를 확인하기 위해 더 긴 시간 프레임 지표를 추가합니다.

  2. ATR과 같은 동적 정지/취급을 포함합니다.

  3. 다른 시간 프레임에서 매개 변수를 테스트하고 높은 효율 기간을 찾습니다.

  4. 변화하는 시장에 대한 CCI 매개 변수와 대역 최적화

  5. 변동성과 부피와 같은 다른 요소를 포함하는 것을 고려하십시오.

  6. 거래 상품에 적합한 시간 프레임을 선택합니다.

  7. 전략 최적화를 자동화하기 위해 기계 학습을 고려해보세요.

요약

전체적으로 이것은 매우 유연하고 사용자 정의 가능한 트렌드 추적 시스템이다. 주요 장점은 트렌드에 대한 CCI, 위험을 제한하기 위한 사용자 정의 대역, 고정 스톱/테이크 및 시간 프레임 선택을 사용하는 것이다. 잘못된 CCI 신호와 유연하지 않은 스톱을 감시해야 한다. 미래 개선은 매개 변수 최적화, 신호 필터링, 효율적인 시간 프레임을 선택, 더 일관된 초과 수익을 달성하기 위해 시장 변화에 자동 적응을 위해 기계 학습을 통합하는 것에서 올 수 있다.


/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 00:00:00
period: 1h
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/
// © REV0LUTI0N

//@version=4

strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)


//CCI Code

length = input(20, minval=1, title="CCI Length")
src = input(close, title="Source")
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))


// Strategy Backtesting
startDate  = input(timestamp("2099-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true


//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = true
timetoclose = true


//Strategy Settings

//Strategy Settings - Enable Check Boxes
enableentry = input(true, title="Enter First Trade ASAP")
enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")
enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")
enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")

//Strategy Settings - Band Sources
ccisource = input(0, title="CCI Simple Cross")
upperbandsource =input(100, title="CCI Enter Long Band")
upperbandexitsource =input(100, title="CCI Exit Long Band")
lowerbandsource =input(-100, title="CCI Enter Short Band")
lowerbandexitsource =input(-100, title="CCI Exit Short Band")

//Strategy Settings - Crosses
simplecrossup = crossover(cci, ccisource)
simplecrossdown = crossunder(cci, ccisource)
uppercrossup = crossover(cci, upperbandsource)
lowercrossdown = crossunder(cci, lowerbandsource)
uppercrossdown = crossunder(cci, upperbandexitsource)
lowercrossup = crossover(cci, lowerbandexitsource)
upperstop = crossunder(cci, upperbandsource)
lowerstop = crossover(cci, lowerbandsource)


// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")


// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
    

//Strategy Execution

//Strategy Execution - Simple Line Cross
if (cci > ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (cci < ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

if (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Entry
if (uppercrossup and enablebands and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (lowercrossdown and enablebands and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Exit
if strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Upper and Lower Band Stops
if strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Close Trade At End Of Time Frame    
if strategy.position_size > 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Stop Loss and Take Profit
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)



더 많은