EMA 라인업에 기반한 전략을 따르는 경향

저자:차오장, 날짜: 2024-02-05 14:21:18
태그:

img

전반적인 설명

이 전략은 다른 기간의 3 개의 EMA 라인을 기반으로 합니다. 이 전략은 가격이 EMA 라인의 위에 있는지 여부에 따라 현재 트렌드 방향을 판단합니다. 단기 EMA 라인이 장기 EMA 라인의 위에 넘을 때 구매 신호가 생성됩니다. 단기 EMA 라인이 장기 EMA 라인의 아래에 넘을 때 판매 신호가 생성됩니다. 이 전략은 트렌드가 실행되는 것을 추적하고 트렌드가 역전될 때 시간에 따라 포지션을 닫습니다.

전략 논리

이 전략은 각각 10일, 20일 및 50일 3개의 EMA 라인을 사용합니다. 판단 규칙은 다음과 같습니다.

  1. 10일 EMA와 20일 EMA 모두 50일 EMA를 넘으면 상승 추세로 정의됩니다.

  2. 10일 EMA와 20일 EMA 모두 50일 EMA보다 낮으면 하향 추세로 정의됩니다.

  3. 단기 EMA 라인 (10일 및 20일) 이 장기 EMA 라인 (50일) 을 넘을 때 구매 신호가 생성됩니다.

  4. 단기 EMA 라인 (10일 및 20일) 이 장기 EMA 라인 (50일) 아래를 넘으면 판매 신호가 생성됩니다.

  5. 상승 추세에서 긴 포지션을 유지하고 하락 추세에서 짧은 포지션을 유지합니다.

  6. 트렌드가 역전될 때 현재 방향 지위를 닫습니다 (단기 EMA는 장기 EMA를 넘습니다).

이 전략은 적시에 포지션을 폐쇄하여 수익을 확보하고 긴 포지션과 짧은 포지션을 번갈아 수익을 얻습니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 규칙은 간단하고 명확하고 이해하기 쉽고 실행하기 쉽습니다.
  2. 트렌드를 결정하기 위해 EMA 라인을 사용하는 것은 단기 시장 변동의 간섭을 피합니다.
  3. 트렌드 러닝을 추적하기 위해 적시에 포지션을 닫으면 손실이 커지지 않습니다.
  4. 트렌드를 추적하여 높은 수익률을 가진 시장 방향을 예측할 필요가 없습니다.

위험 분석

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

  1. 범위에 묶인 시장에서 EMA 라인은 자주 교차할 수 있으며, 빈번한 개점 및 폐쇄로 인해 높은 거래 비용을 초래할 수 있습니다.

  2. EMA의 트렌드 결정은 가격 격차 이후 실패할 수 있고 좋은 진입 기회를 놓칠 수 있습니다.

위험을 최적화하려면 몇 가지 방법을 사용할 수 있습니다.

  1. 오픈 포지션 규칙은 EMA가 너무 많이 거래되는 것을 피하기 위해 가까이 있을 때 적절하게 완화될 수 있습니다.

  2. EMA 실패를 피하기 위해 다른 지표를 결합하여 경향을 결정합니다.

최적화 방향

전략은 다음 측면에서 최적화 될 수 있습니다:

  1. 매개 변수 최적화. 최적의 매개 변수를 찾기 위해 다른 EMA 기간 조합을 테스트합니다.

  2. 거래 비용 최적화. 불필요한 빈번한 거래를 줄이기 위해 오픈 포지션 규칙을 적절히 최적화하십시오.

  3. 스톱 로스 전략 최적화. 단일 손실을 제어하기 위해 합리적인 스톱 로스 수준을 설정;

  4. 다른 지표를 조합합니다. 최적의 입시 시기를 결정하는 데 도움이되는 MACD, KDJ 및 다른 지표를 사용하십시오.

요약

일반적으로, 이 전략은 매우 간단하고 실용적입니다. 그것은 적절한 스톱 로스 전략과 함께 트렌드 방향을 결정하기 위해 EMA를 사용하여 위험을 효과적으로 제어합니다. 또한 최적화를 위한 방이 있습니다. 매개 변수 최적화, 스톱 로스 전략 및 기타 지표를 결합함으로써 이 전략의 성능을 더욱 향상시킬 수 있습니다.


/*backtest
start: 2024-01-28 00:00:00
end: 2024-01-31 04:00:00
period: 45m
basePeriod: 5m
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/
// © mattehalen

//@version=4
//study("EMA 10,20 59",overlay=true)
strategy("EMA 10,20 59",overlay=true)
infoBox     = input(true, title="infoBox", type=input.bool)
infoBox2    = input(false, title="infoBox2", type=input.bool)
BuySellSignal_Bool = input(false, title="Buy & SellSignal", type=input.bool)
infoBoxSize = input(title="infoBoxSize", defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge])
ema1Value   = input(10)
ema2Value   = input(20)
ema3Value   = input(59)
maxLoss = input(3000)
ema1        = ema(close,ema1Value)
ema2        = ema(close,ema2Value)
ema3        = ema(close,ema3Value)
objcnt      = 0
buyTitle    = tostring(close[1])
myProfit    = float(0)

plot(ema1,title="ema1",color=color.red,linewidth=2)
plot(ema2,title="ema2",color=color.green,linewidth=2)
plot(ema3,title="ema3",color=color.black,linewidth=2)

Buytrend = (ema1 and ema2 > ema3) and (ema1[1] and ema2[1] > ema3[1])
BarssinceBuyTrend = barssince(Buytrend)
BarssinceSellTrend = barssince(not Buytrend)
closeAtBuyTrend = close[1]
bgcolor(Buytrend ? color.green : color.red,transp=70)

BuySignal = Buytrend and not Buytrend[1] and BuySellSignal_Bool

BuySignalOut = Buytrend and (crossunder(ema1,ema2)) and BuySellSignal_Bool
BarssinceBuy = barssince(BuySignal)
bgcolor(BuySignal ? color.green : na , transp=30)
bgcolor(BuySignalOut ? color.black : na , transp=30)
plot(BarssinceBuy,title="BarssinceBuy",display=display.none)


SellSignal = not Buytrend and Buytrend[1] and BuySellSignal_Bool
SellSignalOut = not Buytrend and (crossover(ema1,ema2)) and BuySellSignal_Bool
BarssinceSell = barssince(SellSignal)
bgcolor(SellSignal ? color.red : na , transp=30)
bgcolor(SellSignalOut ? color.black : na , transp=30)
plot(BarssinceSell,title="BarssinceSell",display=display.none)


buyProfit   = float(0)
cntBuy      =0
sellProfit  = float(0)
cntSell     =0
buyProfit   := Buytrend and not Buytrend[1]? nz(buyProfit[1]) + (close[BarssinceBuyTrend[1]]-close) : nz(buyProfit[1])
cntBuy      := Buytrend and not Buytrend[1]? nz(cntBuy[1]) + 1: nz(cntBuy[1])
sellProfit  := not Buytrend and Buytrend[1]? nz(sellProfit[1]) + (close-close[BarssinceSellTrend[1]]) : nz(sellProfit[1])
cntSell     := not Buytrend and Buytrend[1]? nz(cntSell[1]) + 1 : nz(cntSell[1])
totalProfit = buyProfit + sellProfit

// if (Buytrend and not Buytrend[1] and infoBox==true)
//     l = label.new(bar_index - (BarssinceBuyTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuyTrend[1]]) + "\n" + "Profit = "+tostring(close[BarssinceBuyTrend[1]]-close) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.red,size=infoBoxSize)
// if (not Buytrend and Buytrend[1] and infoBox==true)
//     l = label.new(bar_index - (BarssinceSellTrend[1]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSellTrend[1]]) + "\n" + "Profit = "+tostring(close-close[BarssinceSellTrend[1]]) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.green,size=infoBoxSize)

// if (BuySignalOut and not BuySignalOut[1] and infoBox2==true)
// //    l = label.new(bar_index - (BarssinceBuy[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.purple,size=infoBoxSize
//     l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceBuy[0]]) + "\n" + "Profit = "+tostring(close-close[BarssinceBuy[0]]) ,style=label.style_labelup, yloc=yloc.belowbar,color=color.lime,size=infoBoxSize)
// if (SellSignalOut and not SellSignalOut[1] and infoBox2==true)
// //    l = label.new(bar_index - (BarssinceSell[0]/2), na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.purple,size=infoBoxSize)
//     l = label.new(bar_index, na,text="Close = " + tostring(close) + "\n" + "Start = "+tostring(close[BarssinceSell[0]]) + "\n" + "Profit = "+tostring(close[BarssinceSell[0]]-close) ,style=label.style_labeldown, yloc=yloc.abovebar,color=color.fuchsia,size=infoBoxSize)


// l2 = label.new(bar_index, na, 'buyProfit in pip = '+tostring(buyProfit)+"\n"+  'cntBuy = '+tostring(cntBuy) +"\n"+  'sellProfit in pip = '+tostring(sellProfit)+"\n"+  'cntSell = '+tostring(cntSell) +"\n"+  'totalProfit in pip = '+tostring(totalProfit)     , 
//   color=totalProfit>0 ? color.green : color.red, 
//   textcolor=color.white,
//   style=label.style_labeldown, yloc=yloc.abovebar,
//   size=size.large)

// label.delete(l2[1])



//--------------------------------------------------
//--------------------------------------------------
if (Buytrend)
    strategy.close("short", comment = "Exit short")
    strategy.entry("long", true)
    strategy.exit("Max Loss", "long", loss = maxLoss)

//if BuySignalOut
   // strategy.close("long", comment = "Exit Long")
if (not Buytrend)
    // Enter trade and issue exit order on max loss.
    strategy.close("long", comment = "Exit Long")
    strategy.entry("short", false)
    strategy.exit("Max Loss", "short", loss = maxLoss)
//if SellSignalOut
    // Force trade exit.
    //strategy.close("short", comment = "Exit short")
    
//--------------------------------------------------
//--------------------------------------------------
//--------------------------------------------------



더 많은