ATR 추세 추종 전략


생성 날짜: 2023-09-21 15:13:47 마지막으로 수정됨: 2023-09-21 15:13:47
복사: 0 클릭수: 770
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 평균 실제 파장 (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)