다중 시간 프레임에 대한 동적 손절매를 통한 EMA-Squeeze 거래 전략

EMA SQM CMF KC SL TP MTF
생성 날짜: 2024-12-11 15:50:38 마지막으로 수정됨: 2024-12-11 15:50:38
복사: 0 클릭수: 435
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 시간 프레임에 대한 동적 손절매를 통한 EMA-Squeeze 거래 전략

개요

이 전략은 다중 시간 주기의 분석에 기반한 동적 거래 시스템으로, 지수 이동 평균 ((EMA), Squeeze 동적 지수 ((SQM) 및 자금 흐름 지수 ((CMF) 을 결합하여 거래 신호를 생성한다. 전략의 핵심은 여러 시간 프레임의 분석을 통해 트렌드를 확인하고, 동적 스톱로스를 사용하여 리스크 관리를 최적화한다. 이 전략은 자율적 인 스톱로스 및 수익 프로그램을 채택하여 시장의 변동성에 따라 거래 매개 변수를 자동으로 조정할 수 있습니다.

전략 원칙

전략은 거래 기회를 식별하기 위해 세 가지 주요 기술 지표의 조합을 사용합니다. 첫째, 11-주기 및 34-주기 EMA를 통해 시장의 추세 방향을 결정합니다. 둘째, 개선된 버전의 Squeeze Momentum 지표를 사용하여 시장의 압력과 잠재적인 돌파구를 감지합니다. 이 지표는 선형 회귀 방식을 통해 가격 편차를 계산합니다. 마지막으로, 개선된 자금 흐름 지표 (CMF) 를 통해 거래 방향을 확인하여 가격 움직임을 지원하는 충분한 자금이 있는지 확인합니다. 전략은 신호를 확인한 후 동적인 중지 지점을 설정하고, 중지 지점은 수익이 증가함에 따라 자동으로 조정됩니다.

전략적 이점

  1. 다차원 신호 확인: 여러 기술 지표와 시간 주기 분석을 결합하여 가짜 신호의 위험을 크게 감소시킵니다.
  2. 지능형 위험 관리: 동적 중지 시스템은 시장의 변동에 따라 자동으로 조정할 수 있으며, 수익을 보호하면서 조기 출전을 피할 수 있습니다.
  3. 자기 적응력: 전략의 매개 변수는 다른 시장 조건에 따라 조정될 수 있으며, 잘 적응한다.
  4. 완전한 거래 폐쇄 고리: 입시 신호부터 출구 관리에 이르기까지 명확한 규칙이 존재하여 주관적 판단의 영향을 줄입니다.
  5. 유통 확인: 유통을 모니터링하여 가격 움직임을 확인하여 거래의 신뢰성을 향상시킵니다.

전략적 위험

  1. 매개 변수 민감성: 여러 기술 지표의 매개 변수 설정은 신중한 최적화가 필요하며, 부적절한 매개 변수는 성능 저하로 이어질 수 있다.
  2. 시장 환경 의존성: 급격한 변동성 또는 낮은 유동성 시장 환경에서는 신호 품질이 영향을 받을 수 있다.
  3. 계산 복잡성: 여러 시간 주기 계산은 신호 지연으로 인해 실제 거래 효과에 영향을 미칠 수 있습니다.
  4. 정지 조정 위험: 동적 정지는 특정 시장 조건에서 너무 급진적이거나 보수적일 수 있습니다.
  5. 재원 관리 요구 사항: 전략은 위험과 수익을 균형 잡기 위해 합리적인 재원 관리가 필요합니다.

전략 최적화 방향

  1. 변동율 적응을 도입: ATR 또는 다른 변동율 지표에 따라 변수를 동적으로 조정하여 전략의 적응성을 향상시킬 수 있습니다.
  2. 최적화된 신호 필터링: 거래량 가중치 또는 시간 필터를 추가하여 신호 품질을 향상시킬 수 있다.
  3. 개선된 스톱 메커니즘: 지지점과 저항점과 결합하여 스톱 포인트의 설정을 최적화할 수 있다.
  4. 시장 환경 분석을 추가: 시장 추세 강도 지표를 도입하고, 다른 시장 환경에서 다른 파라미터 설정을 사용합니다.
  5. 자본 관리: 포지션 관리 알고리즘을 도입하여 신호 강도 및 시장 변동에 따라 포지션 비율을 조정한다.

요약하다

이 전략은 다차원적인 기술적 분석과 지능적인 위험 관리를 통해 거래자에게 체계화된 거래 프로그램을 제공합니다. 그것의 핵심 장점은 트렌드 추적과 동적 위험 관리를 결합하여 수익을 보호하면서 시장 기회를 잡을 수 있다는 것입니다. 전략에는 최적화해야 할 측면이 있지만, 합리적인 매개 변수 설정과 위험 통제를 통해 효과적인 거래 도구로 사용할 수 있습니다.

전략 소스 코드
/*backtest
start: 2024-11-10 00:00:00
end: 2024-12-09 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("LL Crypto - SUI", overlay=true)

// Parâmetros de tempo para criptomoedas
fast_ema_len = input.int(11, minval=5, title="Fast EMA")
slow_ema_len = input.int(34, minval=20, title="Slow EMA")
sqm_lengthKC = input.int(20, title="SQM KC Length")
kauf_period = input.int(20, title="Kauf Period")
kauf_mult = input.float(2, title="Kauf Mult factor")
min_profit_sl = input.float(5, minval=0.01, maxval=100.0, title="Min profit to start moving SL [%]")
longest_sl = input.float(10, minval=0.01, maxval=100.0, title="Maximum possible of SL [%]")
sl_step = input.float(0.5, minval=0.0, maxval=1.0, title="Take profit factor")

// Parâmetros adaptados para criptomoedas
CMF_length = input.int(11, minval=1, title="CMF length")
show_plots = input.bool(true, title="Show plots")

// Definir intervalos de tempo para criptomoedas
selected_timeframe = input.string(defval="15", title="Intervalo de Tempo", options=["1", "15", "60"])

lower_resolution = timeframe.period == '1' ? '1' :
                   timeframe.period == '5' ? '15' :
                   timeframe.period == '15' ? '60' :
                   timeframe.period == '60' ? '240' :
                   timeframe.period == '240' ? 'D' :
                   timeframe.period == 'D' ? 'W' : 'M'

sp_close = close[barstate.isrealtime ? 1 : 0]
sp_high = high[barstate.isrealtime ? 1 : 0]
sp_low = low[barstate.isrealtime ? 1 : 0]
sp_volume = volume[barstate.isrealtime ? 1 : 0]

// Calcular Squeeze Momentum ajustado para criptomoedas
sqm_val = ta.linreg(sp_close - math.avg(math.avg(ta.highest(sp_high, sqm_lengthKC), ta.lowest(sp_low, sqm_lengthKC)), ta.sma(sp_close, sqm_lengthKC)), sqm_lengthKC, 0)
close_low = request.security(syminfo.tickerid, lower_resolution, sp_close, lookahead=barmerge.lookahead_on)
high_low = request.security(syminfo.tickerid, lower_resolution, sp_high, lookahead=barmerge.lookahead_on)
low_low = request.security(syminfo.tickerid, lower_resolution, sp_low, lookahead=barmerge.lookahead_on)
sqm_val_low = ta.linreg(close_low - math.avg(math.avg(ta.highest(high_low, sqm_lengthKC), ta.lowest(low_low, sqm_lengthKC)), ta.sma(close_low, sqm_lengthKC)), sqm_lengthKC, 0)

// CMF adaptado para criptomoedas
ad = sp_close == sp_high and sp_close == sp_low or sp_high == sp_low ? 0 : ((2 * sp_close - sp_low - sp_high) / (sp_high - sp_low)) * sp_volume
money_flow = math.sum(ad, CMF_length) / math.sum(sp_volume, CMF_length)

// Condições de entrada para criptomoedas
low_condition_long = (sqm_val_low > sqm_val_low[1])
low_condition_short = (sqm_val_low < sqm_val_low[1])
money_flow_min = (money_flow[4] > money_flow[2]) and (money_flow[3] > money_flow[2]) and (money_flow[2] < money_flow[1]) and (money_flow[2] < money_flow)
money_flow_max = (money_flow[4] < money_flow[2]) and (money_flow[3] < money_flow[2]) and (money_flow[2] > money_flow[1]) and (money_flow[2] > money_flow)
condition_long = ((sqm_val > sqm_val[1])) and money_flow_min and ta.lowest(sqm_val, 5) < 0
condition_short = ((sqm_val < sqm_val[1])) and money_flow_max and ta.highest(sqm_val, 5) > 0
enter_long = low_condition_long and condition_long
enter_short = low_condition_short and condition_short

// Stop conditions
var float current_target_price = na
var float current_sl_price = na
var float current_target_per = na
var float current_profit_per = na

set_targets(isLong, min_profit, current_target_per, current_profit_per) =>
    float target = na
    float sl = na
    if isLong
        target := sp_close * (1.0 + current_target_per)
        sl := sp_close * (1.0 - (longest_sl / 100.0))
    else
        target := sp_close * (1.0 - current_target_per)
        sl := sp_close * (1.0 + (longest_sl / 100.0))
    [target, sl]

target_reached(isLong, min_profit, current_target_per, current_profit_per) =>
    float target = na
    float sl = na
    float profit_per = na
    float target_per = na
    if current_profit_per == na
        profit_per := (min_profit * sl_step) / 100.0
    else
        profit_per := current_profit_per + ((min_profit * sl_step) / 100.0)
    target_per := current_target_per + (min_profit / 100.0)
    if isLong
        target := strategy.position_avg_price * (1.0 + target_per)
        sl := strategy.position_avg_price * (1.0 + profit_per)
    else
        target := strategy.position_avg_price * (1.0 - target_per)
        sl := strategy.position_avg_price * (1.0 - profit_per)
    [target, sl, profit_per, target_per]

hl_diff = ta.sma(sp_high - sp_low, kauf_period)
stop_condition_long = 0.0
new_stop_condition_long = sp_low - (hl_diff * kauf_mult)
if (strategy.position_size > 0)
    if (sp_close > current_target_price)
        [target, sl, profit_per, target_per] = target_reached(true, min_profit_sl, current_target_per, current_profit_per)
        current_target_price := target
        current_sl_price := sl
        current_profit_per := profit_per
        current_target_per := target_per
    stop_condition_long := math.max(stop_condition_long[1], current_sl_price)
else
    stop_condition_long := new_stop_condition_long

stop_condition_short = 99999999.9
new_stop_condition_short = sp_high + (hl_diff * kauf_mult)
if (strategy.position_size < 0)
    if (sp_close < current_target_price)
        [target, sl, profit_per, target_per] = target_reached(false, min_profit_sl, current_target_per, current_profit_per)
        current_target_price := target
        current_sl_price := sl
        current_profit_per := profit_per
        current_target_per := target_per
    stop_condition_short := math.min(stop_condition_short[1], current_sl_price)
else
    stop_condition_short := new_stop_condition_short

// Submit entry orders
if (enter_long and (strategy.position_size <= 0))
    if (strategy.position_size < 0)
        strategy.close(id="SHORT")
    current_target_per := (min_profit_sl / 100.0)
    current_profit_per := na
    [target, sl] = set_targets(true, min_profit_sl, current_target_per, current_profit_per)
    current_target_price := target
    current_sl_price := sl
    strategy.entry(id="LONG", direction=strategy.long)

    if show_plots
        label.new(bar_index, sp_high, text="LONG\nSL: " + str.tostring(stop_condition_long), style=label.style_label_down, color=color.green)





if (enter_short and (strategy.position_size >= 0))
    if (strategy.position_size > 0)
        strategy.close(id="LONG")
    current_target_per := (min_profit_sl / 100.0)
    current_profit_per := na
    [target, sl] = set_targets(false, min_profit_sl, current_target_per, current_profit_per)
    current_target_price := target
    current_sl_price := sl
    strategy.entry(id="SHORT", direction=strategy.short)
    if show_plots
        label.new(bar_index, sp_high, text="SHORT\nSL: " + str.tostring(stop_condition_short), style=label.style_label_down, color=color.red)

if (strategy.position_size > 0)
    strategy.exit(id="EXIT LONG", stop=stop_condition_long)

if (strategy.position_size < 0)
    strategy.exit(id="EXIT SHORT", stop=stop_condition_short)

// Plot anchor trend
plotshape(low_condition_long, style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(low_condition_short, style=shape.triangledown, location=location.abovebar, color=color.red)

plotshape(condition_long, style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(condition_short, style=shape.triangledown, location=location.belowbar, color=color.red)

plotshape(enter_long, style=shape.triangleup, location=location.bottom, color=color.green)
plotshape(enter_short, style=shape.triangledown, location=location.bottom, color=color.red)

// Plot emas
plot(ta.ema(close, 20), color=color.blue, title="20 EMA")
plot(ta.ema(close, 50), color=color.orange, title="50 EMA")
plot(ta.sma(close, 200), color=color.red, title="MA 200")

// Plot stop loss values for confirmation
plot(series=(strategy.position_size > 0) and show_plots ? stop_condition_long : na, color=color.green, style=plot.style_linebr, title="Long Stop")
plot(series=(strategy.position_size < 0) and show_plots ? stop_condition_short : na, color=color.green, style=plot.style_linebr, title="Short Stop")
plot(series=(strategy.position_size < 0) and show_plots ? current_target_price : na, color=color.yellow, style=plot.style_linebr, title="Short TP")
plot(series=(strategy.position_size > 0) and show_plots ? current_target_price : na, color=color.yellow, style=plot.style_linebr, title="Long TP")