다중 EMA, RSI 및 표준편차에 기반한 출구 촛불 높이의 브레이크오웃 거래 전략

저자:차오장, 날짜: 2024-03-28 16:13:45
태그:

img

전략 개요

이 전략은 잠재적 인 구매 및 판매 기회를 식별하기 위해 여러 가지 기하급수적인 이동 평균 (EMA), 상대적 강도 지수 (RSI) 및 표준 편차 기반 출구 조건을 결합합니다. 시장 트렌드의 방향과 강도를 분석하기 위해 단기 (6, 8, 12 일), 중기 (55 일) 및 장기 (150, 200, 250 일) EMA를 사용합니다. 구성 가능한 구매 (30) 및 판매 (70) 임계로 RSI는 추진력을 평가하고 과소매 또는 과소매 조건을 식별하는 데 사용됩니다. 전략은 또한 종료 가격이 12 일 EMA에서 구성 가능한 표준 편차 범위에 도달 할 때 작동하는 독특한 출구 메커니즘을 갖추고 있으며 수익을 보호하거나 손실을 최소화 할 수있는 방법을 제공합니다.

전략 원칙

  1. 여러 EMA (6, 8, 12, 55, 100, 150, 200) 를 시각적 참조로 계산하여 시장 트렌드를 평가합니다.
  2. 사용자 입력 (3-4개의 촛불) 을 기반으로 가장 최근의 N 촛불 중 가장 높은 높음과 가장 낮은 낮음을 결정합니다.
  3. 엔트리 로그: 최근 N 촛불 중 가장 높은 마이너보다 높고 EMA 필터 (가동된 경우) 이상입니다.
  4. 엔트리 쇼트: 최근 N 촛불의 최저 하위보다 낮고 EMA 필터 (가동된 경우) 아래의 현재 폐쇄입니다.
  5. 엑시트 롱: 현재 클로지는 12일 EMA + 0.5 표준편차 이하 또는 12일 EMA 이하입니다.
  6. 마감 마감: 현재 마감은 12일 EMA - 0.5 표준편차 이상 또는 12일 EMA 이상입니다.
  7. RSI를 14의 채무 기간, 30의 과반 판매 한계, 70의 과반 구매 한계로 보충적 지표로 사용하십시오.

전략적 장점

  1. 더 포괄적인 시장 분석 관점을 위해 트렌드 추적 (다중 EMA) 및 모멘텀 (RSI) 차원을 결합합니다.
  2. 표준편차에 기반한 유일한 출구 메커니즘은 이익을 보호하고 위험을 통제하는 균형을 유지할 수 있습니다.
  3. 사용자가 구성할 수 있는 주요 매개 변수를 가진 고도로 모듈화된 코드입니다.
  4. 여러 도구와 시간 프레임에 적용됩니다. 특히 매일 주식과 비트코인 거래.

위험 분석

  1. 시장 통합 또는 초기 트렌드 역전 중 빈번한 잘못된 신호로 인해 연속적인 손실이 발생합니다.
  2. 기본 매개 변수는 모든 시장 조건에 효과적이지 않을 수 있습니다. 백테스팅에 기반한 최적화가 필요합니다.
  3. 이 전략에만 의존하는 것은 위험합니다. 다른 지표와 함께 의사 결정에 대한 지원/저항 수준을 결합하는 것이 좋습니다.
  4. 갑작스러운 주요 사건으로 인해 트렌드 전환에 반응하는 것이 느립니다.

최적화 방향

  1. EMA 및 RSI 매개 변수를 최적화하십시오: 도구, 시간 프레임 및 시장 특성에 따라 최적의 매개 변수 범위를 철저하게 검색하십시오.
  2. 스톱 로스 및 취리 메커니즘을 도입: 단일 거래 위험을 제어하기 위해 ATR과 같은 변동성 지표에 대한 참조로 합리적인 스톱 로스 및 취리 수익 수준을 설정하십시오.
  3. 포지션 크기를 구현하십시오. 트렌드 강도 (예: ADX) 또는 주요 지원/저항 수준에 가까운 위치에 따라 포지션 크기를 조정하십시오.
  4. 다른 기술적 지표와 결합: 볼링거 밴드, MACD, 이동 평균 크로스오버와 같이 입력/출출 신호의 신뢰성을 향상시킵니다.
  5. 다른 시장 상태에 최적화: 트렌딩, 범위 및 전환 시장을 위해 매개 변수 조합을 세밀하게 조정합니다.

요약

이 문서에서는 여러 이동 평균, RSI 및 표준 편차 출구에 기반한 촛불 높이의 브레이크아웃 거래 전략을 제안합니다. 전략은 트렌드 기회를 포착하고 위험을 관리하기 위해 독특한 표준 편차 출구 메커니즘을 사용하는 동시에 트렌드 및 동력 차원에서 시장을 분석합니다. 전략 논리는 명확하고 엄격하며 코드 구현은 간결하고 효율적입니다. 적절한 최적화와 함께이 전략은 견고한 내일 중~고 주파수 거래 전략이 될 가능성이 있습니다. 그러나 모든 전략에는 한계가 있으며 맹목적인 사용이 위험을 가져올 수 있다는 점에 유의해야합니다. 양적 거래는 기계적 인 신호 순서 과정이 아니라 전반적인 시장 상황을 파악하고 신중한 리스크 관리를 기반으로 만들어져야합니다. 거래자는 또한 거래 성과를 평가하고 신속한 전략 조정을 수행하고 장기적인 성공을 달성하기 위해 자신의 스타일과 위험 관용을 지속적으로 결합해야합니다.


/*backtest
start: 2023-03-22 00:00:00
end: 2024-03-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Candle Height Breakout with Configurable Exit and Signal Control", shorttitle="CHB Single Signal", overlay=true)

// Input parameters for EMA filter and its length
useEmaFilter = input.bool(true, "Use EMA Filter", group="Entry Conditions")
emaFilterLength = input.int(55, "EMA Filter Length", minval=1, group="Entry Conditions")
candleCount = input.int(4, "SamG Configurable Candle Count for Entry", minval=3, maxval=4, step=1, group="Entry Conditions")
exitEmaLength = input.int(12, "Exit EMA Length", minval=1, group="Exit Conditions", defval=12)
exitStdDevMultiplier = input.float(0.5, "Exit Std Dev Multiplier", minval=0.1, maxval=2.0, step=0.1, group="Exit Conditions")

// State variables to track if we are in a long or short position
var bool inLong = false
var bool inShort = false

// Calculating EMAs with fixed periods for visual reference
ema6 = ta.ema(close, 6)
ema8 = ta.ema(close, 8)
ema12 = ta.ema(close, 12)
ema55 = ta.ema(close, 55)
ema100 = ta.ema(close, 100)
ema150 = ta.ema(close, 150)
ema200 = ta.ema(close, 200)
emaFilter = ta.ema(close, emaFilterLength)
exitEma = ta.ema(close, exitEmaLength)

// Plotting EMAs
plot(ema6, "EMA 6", color=color.red)
plot(ema8, "EMA 8", color=color.orange)
plot(ema12, "EMA 12", color=color.yellow)
plot(ema55, "EMA 55", color=color.green)
plot(ema100, "EMA 100", color=color.blue)
plot(ema150, "EMA 150", color=color.purple)
plot(ema200, "EMA 200", color=color.fuchsia)
plot(emaFilter, "EMA Filter", color=color.black)
plot(exitEma, "Exit EMA", color=color.gray)

// Calculating the highest and lowest of the last N candles based on user input
highestOfN = ta.highest(high[1], candleCount)
lowestOfN = ta.lowest(low[1], candleCount)

// Entry Conditions with EMA Filter
longEntryCondition = not inLong and not inShort and (close > highestOfN) and (not useEmaFilter or (useEmaFilter and close > emaFilter))
shortEntryCondition = not inLong and not inShort and (close < lowestOfN) and (not useEmaFilter or (useEmaFilter and close < emaFilter))

// Update position state on entry
if (longEntryCondition)
    strategy.entry("Buy", strategy.long, comment="B")
    inLong := true
    inShort := false

if (shortEntryCondition)
    strategy.entry("Sell", strategy.short, comment="S")
    inLong := false
    inShort := true

// Exit Conditions based on configurable EMA and Std Dev Multiplier
smaForExit = ta.sma(close, exitEmaLength)
upperExitBand = smaForExit + exitStdDevMultiplier * ta.stdev(close, exitEmaLength)
lowerExitBand = smaForExit - exitStdDevMultiplier * ta.stdev(close, exitEmaLength)

exitConditionLong = inLong and (close < upperExitBand or close < exitEma)
exitConditionShort = inShort and (close > lowerExitBand or close > exitEma)

// Strategy exits
if (exitConditionLong)
    strategy.close("Buy", comment="Exit")
    inLong := false

if (exitConditionShort)
    strategy.close("Sell", comment="Exit")
    inShort := false

// Visualizing entry and exit points
plotshape(series=longEntryCondition, style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="Buy Signal", text="B")
plotshape(series=shortEntryCondition, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="Sell Signal", text="S")


더 많은