전략에 따른 ATR 트렌드

저자:차오장, 날짜: 2023-09-21 15:13:47
태그:

전반적인 설명

이 전략은 가격 트렌드를 파악하기 위해 평균 진정한 범위 (ATR) 를 사용하며 트렌드를 따르는 ATR을 기반으로 정지점을 설정합니다.

어떻게 작동 합니까?

  1. ATR 값을 계산합니다.

  2. ATR을 기반으로 스톱 손실 수준을 결정합니다.

  3. 가격 경류 정지 수준에 따라 긴 / 짧은 입력합니다.

  4. 역동적으로 정지를 조정하여 수익을 차단합니다.

장점

  • ATR는 자동으로 정지 조정, 수동 개입 필요 없습니다
  • 단순하고 직관적인 논리, 쉽게 구현
  • 함락되는 것을 피하는 데 도움이 됩니다.
  • 라이딩 트렌드에서 얻은 이익
  • ATR 매개 변수를 통해 제어되는 거래 빈도

위험성

  • 열악한 ATR 매개 변수는 너무 느슨하거나 단단한 정지 원인이 될 수 있습니다
  • 트렌드 끝을 효과적으로 식별 할 수 없습니다.
  • 어떤 시간 차이는 존재합니다.
  • 역행으로 수익이 줄어들 수 있습니다.

최적화 방향

  • ATR 기간 매개 변수를 최적화
  • 정지 거리를 위한 다른 ATR 배수를 테스트
  • 트렌드 반전을 감지하는 필터를 추가합니다.
  • 매개 변수 최적화를 위해 기계 학습을 탐구
  • 이윤 취득의 추가 메커니즘을 고려하십시오.

결론

이 전략은 ATR을 사용하여 트렌드를 효과적으로 잡으며 동적 스톱으로 수익을 잠금합니다. 미세 조정 매개 변수는 성능을 향상시킬 수 있습니다. 그러나 ATR 지연은 완전히 제거 할 수 없습니다. 전반적으로 간단하고 실용적인 트렌드 다음 솔루션입니다.


/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

strategy(title="ATR Strategy", overlay = true,  commission_type=strategy.commission.percent,commission_value=0.075)
//credits to HPotter for the orginal code
nATRPeriod = input(5)
nATRMultip = input(3.5)
xATR = ta.atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), math.max(nz(xATRTrailingStop[1]), close - nLoss),
                    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), math.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))) 
color = pos == -1 ? color.red: pos == 1 ? color.green : color.blue 
plot(xATRTrailingStop, color=color, title="ATR Trailing Stop")

barbuy = close > xATRTrailingStop 
barsell = close < xATRTrailingStop 

strategy.entry("Long", strategy.long, when = barbuy) 
strategy.entry("Short", strategy.short, when = barsell) 

barcolor(barbuy? color.green:color.red)



더 많은