EMA 크로스오버 기반 트렌드 전략


생성 날짜: 2023-09-15 11:51:34 마지막으로 수정됨: 2023-09-15 11:51:34
복사: 0 클릭수: 767
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이 글은 EMA 평균선 교차를 이용한 거래 신호를 형성하는 트렌드 추적 전략에 대해 자세히 설명한다. 이 전략은 평균선 변수 조합을 최적화하여 전략의 안정성을 높인다.

1 전략

이 전략은 다음과 같은 핵심 규칙을 따르고 있습니다.

  1. 빠른 라인 EMA와 느린 라인 EMA를 설정하고, 빠른 라인 반응 가격 변화, 느린 라인 판단 경향;

  2. “이런 일이 벌어진다면, 우리는 더 많은 일을 할 수 있을 것이다.

  3. 가짜 신호를 줄이기 위해 EMA 파라미터 비율을 설정하고, 느린 선 주기 ≥ 빠른 선 3배;

  4. 선택적으로 여러 모드만 사용해서 역대 거래가 없도록 한다.

  5. 사용자 정의 피크 사이클을 통해 파라미터 최적화 테스트를 수행할 수 있다.

EMA 평균 변수를 조정하여 민감성을 유지하면서 안정성을 높이고 트렌드 거래 기회를 잠금 할 수 있습니다.

2 전략적 장점

이 전략의 가장 큰 장점은 규칙이 간단하고, 실행하기 쉽고, 시간이 제한된 거래자에게 적합하다는 것입니다.

또 다른 장점은 매개 변수 최적화를 통해 빈번하게 유효하지 않은 거래를 줄일 수 있다는 것입니다.

마지막으로, 여러 모드만 선택하여 역전 거래가 필요하지 않으며 주식 시장과 같은 품종에 적합합니다.

  1. 잠재적인 위험

그러나 이 전략에는 다음과 같은 문제점이 있습니다.

첫째, EMA 평균선 자체는 지연 문제로 인해 최적의 지점을 놓칠 수 있습니다.

두 번째, 변수 설정이 잘못되면 과도한 필터링으로 인해 누락이 발생할 수 있습니다.

마지막으로, 제동 제동 손실 메커니즘은 개선되고 최적화되어야 합니다.

네 가지 내용

이 문서에서는 EMA 평균선 교차를 기반으로 한 트렌드 거래 전략에 대해 자세히 소개한다. 이는 평균선 변수 조합을 조정하여 전략의 안정성을 향상시킨다. 이 전략은 사용하기 쉽고 규칙은 간단하고 명확하지만, 평균선 지연을 방지하는 문제도 주의해야 한다.

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

//@version=4
// 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gregoirejohnb
//
// Moving average crossover systems measure drift in the market. They are great strategies for time-limited people.
// So, why don't more people use them?
// 
// I think it's due to poor choice in choosing EMA lengths: Market Wizard Ed Seykota has a guideline for moving average crossovers: the slow line should be at least 3x the fast line.
// This removes a lot of the whipsaws inherent in moving average systems, which means greater profitability.
// His other piece of advice: long-only strategies are best in stock markets where there's a lot more upside potential.
//
// Using these simple rules, we can reduce a lot of the whipsaws and low profitability trades! This strategy was made so you can see for yourself before trading.
//
// === HOW TO USE THIS INDICATOR ===
// 1) Choose your market and timeframe.
// 2) Choose the length.
// 3) Choose the multiplier.
// 4) Choose if the strategy is long-only or bidirectional. 
//
// Don't overthink the above! We don't know the best answers, that's why this strategy exists! We're going to test and find out.
//  After you find a good combination, set up an alert system with the default Exponential Moving Average indicators provided by TradingView.
//
// === TIPS ===
// Increase the multiplier to reduce whipsaws (back and forth trades).
// Increase the length to take fewer trades, decrease the length to take more trades.
// Try a Long-Only strategy to see if that performs better.
//
strategy(title="EMA Crossover Strategy", shorttitle="EMA COS", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10, currency=currency.USD,commission_type=strategy.commission.percent,commission_value=0.1)

// === GENERAL INPUTS ===
//strategy start date
start_year = input(defval=2020, title="Backtest Start Year")

// === LOGIC ===
length = input(type=input.integer,defval=20,minval=1,title="Length")
ratio = input(type=input.integer,defval=3,title="Multiplier (3x length, 4x length, etc)",options=[3,4,5,6,7,8,9,10])
longOnly = input(type=input.bool,defval=false,title="Long Only")
fast = ema(hl2,length)
slow = ema(hl2,length * ratio)
plot(fast,linewidth=2,color=color.orange,title="Fast")
plot(slow,linewidth=2,color=color.blue,title="Slow")

longEntry = crossover(fast,slow)
shortEntry = crossunder(fast,slow)

plotshape(longEntry ? close : na,style=shape.triangleup,color=color.green,location=location.belowbar,size=size.small,title="Long Triangle")
plotshape(shortEntry and not longOnly ? close : na,style=shape.triangledown,color=color.red,location=location.abovebar,size=size.small,title="Short Triangle")
plotshape(shortEntry and longOnly ? close : na,style=shape.xcross,color=color.black,location=location.abovebar,size=size.small,title="Exit Sign")

// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() =>
    crossover(fast,slow) and 
       time > timestamp(start_year, 1, 1, 01, 01)
exitLong() =>
    longOnly and crossunder(fast,slow)
strategy.entry(id="Long", long=strategy.long, when=enterLong())
strategy.close(id="Long", when=exitLong())
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() =>
    not longOnly and crossunder(fast,slow) and 
       time > timestamp(start_year, 1, 1, 01, 01)
exitShort() =>
    false
strategy.entry(id="Short", long=strategy.short, when=enterShort())
strategy.close(id="Short", when=exitShort())