EMA와 누적 거래량을 기반으로 한 롱 앤 숏 트레이딩 전략


생성 날짜: 2023-09-20 11:48:34 마지막으로 수정됨: 2023-09-20 11:48:34
복사: 0 클릭수: 793
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 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"   ) )