EMA 골든 크로스 풀백 전략


생성 날짜: 2023-12-21 11:48:54 마지막으로 수정됨: 2023-12-21 11:48:54
복사: 2 클릭수: 877
avatar of ChaoZhang ChaoZhang
1
집중하다
1623
수행원

EMA 골든 크로스 풀백 전략

개요

EMA 골드 크로스 리워드 전략은 EMA 지표에 기반한 정량 거래 전략이다. 이 전략은 세 개의 다른 주기의 EMA 곡선을 사용하여 거래 신호를 구성하고, 가격 리워드 메커니즘과 결합하여 스톱 로즈 스톱을 설정하여 자동화 거래를 구현한다.

전략 원칙

이 전략은 세 개의 EMA 곡선을 사용합니다.

  • EMA1: 가격 재조정 지지/저항 지점을 판단하기 위해 쓰이며, 주기가 짧으며, 기본적으로 33주기 .
  • EMA2: 부분 반전 신호를 필터링하기 위해 사용되며, 주기율은 EMA1의 5배이며, 165주기를 기본으로 한다.
  • EMA3: 전반적인 트렌드 방향을 판단하는 데 사용되며, 주기는 EMA1의 11배이며, 365주기를 기본으로 한다.

거래 신호는 다음과 같은 논리에 따라 생성됩니다.

다단계 신호: 가격이 EMA1을 구성한 후 회전이 발생하고, EMA1 위에 더 높은 낮은 점이 형성되며, 회전이 EMA2에 닿지 않습니다. 조건을 충족 한 후, EMA1을 다시 착용 할 때 더 많이합니다.

공백 신호: 가격이 EMA1을 넘은 후 회전이 발생하고, EMA1 아래에서 더 낮은 고점이 형성되며, 회전의 크기는 EMA2을 만지지 않습니다. 조건을 충족 한 후, 다시 EMA1을 넘을 때 공백을 만듭니다.

스톱로스는 최저 가격/최고 가격을 재조정한다. 스톱은 스톱로스의 2배로 설정한다.

전략적 이점

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. EMA 지표를 사용하여 거래 신호를 구성하는 것은 신뢰성이 높습니다.
  2. 가격 회귀 메커니즘과 함께, 을 효과적으로 피할 수 있다.
  3. 정지점은 이전 고/저 수준으로 설정되어 있고, 위험을 효과적으로 제어한다.
  4. 스톱 스톱 손실 비율에 따라 스톱 포인트를 설정하여 이익-손실 비율 요구 사항을 충족하십시오.
  5. 시장에 따라 EMA 매개 변수를 조정할 수 있으며, 다른 주기들에 적응한다.

전략적 위험

이 전략에는 위험도 있습니다.

  1. EMA 지표는 추세 전환점을 놓칠 수 있습니다.
  2. 회귀 범위가 EMA2를 초과하면 false signals를 생성할 수 있다.
  3. 동향상태의 정지 손실이 돌파될 수 있다.
  4. 잘못된 매개 변수 설정으로 인해 너무 자주 거래되거나 기회를 놓치게 될 수 있습니다.

EMA 주기를 조정하거나, 회귀 제한 범위를 조정하는 등의 방법으로 파라미터를 최적화할 수 있다. 또한 다른 지표 필터링 신호와 결합할 수 있다.

전략 최적화 방향

이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.

  1. 트렌드 지표 판단을 높이고 역전 거래를 피한다. 예를 들어 MACD에 가입한다.
  2. 거래량 지표를 추가하여 가짜 돌파구를 피하십시오. 예를 들어 OBV에 가입하십시오.
  3. EMA 주기 파라미터를 최적화하거나, 적응 EMA를 채택한다.
  4. 워드백 모델과 같은 기계 학습 방법과 결합된 동적으로 최적화되는 파라미터들.
  5. 모델 예측에 참여하고, 적응식 스톱 손실을 설정한다.

요약하다

EMA 골드 크로스 리워드 전략은 3개의 EMA 거래 시스템을 구축하여 가격 리워드 특성을 결합하여 스톱 스톱을 설정하여 자동화 거래를 구현한다. 이 전략은 거래 위험을 효과적으로 제어하며, 시장에 따라 파라미터를 조정하여 최적화 할 수 있다.

전략 소스 코드
/*backtest
start: 2023-11-20 00:00:00
end: 2023-12-20 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/
// created by Space Jellyfish
//@version=4

strategy("EMA pullback strategy", overlay = true, initial_capital=10000, commission_value = 0.075)

target_stop_ratio = input(title="Take Profit Stop Loss ratio", type=input.float, defval=2.06, minval=0.5, maxval=100)
riskLimit_low =  input(title="lowest risk per trade", type=input.float, defval=0.008, minval=0, maxval=100)
riskLimit_high =  input(title="highest risk per trade", type=input.float, defval=0.02, minval=0, maxval=100)
//give up the trade, if the risk is smaller than limit, adjust position size if risk is bigger than limit

ema_pullbackLevel_period = input(title="EMA1 for pullback level Period", type=input.integer, defval=33, minval=1, maxval=10000)
ema_pullbackLimiit_period = input(title="EMA2 for pullback limit Period", type=input.integer, defval=165, minval=1, maxval=10000)
ema_trend_period = input(title="EMA3 for trend Period", type=input.integer, defval=365, minval=1, maxval=10000)

startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer, defval=2018, minval=2008, maxval=2200)

inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))

ema_pullbackLevel = ema(close, ema_pullbackLevel_period)
ema_pullbackLimit = ema(close, ema_pullbackLimiit_period)
ema_trendDirection = ema(close, ema_trend_period)

//ema pullback 
float pricePullAboveEMA_maxClose = na
float pricePullAboveEMA_maxHigh = na

float pricePullBelowEMA_minClose = na
float pricePullBelowMA_minLow = na

if(crossover(close, ema_pullbackLevel))
    pricePullAboveEMA_maxClose := close
    pricePullAboveEMA_maxHigh := high
else
    pricePullAboveEMA_maxClose := pricePullAboveEMA_maxClose[1]
    pricePullAboveEMA_maxHigh := pricePullAboveEMA_maxHigh[1]

if(close > pricePullAboveEMA_maxClose)
    pricePullAboveEMA_maxClose := close
if(high > pricePullAboveEMA_maxHigh)
    pricePullAboveEMA_maxHigh := high

if(crossunder(close, ema_pullbackLevel))
    pricePullBelowEMA_minClose := close
    pricePullBelowMA_minLow := low
else
    pricePullBelowEMA_minClose :=pricePullBelowEMA_minClose[1]
    pricePullBelowMA_minLow:=pricePullBelowMA_minLow[1]
    
if(close < pricePullBelowEMA_minClose)
    pricePullBelowEMA_minClose := close
if(low < pricePullBelowMA_minLow)
    pricePullBelowMA_minLow := low


long_strategy = crossover(close, ema_pullbackLevel) and pricePullBelowEMA_minClose < ema_pullbackLimit and ema_pullbackLevel>ema_trendDirection 
short_strategy = crossunder(close, ema_pullbackLevel) and pricePullAboveEMA_maxClose > ema_pullbackLimit and ema_pullbackLevel<ema_trendDirection


var open_long_or_short = 0// long = 10000, short = -10000, no open = 0

//check if position is closed
if(strategy.position_size == 0)
    open_long_or_short := 0
else
    open_long_or_short := open_long_or_short[1]

float risk_long = na
float risk_short = na
float stopLoss = na
float takeProfit = na
float entry_price = na

float entryContracts = 0



risk_long := risk_long[1]
risk_short := risk_short[1]
    
//open a position determine the position size
if (strategy.position_size == 0 and long_strategy and inDateRange)
    risk_long := (close - pricePullBelowMA_minLow) / close

    if(risk_long < riskLimit_high)
        entryContracts := strategy.equity / close
    else
        entryContracts := (strategy.equity * riskLimit_high / risk_long)/close
    
    if(risk_long > riskLimit_low)
        strategy.entry("long", strategy.long, qty = entryContracts, when = long_strategy)


    open_long_or_short := 10000
    
if (strategy.position_size == 0 and short_strategy and inDateRange)
    risk_short := (pricePullAboveEMA_maxHigh - close) / close
    if(risk_short < riskLimit_high)
        entryContracts := strategy.equity / close
    else
        entryContracts := (strategy.equity * riskLimit_high / risk_short)/close

    if(risk_short > riskLimit_low)
        strategy.entry("short", strategy.short, qty = entryContracts, when = short_strategy)

    
    open_long_or_short := -10000

//take profit / stop loss
if(open_long_or_short == 10000)

    stopLoss :=   strategy.position_avg_price*(1 - risk_long)
    takeProfit :=  strategy.position_avg_price*(1 + target_stop_ratio * risk_long)
    entry_price := strategy.position_avg_price
    strategy.exit("Long exit","long", limit = takeProfit , stop = stopLoss)
    
if(open_long_or_short == -10000)
    stopLoss :=  strategy.position_avg_price*(1 + risk_short)
    takeProfit :=  strategy.position_avg_price*(1 - target_stop_ratio * risk_short)
    entry_price := strategy.position_avg_price
    strategy.exit("Short exit","short", limit = takeProfit, stop = stopLoss)



plot(ema_pullbackLevel, color=color.aqua,  title="ema pullback level")
plot(ema_pullbackLimit, color=color.purple,  title="ema pullback limit")
plot(ema_trendDirection, color=color.white,  title="ema trend")

plot(entry_price, color = color.yellow, linewidth = 1, style = plot.style_linebr)
plot(stopLoss, color = color.red, linewidth = 1, style = plot.style_linebr)
plot(takeProfit, color = color.green, linewidth = 1, style = plot.style_linebr)





//