역전 트렌드 포착 및 동적 스톱 손실 컴보 전략

저자:차오장, 날짜: 2024-02-05 09:54:13
태그:

img

전반적인 설명

이 전략은 역행 트렌드 포착 전략과 동적 스톱 로스 전략을 결합하여 역행 트렌드를 포착하고 동적 스톱으로 위험을 제어합니다.

전략 논리

역전 추세 포착 전략

이 전략은 스토카스틱 오시레이터의 K와 D 값을 기반으로 합니다. 이 전략은 가격이 2일 연속 하락하고 K가 D보다 상승할 때 구매 신호를 생성합니다. 이 전략은 가격이 2일 동안 상승하고 K가 D보다 하락할 때 판매 신호를 생성합니다. 이것은 가격 반전 추세를 잡습니다.

동적 스톱 로스 전략

이 전략은 가격 변동성 및 치우치에 따라 동적 스톱 손실을 설정합니다. 최근 가장 높은 최고 및 최저 낮은 변동을 계산하고 치우치에 따라 상위 또는 하향 채널에 있는지 판단하고 그에 따라 동적 스톱 가격을 설정합니다. 이것은 시장 상태에 따라 스톱 위치를 조정합니다.

이 두 가지 전략은 환전 신호를 감지하고 위험을 통제하기 위해 동적 중지 장치를 설정하기 위해 함께 작동합니다.

이점 분석

  • 포획 가격 반전 지점, 반전 거래에 적합합니다
  • 동적 정지는 시장 환경에 맞게 조정됩니다.
  • 이중 신호 확인은 잘못된 신호를 피합니다.
  • 리스크를 통제하고 수익을 보장

위험 분석

  • 역전 실패 위험 역전 신호가 실패할 수 있습니다.
  • 파라미터 위험, 잘못된 파라미터가 성능에 영향을 줄 수 있습니다.
  • 유동성 위험 일부 상품은 손실을 막기 위해 유동성이 부족합니다.

위험은 매개 변수 최적화, 엄격한 스톱 로스, 유동성이 좋은 상품을 선택함으로써 통제될 수 있습니다.

최적화 방향

  • 최적의 조합을 위해 스토카스틱 매개 변수를 최적화
  • 최고의 정지 위치를 위해 정지 매개 변수를 최적화
  • 범주 시장에 개방을 피하기 위해 필터를 추가
  • 최대 손실을 제한하기 위해 위치 크기를 추가

포괄적 인 최적화는 위험을 제어하는 동시에 역전을 포착 할 수 있도록합니다.

요약

이 전략은 안정적인 단기 거래를 위해 역동 트렌드 포착과 동적 스톱을 결합합니다. 지속적인 최적화와 모니터링으로 안정적인 수익을 얻을 수 있습니다.


/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 07/12/2020
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
//  The Kase Dev Stops system finds the optimal statistical balance between letting profits run, 
//  while cutting losses.  Kase DevStop seeks an ideal stop level by accounting for volatility (risk),
//  the variance in volatility (the change in volatility from bar to bar), and volatility skew 
//  (the propensity for volatility to occasionally spike incorrectly).
//  Kase Dev Stops are set at points at which there is an increasing probability of reversal against 
//  the trend being statistically significant based on the log normal shape of the range curve.  
//  Setting stops will help you take as much risk as necessary to stay in a good position, but not more.
//
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

KaseDevStops(Length, Level) =>
    pos = 0.0
    RWH = (high - low[Length]) / (atr(Length) * sqrt(Length))
    RWL = (high[Length] - low) / (atr(Length) * sqrt(Length))
    Pk = wma((RWH-RWL),3)
    AVTR = sma(highest(high,2) - lowest(low,2), 20)
    SD = stdev(highest(high,2) - lowest(low,2),20)
    Val4 = iff(Pk>0, highest(high-AVTR-3*SD,20), lowest(low+AVTR+3*SD,20))
    Val3 = iff(Pk>0, highest(high-AVTR-2*SD,20), lowest(low+AVTR+2*SD,20))
    Val2 = iff(Pk>0, highest(high-AVTR-SD,20), lowest(low+AVTR+SD,20))
    Val1 = iff(Pk>0, highest(high-AVTR,20), lowest(low+AVTR,20))
    ResPrice = iff(Level == 4, Val4,
                 iff(Level == 3, Val3,
                  iff(Level == 2, Val2,
                     iff(Level == 1, Val1, Val4))))
    pos := iff(close < ResPrice , -1, 1)
    pos

strategy(title="Combo Backtest 123 Reversal & Kase Dev Stops", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
LengthKDS = input(30, minval=2, maxval = 100)
LevelKDS = input(title="Trade From Level", defval=4, options=[1, 2, 3, 4])
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posKaseDevStops = KaseDevStops(LengthKDS, LevelKDS)
pos = iff(posReversal123 == 1 and posKaseDevStops == 1 , 1,
	   iff(posReversal123 == -1 and posKaseDevStops == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )

더 많은