랜덤 엔트리에 기반한 종합 스톱 로스 및 영업 전략

저자:차오장날짜: 2024-01-24 15:38:49
태그:

img

전반적인 설명

이 전략의 주요 아이디어는 임의로 입구 지점을 결정하고 각 거래의 위험 관리 및 이익과 손실을 제어하기 위해 세 가지 수익점과 한 번의 손실을 멈추는 지점을 설정하는 것입니다.

전략 논리

이 전략은 롱 엔트리 포인트를 결정하기 위해 11에서 13 사이의 랜덤 숫자 rd_number_entry를 사용하고, 포지션의 폐쇄를 결정하기 위해 20에서 22 사이의 rd_number_exit을 사용합니다. 롱을 마친 후 스톱 로스는 엔트리 가격 마이너스 atr ((14) 로 설정됩니다.slx. 동시에, 세 가지 취득 포인트가 설정됩니다. 첫 번째 취득 포인트는 입시 가격 더하기 atr ((14) 입니다.tpx, 두 번째 수익점은 입시 가격 더하기 2입니다.tpx, 그리고 세 번째 취득 포인트는 입시 가격 더하기 3입니다shorts의 원칙은 비슷하지만, 엔트리 결정은 다른 rd_number_entry 값을 취하고, 이윤을 취하고 손실을 멈추는 방향은 반대입니다.

리스크는 tpx (수익률) 와 slx (손실률) 를 조정하여 제어할 수 있습니다.

이점 분석

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

  1. 무작위 입력의 사용은 곡선 부착의 가능성을 줄일 수 있습니다
  2. 여러 개의 스톱 로스 및 수익 포인트를 설정하면 단일 거래의 위험을 제어 할 수 있습니다.
  3. ATR을 사용하여 수익을 취하고 손실을 멈추도록 설정하면 시장 변동성을 기반으로 할 수 있습니다.
  4. 거래 위험은 계수를 조정함으로써 통제될 수 있습니다.

위험 분석

이 전략의 위험은 또한 다음을 포함합니다.

  1. 무작위로 입력하면 트렌드를 놓칠 수 있습니다.
  2. 스톱 손실이 너무 작다면, 그것은 쉽게 중지 될 수 있습니다
  3. 영업이익이 너무 크면 영업이익이 충분하지 않을 수 있습니다.
  4. 부적절한 매개 변수는 더 큰 손실로 이어질 수 있습니다.

리스크는 수익을 취하고 손실을 멈추는 계수를 조정하고 무작위 입력 논리를 최적화함으로써 줄일 수 있습니다.

최적화 방향

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

  1. 무작위 입력 논리를 개선하고 트렌드 지표 판단을 통합
  2. 이윤률을 더 합리적으로 만들기 위해 수익률 및 손해 중지 계수를 최적화
  3. 다른 단계에 다른 이익이 공간을 사용 하기 위해 위치 통제를 증가
  4. 기계 학습 알고리즘으로 매개 변수를 최적화

결론

이 전략은 랜덤 엔트리에 기반하고 단일 거래의 위험을 제어하기 위해 여러 가지 수익을 취하고 손실을 멈추는 지점을 설정합니다. 높은 무작위성으로 인해 곡선 적합성의 확률이 감소 할 수 있습니다. 매개 변수 최적화를 통해 거래 위험을 줄일 수 있습니다. 추가 최적화와 연구에 여전히 많은 공간이 있습니다.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Random Strategy with 3 TP levels and SL", overlay=true,max_bars_back = 50)

tpx = input(defval = 0.8, title = 'Atr multiplication for TPs?')
slx = input(defval = 1.2, title = 'Atr multiplication for SL?')
isLong = false
isLong := nz(isLong[1])

isShort = false
isShort := nz(isShort[1])

entryPrice = 0.0
entryPrice := nz(entryPrice[1])
tp1 = true
tp1 := nz(tp1[1])
tp2 = true
tp2 := nz(tp2[1])

sl_price = 3213.0
sl_price := nz(sl_price[1])

sl_atr = atr(14)*slx
tp_atr = atr(14)*tpx

rd_number_entry = 1.0
rd_number_entry := (16708 * nz(rd_number_entry[1], 1) % 2147483647)%17

rd_number_exit = 1.0
rd_number_exit := ((16708 * time % 2147483647) %17)


//plot(rd_number_entry)

shortCondition = (rd_number_entry == 13? true:false) and (year >= 2017) and not isLong and not isShort
longCondition = (rd_number_entry == 11 ? true:false) and (year >= 2017) and not isShort and not isShort
//Never exits a trade:
exitLong = (rd_number_exit == 22?true:false) and (year >= 2018) and not isShort
exitShort = (rd_number_exit ==  22?true:false) and (year >= 2018) and not isLong


//shortCondition = crossunder(sma(close, 14), sma(close, 28)) and year >= 2017
//longCondition = crossover(sma(close, 14), sma(close, 28)) and year >= 2017

//exitLong = crossunder(ema(close, 14), ema(close, 28)) and year >= 2017
//exitShort = crossover(ema(close, 14), ema(close, 28)) and year >= 2017

if (longCondition and not isLong)
    strategy.entry('Long1', strategy.long)
    strategy.entry('Long2', strategy.long)
    strategy.entry('Long3', strategy.long)
    isLong := true
    entryPrice := close
    isShort := false
    tp1 := false
    tp2 := false
    sl_price := close-sl_atr

if (shortCondition and not isShort)
    strategy.entry('Short1', strategy.short)
    strategy.entry('Short2', strategy.short)
    strategy.entry('Short3', strategy.short)
    isShort := true
    entryPrice := close
    isLong := false
    tp1 := false
    tp2 := false
    sl_price := close+sl_atr
    
if (exitShort and isShort)
    strategy.close('Short1')
    strategy.close('Short2')
    strategy.close('Short3')
    isShort :=  false

if (exitLong and isLong)
    strategy.close('Long1')
    strategy.close('Long2')
    strategy.close('Long3')
    isLong :=  false

if isLong
    if (close > entryPrice + tp_atr) and not tp1
        strategy.close('Long1')
        tp1 := true
        sl_price := close - tp_atr
    if (close > entryPrice + 2*tp_atr) and not tp2
        strategy.close('Long2')
        tp2 := true
        sl_price := close - tp_atr
    if (close > entryPrice + 3*tp_atr)
        strategy.close('Long3')
        isLong := false
    if (close < sl_price)
        strategy.close('Long1')
        strategy.close('Long2')
        strategy.close('Long3')
        isLong := false

if isShort
    if (close < entryPrice - tp_atr) and not tp1
        strategy.close('Short1')
        sl_price := close + tp_atr
        tp1 := true
    if (close < entryPrice - 2*tp_atr) and not tp2
        strategy.close('Short2')
        sl_price := close + tp_atr
        tp2 := true
    if (close < entryPrice - 3*tp_atr)
        strategy.close('Short3')
        isShort := false
    if (close > sl_price)
        strategy.close('Short1')
        strategy.close('Short2')
        strategy.close('Short3')
        isShort := false
plot(atr(14)*slx)
plot(sl_price)

더 많은