추세 추종 평균 회귀 채널 전략


생성 날짜: 2023-11-01 16:20:45 마지막으로 수정됨: 2023-11-01 16:20:45
복사: 0 클릭수: 747
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

추세 추종 평균 회귀 채널 전략

개요

이 전략은 CCI 지표에 기반하여 유연한 트렌드를 추적하는 자동 거래 시스템을 설계했다. 그것은 CCI 지표의 0 축에 따라 상부 또는 하부로 거래 신호를 발산 할 수 있으며, 사용자 정의 상부 채널 밴드 및 채널 밴드 교차로 신호를 발산 할 수 있다. 전략은 고정된 중지 손실, 중지 비율을 설정 할 수 있으며, 시간 단위 거래 및 일일 고정 시간 단위 거래 등의 다양한 기능을 갖추고 있다.

전략 원칙

  1. CCI 지표의 0축 교차를 사용하여 시장의 흐름을 판단합니다. CCI 상단 0축을 가로지르는 것은 낙점 신호이며, CCI 하단 0축을 가로지르는 것은 낙점 신호입니다.

  2. 사용자 정의 CCI 상하 채널 밴드, CCI 상하 채널 밴드 상하 채널 밴드 상향 신호, CCI 하하 채널 밴드 하향 신호. 채널 밴드 교차는 중지 신호.

  3. 특정 시간대에 거래할 수 있고 거래되지 않은 시간대에 평점 을 설정할 수 있다. 매일 일정한 시간대에 거래할 수 있다.

  4. 고정 스톱 손실, 스톱 비율을 설정할 수 있다.

  5. 사용자 정의 가능한 트레이딩 Alert 메시지

  6. 정책은 완전히 사용자 정의 가능하며 CCI 파라미터, 통로 밴드 파라미터, 스톱 스톱 파라미터와 같은 최적화 전략을 조정할 수 있습니다.

우위 분석

  1. CCI 지표는 시장의 흐름을 판단하기 위해 사용되며, 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)