동력 트렌드 추적 전략

저자:차오장, 날짜: 2023-11-07 16:49:49
태그:

img

전반적인 설명

이 전략은 이동 평균과 부피의 트렌드 분석을 기반으로 하고, 동력 지표를 설정하고, 트렌드를 추적하여 구매 및 판매 작업을 수행합니다.

전략 원칙

  1. 마감 가격의 EMA와 부피의 누적 EMA를 계산합니다.
  2. 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스
  3. 계속 상승할 때, 누적 EMA의 2배 이상의 닫는 교차, 긴 위치에 추가
  4. RSI 인디케이터를 설정합니다. RSI가 90을 넘으면 수익을 취하기 위해 1/3 포지션을 닫습니다.
  5. 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스
  6. 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스
  7. 엔트리 가격의 일정한 비율로 스톱 로스 라인을 설정
  8. 짧은 포지션의 수익은 긴 포지션과 동일합니다.

이점 분석

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

  1. 동향을 판단하기 위해 EMA를 사용하면 동향을 효과적으로 추적 할 수 있습니다.
  2. 실제 트렌드 변화를 판단하기 위해 부피의 누적 EMA를 사용
  3. 수익을 취하기 위한 모멘텀 추적 지표 RSI
  4. 스톱 로스로 좋은 리스크 제어
  5. 다른 시장 조건에 적응 할 수 있으며 매개 변수를 유연하게 조정 할 수 있습니다.

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. EMA가 뒤쳐지고 있고, 전환점을 놓칠 수도 있습니다.
  2. 부피는 항상 실제 추세를 반영하지 않을 수 있습니다.
  3. 일정한 비율의 스톱 손실은 너무 기계적일 수 있습니다.
  4. 너무 많은 매개 변수가 매개 변수를 조정하는 것을 어렵게 만듭니다.
  5. 높은 거래 빈도는 높은 거래 비용으로 이어집니다.

위험 해결 방법:

  1. 지연을 줄이기 위해 EMA 매개 변수를 최적화합니다.
  2. 부피 신호를 확인하기 위해 다른 표시기와 결합
  3. 시장 조건에 따라 스톱 로스 포인트를 최적화
  4. 매개 변수를 단순화하고, 주요 설정을 유지
  5. 스톱 로스 및 거래 빈도를 적절하게 느리게 합니다.

최적화 방향

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

  1. 최적의 조합을 찾기 위해 다른 EMA 매개 변수 설정을 테스트
  2. 입력에 대한 신호 강도 판단으로 부피 배수를 추가
  3. MACD, KD 및 다른 지표와 결합하여 진입을 확인합니다
  4. 특정 주식의 특성에 따라 스톱 로스 비율을 최적화합니다.
  5. 거래 비용을 줄이기 위해 거래 빈도를 최적화

요약

요약하자면, 이것은 이동 평균 시스템에 기반한 트렌드 추적 전략이다. 핵심 아이디어는 트렌드 방향을 결정하기 위해 EMA를 사용하여 VOLUME 모멘텀 지표로 진입을 확인하는 것입니다. 매개 변수 조정을 통해 지속적으로 최적화 될 수 있으며 추가 확인을 위해 다른 지표에 의해 지원 될 수 있습니다. 전반적으로 유연한 트렌드 추적 전략으로 숙련된 사용 후에 좋은 수익을 얻을 수 있습니다.


/*backtest
start: 2023-10-30 00:00:00
end: 2023-11-06 00:00:00
period: 5m
basePeriod: 1m
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=5, default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000)


emaLength= input(25, 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(true, 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)

cumValue = cumulPriceVolume / cumulVolume

emaVal=ema(close, emaLength)

emaCumValue1=ema(cumValue, emaLength)
emaCumValue2=ema(cumValue, emaLength*2)

emaCumValueHistory=ema(cumValue[emaLength], emaLength)


//vwapVal1=vwap(hlc3)

rsiVal=rsi(close,5)

plotEma=plot(emaVal, title="EMA", color=color.green,  transp=25)
//plot(vwapValue, title="Cumulate Volumne", color=color.orange,  linewidth=2, transp=25)
//plot(vwapVal1, title="vwapVal1", color=color.purple,  linewidth=1, transp=25)
plotCum=plot(emaCumValue1, title="emaVwapValue", color=color.purple,  linewidth=2, transp=35)
plot(emaCumValue2, title="emaVwapValue", color=color.yellow,  linewidth=3, transp=25)
fill(plotEma,plotCum, color=emaVal>emaCumValue1 ? color.lime : color.red, transp=35, title="ema and cum area")

plot(emaCumValueHistory, title="emaCumValueHistory", color=color.black,  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)

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

//re-entry
rentryCondition1=strategy.position_size>1 and emaVal > emaCumValue1 and emaCumValue1>emaCumValue2 and crossover(close, emaCumValue2) and close>open and  (tradeDirection=="LONG")
strategy.entry(id="LE",comment="LE RE", long=true, qty=qty1, when=rentryCondition1 )

rentryCondition2=strategy.position_size>1 and emaVal > emaCumValue1 and emaCumValue1>emaCumValueHistory and crossover(close, emaCumValueHistory) and close>open and  (tradeDirection=="LONG")
//strategy.entry(id="LE",comment="LE RE", long=true, qty=qty1, when=rentryCondition2 )    


//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+(1*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="PExit Points=>"+tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and  takePartialProfits == true and close>=takeProfit and crossunder(rsiVal,90) )

profitVal=    strategy.position_size>=1 ?  (strategy.position_avg_price * (1+(1*0.01) )) : ( close[1] * 2 )

//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="Exit Points=>"+tostring(close-strategy.position_avg_price, "###.##"), when=  crossunder(emaVal, emaCumValue1) 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=crossunder(emaVal, emaCumValue1) 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  crossover(rsiVal,15) )  //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<emaCumValue1 and close>emaCumValue1 and open>emaCumValue1 and close>open )   or (crossover(emaVal,emaCumValue1))  ) 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"   ) )
strategy.close(id="SE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and  crossover(emaVal, emaCumValue1)   and (tradeDirection=="SHORT"   ) )



더 많은