VWMA와 ATR 트렌드 다음 전략

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

img

전반적인 설명

이 전략은 트렌드 방향을 결정하기 위해 VWMA를 사용하며 트렌드를 따라 ATR로 스톱 로스를 설정합니다. 명백한 트렌드가있는 시장에 적합합니다.

전략 논리

  1. 트렌드 방향을 결정하기 위해 VWMA를 사용하십시오. 가격이 VWMA보다 높을 때 길게, 가격이 VWMA보다 낮을 때 짧게 이동하십시오.

  2. 거짓 브레이크아웃 신호를 피하기 위해 RSI 오시레이터 필터를 추가합니다. RSI가 30 이상일 때만 긴 신호를 취합니다.

  3. 스톱 손실 라인을 계산하기 위해 ATR를 사용하십시오. ATR 길이는 VWMA와 동일하게 설정되어 있으며, 곱자는 3.5입니다. 실시간으로 스톱 손실 라인 업데이트.

  4. ATR 곱셈은 스톱 손실 라인의 밀도를 제어합니다. 더 큰 곱셈은 트렌드를 따르는 데 더 나은 빈도 업데이트를 의미합니다.

  5. 포지션 크기는 계정 자금과 스톱 로스 비율을 기준으로 계산됩니다.

  6. 가격이 스톱 로스 라인을 넘어갈 때 긴 포지션을 종료합니다.

장점

  1. 트렌드를 결정하기 위해 VWMA를 사용하는 것은 트렌드 기회를 지속적으로 잡습니다.

  2. RSI 필터는 잘못된 신호를 피합니다.

  3. ATR 후속 정류는 추세를 따르고 반전으로 정지되는 것을 피합니다.

  4. 계정 자금과 스톱 로스를 기반으로 하는 포지션 사이징은 리스크 관리에 유리합니다.

위험성

  1. 트렌드 전환점에서의 잠재적 손실은 손실을 제한하기 위해 포지션 크기를 줄여야 합니다.

  2. 부적절한 ATR 매개 변수 설정은 너무 긴 또는 느슨한 스톱 손실 라인을 초래합니다. 매개 변수를 테스트해야합니다.

  3. 급속한 트렌드 역전으로 인해 스톱 로스 업데이트가 지연되어 손실이 증가할 수 있습니다.

  4. 낮은 변동성 환경에서는 포지션 크기를 줄이고 스톱 로스 업데이트 빈도를 높여야 합니다.

강화

  1. 다양한 VWMA 매개 변수 조합을 테스트하여 최적의 신호 매개 변수를 찾습니다.

  2. 과잉 구매/ 과잉 판매 라인 등의 다른 RSI 설정을 테스트합니다.

  3. ATR 곱셈을 테스트하여 적출량과 추적 능력 사이의 최적의 균형을 찾으십시오.

  4. 신호 품질을 향상시키기 위해 MACD, KD와 같은 다른 필터를 추가합니다.

  5. 시장의 변동성에 따라 포지션 크기와 스톱 로스 비율을 최적화합니다.

요약

이 전략은 전반적인 트렌드 추종 편향을 가지고 있으며 명백한 가격 추세를 잘 잡습니다. 트렌드 결정, 신호 필터링, 스톱 로스 트레일링 등에서 장점이 있습니다. 또한 트렌드 역전에서 위험이 있습니다. 미세한 조정 매개 변수 및 포지션 사이징은 더 나은 성과를 가져올 수 있습니다.


/*backtest
start: 2023-10-07 00:00:00
end: 2023-10-13 00:00:00
period: 1h
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("", overlay=true)
strategy(title="VWMA_withATRstops_strategy V2", overlay=true, pyramiding=1,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,

float xATRTrailingStop=na
int pos=na

vwmalength = input(33, title="VWMA Length", minval=1, maxval=365)
//vwmalength2 = input(9, title="VWAM Short Term Length", minval=1, maxval=365)
nATRPeriod = input(33, title="ATR length", minval=1, maxval=365)
nATRMultip = input(3.5, title="ATR Multiplier")

rsiofVwmaLength=input(14, title="RSI of VWMA Length")

riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(5,title="Stop Loss",minval=1)

vwmaVal=vwma(close, vwmalength)
//vwmaVal2=vwma(close, vwmalength2)
//maVal=sma(close, vwmalength)

plot(vwmaVal, color=color.orange, linewidth=2,  title="VWMA")
//plot(vwmaVal2, color=color.blue, title="VWMA Short Term")
//plot(maVal, color=color.blue, title="MA")

//rsi of vwma Longterm
rsiofVwmaVal=rsi(vwmaVal,rsiofVwmaLength)

xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR

xATRTrailingStop:= iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))

pos:=	iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, 	    iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 

color1 = pos == -1 ? color.red: pos == 1 ? color.green : color.blue 

//plot(xATRTrailingStop, color=color1, title="ATR Trailing Stop")

//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


//Long Entry
//strategy.entry(id="VWMA LE", long=true, qty=qty1, when= close >vwmaVal and open>vwmaVal and close>open and close > xATRTrailingStop and xATRTrailingStop>  vwmaVal)

strategy.entry(id="VWMA LE", long=true, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    
//vwmaVal2>vwmaVal and

plot(strategy.position_size>=1  ? xATRTrailingStop : na, color=color1, style=plot.style_linebr, title="ATR Trailing Stop")
bgcolor(strategy.position_size>=1 ? color.blue : na )

//Exit
strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and crossunder(close, xATRTrailingStop)  )
//strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and close<vwmaVal and open<vwmaVal and close<open )

더 많은