EMA 필터와 세션 타임프레임과 함께 상위 대 하위 클로즈 촛불 전략

저자:차오장, 날짜: 2023-12-27 14:38:28
태그:

img

1. 전략 개요

이 전략은 EMA 필터와 세션 시간 프레임과 함께 업 버스 다운 클로즈 촛불 전략이라고 불립니다. 특정 룩백 기간 동안 시장 정서를 결정하기 위해 업과 다운 클로즈 촛불의 수를 계산하고, EMA 필터와 특정 세션에서 거래를 결합하여 긴 신호와 짧은 신호를 식별합니다.

2. 전략 논리

핵심 논리는 최근 룩백 기간 동안 (upCloseCount) 과 (downCloseCount) 의 수를 계산하는 것입니다. (upCloseCount) 이 더 큰 경우 상승 시장을 나타냅니다. (downCloseCount) 이 더 큰 경우 하락 시장을 나타냅니다. EMA 지표는 필터로 사용됩니다. 가격 > EMA 때만 길고 가격이 < EMA 때 짧습니다. 또한 세션1과 세션2를 거래 세션으로 설정합니다.

세부적인 논리:

긴 신호는: inSession true (거래 세션에서) 와 upCloseCount > downCloseCount (더 많은 가까운 촛불) 와 close > ema (EMA보다 높은 닫기 가격) 과 currentSignal가 long (현재의 위치가 없습니다) 이 아닌 경우 발생합니다.

짧은 신호는: inSession true and downCloseCount > upCloseCount (더 아래로 닫는 촛불) 및 close < ema (EMA보다 낮은 닫는 가격) 및 currentSignal가 short (현재의 위치가 없습니다) 이 아닌 경우 발생합니다.

3. 이점 분석

  1. 시장 정서와 추세를 캡처 하 고 닫기 / 다운 닫기 촛불 역사를 비교
  2. EMA 필터를 사용 하 여 다양한 시장에서 거래를 피합니다.
  3. 세션을 설정하여 주요 거래 시간 이외의 잡음을 피하십시오.
  4. 트렌드 추종과 거래 빈도 사이의 균형

4. 위험 분석

  1. 옆 시장에서 오도 될 수 있습니다.
  2. 부적절한 EMA 매개 변수는 비효율적인 필터를 일으킬 수 있습니다.
  3. 부적절하게 설정된 세션에서 놓친 기회
  4. 이벤트로 인한 공백을 캡처할 수 없습니다

해결책:

  1. EMA 매개 변수를 최적화
  2. 거래 세션 최적화
  3. ATR를 기준으로 스톱 로스를 추가합니다.
  4. 사건들을 파악하고, 틈을 피하세요

5. 최적화 방향

  1. 거래 세션 최적화
  2. EMA 매개 변수를 최적화
  3. ATR 기반 스톱 손실을 추가합니다.
  4. 사건들을 파악하고, 틈을 피하세요
  5. 더 나은 필터를 위해 다른 지표와 결합
  6. 제품별 테스트 및 조정

6. 요약

이 전략은 미리 설정된 거래 세션 내에서, 을 가까이와 아래로 비교하고 EMA 필터를 사용하여 트렌드 신호를 식별합니다. 트렌드 다음 효과는 있지만 잘못된 신호의 위험도 있습니다. 매개 변수를 최적화하여 개선하고, 스톱 로스를 추가하고, 필터를 향상시킵니다. 백테스트에서 철저하게 평가하십시오.


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

//@version=5
strategy("Up vs Down Close Candles Strategy with EMA and Session Time Frames", shorttitle="UvD Strat EMA Session", overlay=true)

// User input to define the lookback period, EMA period, and session strings for time frames
int lookback = input(20, title="Lookback Period")
int emaPeriod = input(50, title="EMA Period")
string session1 = input("0900-1200", title="Time Frame 1 Session")
string session2 = input("1300-1600", title="Time Frame 2 Session")

// Calculate the EMA
float ema = ta.ema(close, emaPeriod)

// State variable to track the current signal
var string currentSignal = na

// Counting up-close and down-close candles within the lookback period
int upCloseCount = 0
int downCloseCount = 0

if barstate.isnew
    upCloseCount := 0
    downCloseCount := 0
    for i = 0 to lookback - 1
        if close[i] > close[i + 1]
            upCloseCount += 1
        else if close[i] < close[i + 1]
            downCloseCount += 1

// Define the long (buy) and short (sell) conditions with EMA filter and session time frame
bool inSession = time(timeframe.period, session1) or time(timeframe.period, session2)
bool longCondition = inSession and upCloseCount > downCloseCount and close > ema and currentSignal != "long"
bool shortCondition = inSession and downCloseCount > upCloseCount and close < ema and currentSignal != "short"

// Enter or exit the market based on conditions
if longCondition
    currentSignal := "long"
    strategy.entry("Buy", strategy.long)

if shortCondition
    currentSignal := "short"
    strategy.entry("Sell", strategy.short)

// Exit logic for long and short positions
if currentSignal == "long" and strategy.position_size <= 0
    strategy.close("Sell")

if currentSignal == "short" and strategy.position_size >= 0
    strategy.close("Buy")

plot(ema, color=color.blue, title="EMA")


더 많은