DEMA와 EMA 크로스오버를 ATR 변동성 단기 전략과 결합


생성 날짜: 2024-01-08 14:14:57 마지막으로 수정됨: 2024-01-08 14:14:57
복사: 1 클릭수: 756
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

DEMA와 EMA 크로스오버를 ATR 변동성 단기 전략과 결합

전략 개요

이 전략은 DEMA와 EMA의 단기 교차와 ATR 변동률 전략으로 불린다. 이 전략은 DEMA와 EMA의 교차 신호를 계산하여 ATR 변동률 지표와 결합하여 효율적인 단선 거래 전략을 달성한다. DEMA가 EMA를 통과하고 ATR 변동률이 상승하면 공백을; DEMA가 EMA를 다시 통과하면 평정한다.

2. 전략 원칙

  1. DEMA 지표를 계산한다. DEMA는 쌍 EMA 이동 평균으로, 일정한 주기 내의 쌍 EMA를 계산함으로써, 단기 시장 소음을 효과적으로 필터링하여 신호 정확도를 향상시킬 수 있다.

  2. EMA를 계산한다. EMA는 지수 이동 평균으로 가격 변화에 더 빠르게 반응할 수 있다.

  3. ATR의 변동률을 계산한다. ATR은 실제 변동의 폭을 나타내는 지표로, 시장의 변동성과 위험 수준을 반영한다. ATR이 상승하면 시장의 변동이 증가하여 짧은 라인 조정이 형성될 수 있다.

  4. DEMA가 EMA를 통과하고 ATR의 변동률이 설정된 변수보다 크면 주가가 하락하기 시작하고, 시장은 risk off, 이 때 공백을 다는 것을 나타냅니다.

  5. DEMA가 EMA를 다시 입었을 때, 이는 가격이 지지를 형성하고 상승세를 반발하기 시작하여 평준화되었다는 것을 나타냅니다.

세, 전략적 장점

  1. 이중 EMA와 결합된 EMA는 신호의 정확도를 효과적으로 향상시킬 수 있다.

  2. ATR 변동률 지표는 낮은 위험의 휘프사우 신호를 배제할 수 있다.

  3. 단기 운영, 짧은 라인 추적에 적합하며, 긴 시간 헤퍼링을 피할 수 있다.

  4. 거래 논리는 간단하고 명확하며, 이해하기 쉽고 실행이 가능합니다.

네, 전략적 위험

  1. ATR 파라미터를 잘못 설정하면 거래 기회를 놓칠 수 있습니다.

  2. 동시에 다공중 양쪽 신호에 주의를 기울여야 하며, 조작의 난이도가 크다.

  3. ffected by short-term market volatility.

해결 방법: 매개 변수 최적화 테스트, 매개 변수 조정; 거래 논리를 간소화하고 단방향 신호에만 집중; 적절히 느슨한 중지 범위.

다섯째, 전략적 최적화

  1. DEMA와 EMA의 변수를 최적화하여 최적의 변수 조합을 찾습니다.

  2. ATR의 주기적 변수를 최적화하여 최적의 시장 변동성을 측정하는 지표를 결정한다.

  3. BOLL 채널과 같은 다른 보조 지표를 추가하여 신호의 정확도를 향상시킵니다.

  4. 더 안정적인 수익을 위해 스톱로스 및 스톱스톱 규칙을 추가합니다.

VI. 결론

이 전략은 DEMA, EMA 크로스, ATR 변동률 지표를 통해 간단하고 효율적인 단기 거래 전략을 구축한다. 전략 거래 논리는 명확하고, 작동하기 쉽고, 고주파 단선 거래에 적응할 수 있다. 다음 단계는 매개 변수 최적화 및 규칙 최적화로 더 안정적인 초과 수익을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-12-08 00:00:00
end: 2024-01-07 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_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/
// © Qorbanjf

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Qorbanjf

//@version=4
strategy("Qorban: DEMA/EMA & VOL Short ONLY", shorttitle="DEMA/EMA & VOL SHORT", overlay=true)

// DEMA
length = input(10, minval=1, title="DEMA LENGTH")
src = input(close, title="Source")
e1 = ema(src, length)
e2 = ema(e1, length)
dema1 = 2 * e1 - e2
plot(dema1, "DEMA", color=color.yellow)

//EMA
len = input(25, minval=1, title="EMA Length")
srb = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
ema1 = ema(srb, len)
plot(ema1, title="EMA", color=color.blue, offset=offset)

// get ATR VALUE
atr = atr(14)

//ATRP (Average True Price in precentage)

// Inputs
atrTimeFrame = input("D", title="ATR Timeframe", type=input.resolution)
atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)
useMA = input(title = "Show Moving Average?", type = input.bool, defval = true)
maType = input(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")
maLength = input(defval = 20, title = "Moving Average Period", minval = 1)
slType = input(title="Stop Loss ATR / %", type=input.float, defval=5.0, step=0.1)
slMulti = input(title="SL Multiplier", type=input.float, defval=1.0, step=0.1)
minimumProfitPercent = input(title="Minimum profit %", type=input.float, defval=20.00)

// ATR Logic
// atrValue = atr(atrLookback)
// atrp = (atrValue/close)*100
// plot(atrp, color=color.white, linewidth=2, transp = 30)

atrValue = security(syminfo.tickerid, atrTimeFrame, atr(atrLookback))
atrp = (atrValue/close)*100

// Moving Average Logic
ma(maType, src, length) =>
    maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)
maFilter = security(syminfo.tickerid, atrTimeFrame, ma(maType, atrp, maLength))


// Determine percentage of open profit
var entry = 0.0
distanceProfit = low - entry
distanceProfitPercent = distanceProfit / entry

//Determin if we have a long entry signal OR a sell position signal
profitSignal = minimumProfitPercent == 0.0 or distanceProfitPercent >= minimumProfitPercent
shortSignal = crossunder(dema1, ema1) and atrp > maFilter and strategy.position_size == 0 and not na(atr)
exitSignal = profitSignal and strategy.position_size !=0 and  crossover(dema1, ema1)


// === INPUT BACKTEST RANGE ===
//FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
//FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
//FromYear  = input(defval = 2017, title = "From Year", minval = 2000)
//ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
//ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
//ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

//Invert trade direction & flipping 
//tradInvert = input(defval = false, title = "invert trade direction")
//MOM_MR = input(defval=1, title = "MOM = 1 / MR = -1", minval=-1, maxval=1)
//plots=input(false, title="Show plots?")

// Get stop loss (in pips AND percentage distance)
shortStop = highest(high, 4) - (atr * slMulti)
shortStopPercent = close - (close * slMulti)

// Save long stop & target prices (used for drawing data to the chart & deetermining profit)
var shortStopSaved = 0.0
var shortTargetSaved = 0.0
enterShort = false
if shortSignal
    shortStopSaved := slType ? shortStop : shortStopPercent
    enterShort:= true
    entry := close


// long conditions 
//enterLong = crossover(dema1, ema1) and atrp < maFilter
//exitSignal => crossunder(dema1, ema1)

//Enter trades when conditions are met
strategy.entry("short", strategy.short, when=enterShort, comment="SHORT")

//place exit orders (only executed after trades are active)
strategy.exit(id="Short exit",
 from_entry="short",
 limit=exitSignal ? close : na,
 stop=shortStopSaved,
 when=strategy.position_size > 0,
 comment="end short")
 

//short strategy
//goShort() => crossunder(dema1, ema1) and atrp > maFilter
//KillShort() => crossover(dema1, ema1) 
//strategy.entry("SHORT", strategy.short, when = goShort())
//strategy.close("COVER", when = KillShort())