
이것은 다중 지수 이동 평균 (EMA) 과 상품 채널 지수 (CCI) 를 기반으로 한 트렌드 추적 전략이다. 이 전략은 여러 시간 주기의 EMA를 교차하여 잠재적인 트렌드 변화를 식별하고 CCI 지표와 결합하여 시장의 과매매 또는 과매매 상태를 확인하여 진입 시기의 정확성을 향상시킵니다. 이 전략은 또한 위험을 관리하고 이익을 잠금하기 위해 시간 및 가격에 기반한 동적 스톱 손실 메커니즘을 포함한다.
이 전략은 다음과 같은 몇 가지 핵심 요소에 기반합니다.
다중 EMA 교차: 8, 12, 24, 72 주기 EMA를 사용한다. 짧은 주기 EMA ((8, 12, 24) 가 동시에 72 주기 EMA를 횡단할 때, 잠재적인 다중 신호로 간주된다. 반대로 공백 신호이다.
CCI 지수 확인: 20주기 CCI 지수를 사용하여, CCI가 150보다 크면 과매상 상태를 확인하고, 150보다 작으면 과매상 상태를 확인한다.
입장 조건:
동적 정지 손실:
포지션 관리: 전 포지션 거래, 즉 계좌의 100%의 자금을 사용하여 거래하는 전략.
다중 확인 메커니즘: 다중 EMA 교차와 CCI 지표의 조화를 통해, 가짜 신호의 영향을 효과적으로 줄여 입시 정확도를 높였다.
유연한 입시 메커니즘: 전략은 한 번의 교차와 시간 창 내의 교차 두 가지 상황을 고려하여 다양한 시장 환경에 적응합니다.
다이내믹 리스크 관리: 다른 입점 모드에 따라 다른 스톱 스톱 손실 비율을 설정하여 수익과 위험을 더 잘 균형을 잡습니다.
트렌드 추적 능력: 여러 EMA의 교차를 사용하여 중기 및 장기 트렌드의 변화를 효과적으로 포착할 수 있다.
격동 현상을 필터링: CCI 지표의 과매매 판단을 통해, 수평 격동 시장에서 자주 거래되는 것을 피하는 데 도움이 됩니다.
지연성: EMA와 CCI는 지연된 지표이며, 급격하게 변동하는 시장에서 충분히 반응하지 않을 수 있습니다.
자주 거래: 불안한 시장에서, 더 많은 가짜 브레이크 신호가 발생할 수 있으며, 이는 자주 거래와 수수료의 증가로 이어집니다.
전체 포지션 리스크: 100% 포지션 거래는 큰 철회 위험을 초래할 수 있습니다.
고정 비율 상쇄: 변동성이 높은 시장에서 고정 비율 상쇄는 유리한 상황에서 조기 퇴출 할 수 있습니다.
역사적 데이터에 의존: 전략 성능은 역사적 데이터에 영향을 받을 수 있으며, 미래의 시장 환경 변화에 따라 재 최적화 매개 변수가 필요합니다.
변동률 지표 도입: ATR (Average True Range) 지표를 추가하는 것을 고려하여 시장의 변동에 따라 different market environment에 적응하기 위해 스톱 로즈 수준을 조정하십시오.
포지션 관리를 최적화: 동적 포지션 관리 메커니즘을 도입하여 시장 추세 강도 및 계좌의 위험 부담 능력에 따라 포지션 크기를 조정합니다.
필터링 조건을 추가: 거래량, 트렌드 강도 등의 지표를 추가하여 거래 신호를 더 필터링하여 승률을 높일 수 있습니다.
변수 최적화: 유전 알고리즘이나 격자 검색과 같은 방법을 사용하여, EMA 주기, CCI 값과 같은 변수를 최적화하여 다양한 시장 환경에서 전략의 적응성을 향상시킵니다.
시장 체제 인식에 참여: 시장 상태를 인식하는 모듈을 개발하여 다른 시장 상태에 따라 전략 매개 변수를 조정하거나 거래를 중지하십시오.
EMA와 CCI 다중 교차 트렌드 추적 전략은 기술 분석과 동적 위험 관리의 조합으로 이루어진 정량 거래 시스템이다. 다중 EMA 교차와 CCI 지표의 조합을 통해 전략은 시장의 추세를 효과적으로 포착할 수 있으며, 유연한 입점 메커니즘과 동적 스톱스톱을 통해 위험을 관리할 수 있다. 전략에는 지연성 및 전체 포지션 거래의 잠재적인 높은 회수와 같은 몇 가지 고유한 위험이 있지만, 변동율 조정, 동적 포지션 및 시장 관리 체제 식별 방법과 같은 추가적인 최적화 및 개선으로 전략의 안정성과 적응성을 크게 향상시킬 수 있다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-09-24 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA & CCI Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Параметры EMA
ema8_length = 8
ema12_length = 12
ema24_length = 24
ema72_length = 72
// Расчет EMA
ema8 = ta.ema(close, ema8_length)
ema12 = ta.ema(close, ema12_length)
ema24 = ta.ema(close, ema24_length)
ema72 = ta.ema(close, ema72_length)
// Параметры CCI
cci_length = 20
cci_overbought = 150
cci_oversold = -150
// Параметры тейк-профита и стоп-лосса
takeProfitPercent = input.float(1.5, title="Take Profit (%)", step=0.1)
stopLossPercent = input.float(0.5, title="Stop Loss (%)", step=0.1)
takeProfitPercentTime = input.float(0.5, title="Take Profit (%) for Time-based", step=0.1)
stopLossPercentTime = input.float(0.2, title="Stop Loss (%) for Time-based", step=0.1)
max_wait_bars = input.float(2, title="Max wait candles", step=1)
// Расчет CCI
cci = ta.cci(close, cci_length)
// Состояние открытой позиции
sz = strategy.position_size
// Флаги для отслеживания пересечений EMA вверх
var int ema8_cross_index_up = na
var int ema12_cross_index_up = na
var int ema24_cross_index_up = na
// Флаги для отслеживания пересечений EMA вниз
var int ema8_cross_index_down = na
var int ema12_cross_index_down = na
var int ema24_cross_index_down = na
// Проверка пересечения EMA с 72 вверх и обновление индекса пересечения
if (ta.crossover(ema8, ema72))
ema8_cross_index_up := bar_index
if (ta.crossover(ema12, ema72))
ema12_cross_index_up := bar_index
if (ta.crossover(ema24, ema72))
ema24_cross_index_up := bar_index
// Проверка пересечений EMA вниз и обновление индекса пересечения
if (ta.crossunder(ema8, ema72))
ema8_cross_index_down := bar_index
if (ta.crossunder(ema12, ema72))
ema12_cross_index_down := bar_index
if (ta.crossunder(ema24, ema72))
ema24_cross_index_down := bar_index
// Условия пересечения за одну свечу (лонг и шорт)
cross_condition_one_candle_long = (na(ema8_cross_index_up) == false and (bar_index - ema8_cross_index_up) == 0) and
(na(ema12_cross_index_up) == false and (bar_index - ema12_cross_index_up) == 0) and
(na(ema24_cross_index_up) == false and (bar_index - ema24_cross_index_up) == 0)
cross_condition_one_candle_short = (na(ema8_cross_index_down) == false and (bar_index - ema8_cross_index_down) == 0) and
(na(ema12_cross_index_down) == false and (bar_index - ema12_cross_index_down) == 0) and
(na(ema24_cross_index_down) == false and (bar_index - ema24_cross_index_down) == 0)
// Условия пересечения в течение указанного времени (лонг и шорт)
cross_condition_within_time_long = (not na(ema8_cross_index_up) and (bar_index - ema8_cross_index_up) <= max_wait_bars) and
(not na(ema12_cross_index_up) and (bar_index - ema12_cross_index_up) <= max_wait_bars) and
(not na(ema24_cross_index_up) and (bar_index - ema24_cross_index_up) <= max_wait_bars)
cross_condition_within_time_short = (not na(ema8_cross_index_down) and (bar_index - ema8_cross_index_down) <= max_wait_bars) and (not na(ema12_cross_index_down) and (bar_index - ema12_cross_index_down) <= max_wait_bars) and (not na(ema24_cross_index_down) and (bar_index - ema24_cross_index_down) <= max_wait_bars)
// Условие для открытия лонга
long_condition_one = cross_condition_one_candle_long and cci > cci_overbought and close > ema72
long_condition_time = cross_condition_within_time_long and cci > cci_overbought and close > ema72
// Условие для открытия шорта
short_condition_one = cross_condition_one_candle_short and cci < cci_oversold and close < ema72
short_condition_time = cross_condition_within_time_short and cci < cci_oversold and close < ema72
// Вход в лонг
if (long_condition_one and sz == 0)
strategy.entry(id='Long_one', direction=strategy.long)
if (long_condition_time and sz == 0)
strategy.entry(id='Long_time', direction=strategy.long)
// Вход в шорт
if (short_condition_one and sz == 0)
strategy.entry(id='Short_one', direction=strategy.short)
if (short_condition_time and sz == 0)
strategy.entry(id='Short_time', direction=strategy.short)
// Вычисление цен тейк-профита и стоп-лосса для лонга
if (sz > 0 and strategy.opentrades.entry_id(0) == 'Long_one')
entryPriceLong = strategy.opentrades.entry_price(0)
takeProfitPriceLong = entryPriceLong * (1 + takeProfitPercent / 100)
stopLossPriceLong = entryPriceLong * (1 - stopLossPercent / 100)
strategy.exit("Close long one", "Long_one", limit=takeProfitPriceLong, stop=stopLossPriceLong)
ema8_cross_index_up := na
ema12_cross_index_up := na
ema24_cross_index_up := na
if (sz > 0 and strategy.opentrades.entry_id(0) == 'Long_time')
entryPriceLongTime = strategy.opentrades.entry_price(0)
takeProfitPriceLongTime = entryPriceLongTime * (1 + takeProfitPercentTime / 100)
stopLossPriceLongTime = entryPriceLongTime * (1 - stopLossPercentTime / 100)
strategy.exit("Close long time", "Long_time", limit=takeProfitPriceLongTime, stop=stopLossPriceLongTime)
ema8_cross_index_up := na
ema12_cross_index_up := na
ema24_cross_index_up := na
// Вычисление цен тейк-профита и стоп-лосса для шорта
if (sz < 0 and strategy.opentrades.entry_id(0) == 'Short_one')
entryPriceShort = strategy.opentrades.entry_price(0)
takeProfitPriceShort = entryPriceShort * (1 - takeProfitPercent / 100)
stopLossPriceShort = entryPriceShort * (1 + stopLossPercent / 100)
strategy.exit("Close short one", "Short_one", limit=takeProfitPriceShort, stop=stopLossPriceShort)
ema8_cross_index_down := na
ema12_cross_index_down := na
ema24_cross_index_down := na
if (sz < 0 and strategy.opentrades.entry_id(0) == 'Short_time')
entryPriceShortTime = strategy.opentrades.entry_price(0)
takeProfitPriceShortTime = entryPriceShortTime * (1 - takeProfitPercentTime / 100)
stopLossPriceShortTime = entryPriceShortTime * (1 + stopLossPercentTime / 100)
strategy.exit("Close short time", "Short_time", limit=takeProfitPriceShortTime, stop=stopLossPriceShortTime)
ema8_cross_index_down := na
ema12_cross_index_down := na
ema24_cross_index_down := na
// Отображение EMA на графике
plot(ema8, title="EMA 8", color=color.blue, linewidth=2)
plot(ema12, title="EMA 12", color=color.orange, linewidth=2)
plot(ema24, title="EMA 24", color=color.green, linewidth=2)
plot(ema72, title="EMA 72", color=color.red, linewidth=2)
// Вывод CCI в подвале
//plot(cci, title="CCI", color=color.purple)
//hline(100, "CCI 150", color=color.green)
//hline(-100, "CCI -150", color=color.red)
//hline(0, "CCI 0", color=color.gray)
// Отладочная информация
//plotshape(series=long_condition_one, location=location.belowbar, color=color.lime, style=shape.labelup, title="Long Condition")
//plotshape(series=cross_condition_one_candle_long, location=location.belowbar, color=color.blue, style=shape.triangleup, title="Cross Condition Long")
//plotshape(series=long_condition_time, location=location.belowbar, color=#e6d700, style=shape.labelup, title="Long Condition Time")
//plotshape(series=cross_condition_within_time_long, location=location.belowbar, color=#a21dbd, style=shape.triangleup, title="Cross Condition Time Long")
//plotshape(series=short_condition_one, location=location.abovebar, color=color.red, style=shape.labeldown, title="Short Condition")
//plotshape(series=cross_condition_one_candle_short, location=location.abovebar, color=color.blue, style=shape.triangledown, title="Cross Condition Short")
//plotshape(series=short_condition_time, location=location.abovebar, color=#e6d700, style=shape.labeldown, title="Short Condition Time")
//plotshape(series=cross_condition_within_time_short, location=location.abovebar, color=#a21dbd, style=shape.triangledown, title="Cross Condition Time Short")