역동적인 CCI 지원 및 저항 전략

저자:차오장, 날짜: 2024-01-22 16:37:46
태그:

img

전반적인 설명

이 전략은 CCI 지표의 회전 지점을 사용하여 동적 지지 및 저항 수준을 계산하고 구매 및 판매 신호를 찾기 위해 트렌드 판단을 결합합니다. 이 전략은 CCI의 반전 특성과 중장기 수익 트렌드의 반전 지점을 파악하는 트렌드 추적 능력을 통합합니다.

전략 원칙

CCI 지표는 시장이 너무 약하거나 너무 강하다는 것을 나타낼 수 있습니다. 80과 -80의 두 극단은 시장이 과잉 구매 또는 과잉 판매 상태에 들어갔는지 여부를 결정하는 데 사용될 수 있습니다. 이 전략은 CCI의 이러한 특성을 활용합니다. 왼쪽과 오른쪽 50 바의 피벗 포인트를 계산하여 상위 및 하위 피벗 포인트를 얻습니다. 그 다음 피벗 포인트에 따라 버퍼를 추가하거나 빼면서 지지 및 저항 라인을 동적으로 구성합니다.

구매 신호는 닫기가 개방보다 높고 상위 지원 수준보다 낮을 때 생성됩니다. 닫기가 개방보다 낮고 낮은 저항 수준보다 높을 때 판매 신호가 생성됩니다. 주요 트렌드 방향에 대한 거래 신호를 필터링하기 위해 전략은 또한 EMA와 기울기 지표를 결합하여 현재 주요 트렌드 방향을 결정합니다. 장거리 엔트리 트레이드는 트렌드가 상승세를 결정했을 때만 배치됩니다. 짧은 엔트리 트레이드는 트렌드가 하락세를 결정했을 때만 배치됩니다.

스톱 로즈와 이윤 취득은 ATR 지표에 기초하여 동적으로 계산되며, 이 전략의 위험 통제가 더 합리적입니다.

이점 분석

  1. CCI의 반전 특성을 활용하여 잠재적 반전 지점 근처에 적립하여 수익 가능성을 높입니다.
  2. 트렌드 판단과 결합하면 트렌드에 반대하는 거래를 피하고 손실을 줄일 수 있습니다.
  3. 동적 스톱 로스 및 수익 설정은 위험 통제를 더 합리적으로 만듭니다.
  4. CCI 길이, 버퍼 크기 등 사용자 정의 가능한 매개 변수는 더 많은 시장 환경에 적응합니다.

위험 분석

  1. CCI 지표는 잘못된 신호를 생성하는 경향이 있으며, 트렌드 판단에서 필터를 필요로합니다.
  2. 회귀는 항상 성공하지 않습니다. 손실의 위험이 있습니다.
  3. 부적절한 매개 변수 설정은 과도한 거래 또는 놓친 기회로 이어질 수 있습니다.

매개 변수 최적화, 스톱 로스 범위 조정 등과 같은 방법은 위험을 줄이는 데 도움이 될 수 있습니다. 또한이 전략은 신호에 완전히 의존하지 않고 다른 지표에 보조 도구로 사용될 수 있습니다.

최적화 방향

  1. 다양한 변동성 수준의 시장에 적응하기 위해 버퍼 크기를 최적화합니다.
  2. 더 정확한 동적 스톱 손실 및 수익을 위해 ATR 기간 매개 변수를 최적화합니다.
  3. 다른 CCI 매개 변수 설정을 테스트합니다.
  4. 다른 유형의 트렌드 판단 지표의 효과를 테스트합니다.

결론

이 전략은 CCI의 장기/단기 스크리닝 능력과 트렌드 판단에서 필터 확인을 통합하여, 특정 실용적 가치를 가지고 있다. 동적인 스톱 로스 및 영업은 또한 실제 거래에서 전략을 적용할 때 위험을 통제할 수 있게 한다. 매개 변수 최적화와 개선을 통해 더 나은 결과를 기대할 수 있다.


/*backtest
start: 2023-12-22 00:00:00
end: 2024-01-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AliSignals


//@version=5
strategy("CCI based support and resistance strategy", overlay=true  )


cci_length = input.int(50, "cci length")
right_pivot = input.int(50, "right pivot")
left_pivot = input.int(50, "left pivot")
buffer = input.float(10.0, "buffer")
trend_matter = input.bool(true, "trend matter?")
showmid = input.bool ( false , "show mid?")
trend_type = input.string("cross","trend type" ,options = ["cross","slope"])
slowma_l = input.int(100, "slow ma length")
fastma_l = input.int(50, "fast ma length")
slope_l = input.int(5,  "slope's length for trend detection")
ksl = input.float(1.1)
ktp = input.float(2.2)
restf = input.timeframe(title="Time Frame of Last Period for Calculating max" , defval="D")



// Calculating Upper and Lower CCI
cci = ta.cci(hlc3,cci_length)

uppercci = 0.0
lowercci = 0.0

uppercci := fixnan(ta.pivothigh(cci, left_pivot, right_pivot)) - buffer
lowercci := fixnan(ta.pivotlow (cci, left_pivot, right_pivot)) + buffer
midccci  = math.avg(uppercci,lowercci)


// Support and Resistance based on CCI
res = uppercci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)
sup = lowercci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)
mid =  midccci*(0.015*ta.dev(hlc3,cci_length))+ ta.sma(hlc3,cci_length)



// Calculating trend
t_cross  = 0
t_cross := ta.ema(close,fastma_l) > ta.ema(close,slowma_l) ? 1 : ta.ema(close,fastma_l) < ta.ema(close,slowma_l) ? -1 : t_cross[1] 

t_slope  = 0
t_slope := ta.ema(close,slowma_l) > ta.ema(close,slowma_l)[slope_l] ? 1 : ta.ema(close,slowma_l) < ta.ema(close,slowma_l)[slope_l]  ? -1 : t_slope[1] 

t  = 0
t := trend_type == "cross" ? t_cross : trend_type == "slope" ? t_slope : na

colort =  trend_matter == false ? color.rgb(201, 251, 0) : t == 1 ? color.rgb(14, 243, 132) :  t == -1 ? color.rgb(255, 34, 34) : na
bull_t = trend_matter == false or t ==  1
bear_t = trend_matter == false or t == -1

plot(res, color = colort)
plot(sup, color = colort)
plot(showmid == true ? mid : na)


// Long and Short enter condition
buy  = bull_t == 1 and ta.lowest (2) < sup and close > open and close > sup
sell = bear_t == 1 and ta.highest(2) > res and close < open and close < res

plotshape( buy , color=color.rgb(6, 255, 23) , location = location.belowbar, style = shape.triangleup  , size = size.normal)
plotshape( sell, color=color.rgb(234, 4, 4) ,  location = location.abovebar, style = shape.triangledown, size = size.normal)





atr = ta.atr(100)



CLOSE=request.security(syminfo.tickerid, restf, close)
max = 0.0
max := CLOSE == CLOSE[1] ? math.max(max[1], atr) : atr
act_atr = 0.0
act_atr := CLOSE == CLOSE[1] ? act_atr[1] : max[1]

atr1 =  math.max(act_atr, atr) 

dis_sl = atr1 * ksl
dis_tp = atr1 * ktp


var float longsl  = open[1] - dis_sl
var float shortsl = open[1] + dis_sl
var float longtp =   open[1] + dis_tp
var float shorttp =  open[1] - dis_tp


longCondition = buy
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = sell
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)


longsl  := strategy.position_size > 0  ? longsl[1]  : close - dis_sl
shortsl := strategy.position_size < 0 ? shortsl[1] : close + dis_sl
longtp  := strategy.position_size > 0  ? longtp[1]  : close + dis_tp
shorttp := strategy.position_size < 0 ? shorttp[1] : close - dis_tp




if strategy.position_size > 0 
    strategy.exit(id="My Long close Id", from_entry ="My Long Entry Id" , stop=longsl, limit=longtp)
if strategy.position_size < 0 
    strategy.exit(id="My Short close Id", from_entry ="My Short Entry Id" , stop=shortsl, limit=shorttp)



더 많은