EMA 거래 전략

저자:차오장, 날짜: 2023-09-11 12:02:56
태그:

EMA 거래 전략

이 전략은 EMA 분석을 기반으로 거래되며 다음과 같은 규칙이 있습니다.

  • 전날의 종료가 EMA보다 높으면 긴 기간을 입력합니다.

  • 현재 촛불이 EMA 이하로 닫히면 긴 출구

이 전략의 장점:

  • 트렌드 방향을 결정하기 위해 EMA를 사용합니다.
  • 단순하고 명확한 규칙, 쉽게 실행
  • 최적화를 위한 사용자 정의 가능한 EMA 기간

잠재적인 문제:

  • 범위에 제한된 시장에서 잘못된 신호에 취약합니다.
  • 늦은 출입, 휘프사에서 잡힐 위험
  • 스톱 로즈가 없으니, 통제되지 않은 손실 위험이 있습니다
  • 거래 빈도나 포지션 크기의 규칙이 없습니다.

전반적으로, EMA 전략은 트렌딩 시장에서 더 잘 작동하지만 조심스럽게 사용해야합니다. 정지 및 필터를 추가하면 전략을 최적화하는 데 도움이 될 것입니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ericdwyang

//@version=5
strategy("EMA Strat", overlay=true, margin_long=100, margin_short=100)

// EMA Variables
emaInput = input(21, "Length")
ema = ta.ema(close, emaInput)

// Variable Declaration
p = 0

start = false

// Start Date
yearInput = input(2000, "Year")
if (time >= timestamp(2000,01,01,01,01))
    start := true


// Check first candle relative to EMA
if (close > ema and start == true)
    p += 1
    strategy.entry("Long", strategy.long, comment = "Entry")
    

// Candle close above EMA (p + 1, count reset to 0)
above = close[1] > ema[1]
if (above)
    p += 1



// Candle close below EMA (reset p to 0, count -1)
below = close < ema
if (below)
    p := 0
    strategy.close("Long", comment = "Flat")

// // Exit Position
// if (redCount == -2)
//     strategy.close("Long", comment = "Flat")
    
// goLong = p[1] == 0 and p == 1
// flatten = p == 0
    
// // Restablish long    
// if (goLong and start == true)
//     strategy.entry("Long", strategy.long, comment = "Entry")
    

plot(p)
plot(ema)

    

더 많은