EMA 크로스오버에 기반한 전략을 따르는 경향

저자:차오장, 날짜: 2023-09-15 11:51:34
태그:

이 문서에서는 EMA 크로스오버를 사용하여 거래 신호를 생성하는 트렌드 다음 전략을 자세히 설명합니다. 이동 평균 매개 변수를 최적화함으로써 전략 안정성을 향상시키는 것을 목표로합니다.

I. 전략 논리

핵심 규칙은 다음과 같습니다.

  1. 빠른 EMA와 느린 EMA를 설정하고, 가격 변화 감수성을 위한 빠른 EMA와 트렌드를 위한 느린 EMA를 설정합니다.

  2. 느린 EMA 위의 빠른 EMA 크로스오버에서 장가가 되고 그 아래의 크로스오버에서 단가가 됩니다.

  3. 거짓 신호를 줄이기 위해 느린 기간 ≥ 3배 빠른 기간의 EMA 비율을 설정합니다.

  4. 오프션으로 단장 모드를 선택하여 역동 트렌드 거래를 피합니다.

  5. 매개 변수 최적화를 위한 사용자 정의 가능한 백테스트 기간

EMA 매개 변수를 조정함으로써, 감수성과 안정성은 트렌드를 활용하기 위해 균형을 잡을 수 있습니다.

II. 전략의 장점

가장 큰 장점은 시간적 제약이 있는 거래자에게 적합한 사용 편의성을 위한 단순성입니다.

또 다른 장점은 매개 변수 최적화를 통해 윙사브를 줄일 수 있다는 것입니다.

마지막으로, 장기만 모드는 트렌드 반대 거래를 피하고 주식과 같은 특정 시장에 적합합니다.

III. 잠재적인 약점

그러나 몇 가지 문제가 있습니다.

첫째로, EMA는 본질적으로 미흡한 이슈를 가지고 있으며, 최적의 항목을 놓치게 됩니다.

둘째, 부적절한 설정이 지나치게 필터링을 하게 되면 트레이드를 놓칠 수 있습니다.

마지막으로, 손해를 멈추고 이익을 취하는 메커니즘은 개선이 필요합니다.

IV. 요약

요약적으로,이 기사는 EMA 크로스오버에 기반한 트렌드 다음 전략을 설명했습니다. 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())

더 많은