EMA와 누적용량 크로스오버 전략

저자:차오장, 날짜: 2023-09-20 11:48:34
태그:

전반적인 설명

이 전략은 EMA와 누적 부피 지표를 결합하여 트렌드를 결정하기 위해 크로스오버 상황에 따라 구매 및 판매 신호를 생성합니다. 그것은 더 긴 시간 프레임 시장 방향을 추적하는 전형적인 트렌드 다음 전략에 속합니다.

전략 논리

50일 EMA와 100일 누적 볼륨 지표가 계산된다. EMA가 아래로부터 누적 볼륨을 넘을 때, 사기 신호가 생성된다. EMA가 위로부터 누적 볼륨을 넘을 때, 사기 신호가 생성된다.

포지션 동안 고정 스톱 로스 및 영업 전략이 구현됩니다. 스톱 로스는 엔트리 가격보다 8% 낮게 설정됩니다. 영업 수익은 엔트리 가격보다 8% 높게 설정되며, 가격이 영업 수익 수준에 도달하면 부분적인 포지션 종료가 발생합니다.

이점 분석

이 전략은 트렌드 지표 EMA와 기금 흐름 지표 누적 부피를 결합하여 중장기 동향을 효과적으로 식별하기 위해 가격 및 부피 정보를 활용합니다. 고정 수익 취득 및 스톱 손실은 효율적이며 위험을 제어하면서 부분 수익을 차단하는 데 도움이됩니다.

EMA 기간은 다양한 상품에 대해 자유롭게 조정할 수 있습니다. 긴 거래와 짧은 거래 모두 선형 거래에 구현됩니다. 백테스트는 트렌드 기간 동안 좋은 성능을 보여줍니다.

위험 분석

이동 평균에 대한 과도한 의존은 범위 제한 통합 중 윙사브로 이어질 수 있습니다. 고정 수익 취득 및 스톱 손실은 또한 조기 출구 또는 과대화 스톱 아웃으로 이어질 수 있습니다. 다른 요소 없이 가격 및 볼륨 요소만 고려됩니다.

이동 평균 기간을 확장하면 잘못된 신호를 줄일 수 있습니다. 변동성, RSI와 같은 추가 지표도 판단에 도움이 될 수 있습니다. 트레일 스톱, 동적 출구 등을 통해 수익 취지와 스톱 손실 메커니즘을 최적화하는 것이 유용 할 수 있습니다.

최적화 방향

  1. 최적의 설정을 찾기 위해 EMA 매개 변수 조합을 테스트하고 최적화합니다.

  2. 다른 기술적 지표를 통합하여 앙상블 시스템을 형성합니다.

  3. 머신러닝을 적용하여 트렌드를 예측하고 EMA 성능을 향상시킵니다.

  4. 트레일 스톱, 동적 출구 등을 결합하여 수익을 취하고 손실을 멈추는 전략을 최적화하십시오.

  5. 역동적인 포지션 크기를 위한 자본 관리 모듈을 도입합니다.

  6. 제품 특성에 기반한 매개 변수를 사용자 정의하여 전략 집합을 형성합니다.

요약

트렌드 식별을 위해 EMA와 볼륨을 결합하는 전략의 아이디어는 분명합니다. 그러나 이동 평균과 고정 출구에 대한 과도한 의존은 결함이 있습니다. 더 많은 판단 지표를 추가하고 출구를 최적화하면 안정성을 향상시킬 수 있습니다. 전반적으로 트렌드 추적을 위해 가격 및 볼륨 데이터를 사용하는 아이디어를 제공합니다.


/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 2h
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/
// © mohanee

//@version=4
strategy("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000)


emaLength= input(50, title="EMA Length", minval=1, maxval=200)
cumulativePeriod = input(100,  title="cumulative volume Period", minval=1, maxval=200)


riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(8,title="Stop Loss",minval=1)
takePartialProfits=input(false, title="take partial profits  (percentage same as stop loss)")

tradeDirection=input(title="Trade Direction", defval="LONG", options=["LONG", "SHORT"])

avgPrice = (high + low + close) / 3
avgPriceVolume = avgPrice * volume

cumulPriceVolume = sum(avgPriceVolume, cumulativePeriod)
cumulVolume = sum(volume, cumulativePeriod)

vwapValue = cumulPriceVolume / cumulVolume

emaVal=ema(close, emaLength)

plot(emaVal, title="EMA", color=color.green,  transp=25)
plot(vwapValue, title="Cumulate Volumne / VWAP", color=color.orange,  linewidth=2, transp=25)

bgcolor(emaVal>vwapValue?color.blue:color.purple)    

//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1

strategy.entry(id="LE",comment="LE", long=true, qty=qty1, when=crossover(emaVal, vwapValue)  and (tradeDirection=="LONG") )    //emaVal>vwapValue and crossover(close , emaVal)

//stoploss
stopLossVal=  strategy.position_size>=1 ?  (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00

//draw initil stop loss
plot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr,  linewidth = 2, title = "stop loss")

//partial exits
takeProfit=  strategy.position_size>=1 ?  (strategy.position_avg_price * (1+(stopLoss*0.01) )) : ( close[1] * 2 )
if(takePartialProfits==true)
    strategy.close(id="LE", comment="Partial"+tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and crossunder(close, emaVal) )    //close<close[1] and close[1]<close[2] and close[2]<close[3])
    
strategy.close(id="LE" , comment="LE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )

strategy.close(id="LE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal   and (tradeDirection=="LONG") )


//for short  you dont have to wait crossodown of ema, falling is speed , so just check if close crossing down vwapVal
strategy.entry(id="SE",comment="SE", long=false, qty=qty1, when=(close<vwapValue and close<open  and close[1] < vwapValue  and close[1]<open[1] and close<close[1])  and emaVal>=vwapValue and (tradeDirection=="SHORT") )    //emaVal>vwapValue and crossover(close , emaVal)

//stoploss
stopLossValUpside=  abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ?  (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00

//draw initil stop loss
plot(abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? stopLossValUpside : na, color = color.purple , style=plot.style_linebr,  linewidth = 2, title = "stop loss")

//partial exits
shortTakeProfit=  abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ?  (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00
if(takePartialProfits==true)
    strategy.close(id="SE", comment="Partial" , qty=strategy.position_size/3 , when = (tradeDirection=="SHORT"   ) and  close<shortTakeProfit )  //close<takeProfit and (emaVal - close)>8 )
  
//strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossover(emaVal, vwapValue) and (tradeDirection=="SHORT") )
strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open )   or (crossover(emaVal,vwapValue))  ) and (tradeDirection=="SHORT") )

strategy.close(id="SE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and  close > stopLossValUpside   and (tradeDirection=="SHORT"   ) )




더 많은