트리플 EMA 풀백 브레이크아웃 트레이딩 전략


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

이 전략은 트리플 EMA에 대한 가격의 회귀 성능을 관찰하여 트렌드 움직임을 판단하고 회귀가 끝나면 브레이크 거래를합니다. 이 전략은 트렌드 추적 유형의 전략으로 중장선 트렌드의 회귀 기회를 잡기 위해 고안되었습니다.

전략적 원칙:

  1. 빠른, 중간, 느린 세 개의 EMA를 설정하고, 전형적인 파라미트는 25, 100, 200 사이클이다.

  2. 가격이 상향 회귀가 가장 빠른 EMA에 도달하면 중장선 다단 거래로 판단하고, 하향 회귀가 가장 빠른 EMA에 도달하면 공허 거래로 판단한다.

  3. 상위 회귀의 끝에서 반전이 시작될 때, 가장 빠른 EMA를 돌파할 때 더 많이 한다. 하위 회귀의 끝에서 반전이 시작될 때, 가장 빠른 EMA를 넘어갈 때 공백한다.

  4. 색으로 표시된 매매장간을 시각적으로 직관적으로 표현한다.

  5. 고정된 스톱로스, 리스크 수익률을 설정하고, 리스크 관리를 한다.

이 전략의 장점:

  1. 회전 거래는 성공률이 높습니다.

  2. 3 EMA는 추세를 판단하고, 속임수를 피한다.

  3. 위험과 이익은 통제보다 더 높은 성과와 지속가능성을 향상시킵니다.

이 전략의 위험은:

  1. 너무 긴 회전 시간으로 최고의 입구 지점을 놓칠 수 있다.

  2. 다른 주기들에 맞추기 위해 EMA 파라미터를 최적화해야 합니다.

  3. 고정 스톱은 너무 메카니컬해서 합리적인 설정이 필요합니다.

요약하자면, 이 전략은 트리플 EMA 회전을 통해 돌파를 통해 중·장기 선의 추세를 추적한다. 위험 제어 메커니즘은 장기적으로 안정적인 수익을 얻는 데 도움이 되지만, 투자자는 여전히 변수 최적화 및 회전 판단에 주의를 기울여야 한다.

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

//@version=5
strategy(title="Pullback", overlay=true, initial_capital=1000, slippage=25)

averageData = input.source(close, title="Source")
target_stop_ratio = input.float(title="Ratio Risk/Reward", defval=2, group="Money Management")
security = input.float(50, title='min of pips (00001.00) for each position', group="Money Management")
risk = input.float(2, title="Risk per Trade %", group="Money Management")

riskt = risk / 100 + 1

ema1V = input.int(25, title="Rapide", group="Ema Period")
ema2V = input.int(100, title="Moyenne", group="Ema Period")
ema3V = input.int(200, title="Lente", group="Ema Period")

ema1 = ta.ema(averageData, ema1V)
ema2 = ta.ema(averageData, ema2V)
ema3 = ta.ema(averageData, ema3V)

useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
     group="Backtest Time Period")
backtestStartDate = input(timestamp("5 June 2022"), 
     title="Start Date", group="Backtest Time Period",
     tooltip="This start date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")
backtestEndDate = input(timestamp("5 July 2022"),
     title="End Date", group="Backtest Time Period",
     tooltip="This end date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")

inTradeWindow = true

float pricePullAboveEMA_maxClose = na
float pricePullBelowEMA_minClose = na

if ta.crossover(close, ema1)
    pricePullAboveEMA_maxClose := close
  
else
    pricePullAboveEMA_maxClose := pricePullAboveEMA_maxClose[1]

if close > pricePullAboveEMA_maxClose
    pricePullAboveEMA_maxClose := close

if ta.crossunder(close, ema1)
    pricePullBelowEMA_minClose := close
 
else
    pricePullBelowEMA_minClose := pricePullBelowEMA_minClose[1]

if close < pricePullBelowEMA_minClose
    pricePullBelowEMA_minClose := close

BuyZone = ema1 > ema2 and ema2 > ema3
SellZone = ema1 < ema2 and ema2 < ema3

longcondition = ta.crossover(close, ema1) and pricePullBelowEMA_minClose > ema3 and pricePullBelowEMA_minClose < ema1 
shortcondition = ta.crossunder(close , ema1) and pricePullAboveEMA_maxClose < ema3 and pricePullAboveEMA_maxClose > ema1

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

risk_long := risk_long[1]
risk_short := risk_short[1]

lotB = (strategy.equity*riskt-strategy.equity)/(close - ema2)
lotS = (strategy.equity*riskt-strategy.equity)/(ema2 - close)

if strategy.position_size == 0 and BuyZone and longcondition and inTradeWindow
    risk_long := (close - ema2) / close
    minp = close - ema2
    if minp > security
        strategy.entry("long", strategy.long, qty=lotB)
    
if strategy.position_size == 0 and SellZone and shortcondition and inTradeWindow
    risk_short := (ema2 - close) / close
    minp = ema2 - close
    if minp > security
        strategy.entry("short", strategy.short, qty=lotS)
    
if strategy.position_size > 0

    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", stop = stopLoss, limit = takeProfit)
    
if strategy.position_size < 0

    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", stop = stopLoss, limit = takeProfit)
    
plot(ema1, color=color.blue, linewidth=2, title="Ema Rapide")
plot(ema2, color=color.orange, linewidth=2, title="Ema Moyenne")
plot(ema3, color=color.white, linewidth=2, title="Ema Lente")
p_ep = plot(entry_price, color=color.new(color.white, 0), linewidth=2, style=plot.style_linebr, title='entry price')
p_sl = plot(stopLoss, color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr, title='stopLoss')
p_tp = plot(takeProfit, color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr, title='takeProfit')
fill(p_sl, p_ep, color.new(color.red, transp=85))
fill(p_tp, p_ep, color.new(color.green, transp=85))

bgcolor(BuyZone ? color.new(color.green, 95)  : na)
bgcolor(SellZone ? color.new(color.red, 95)  : na)