무작위 진입을 기반으로 한 복합 손절매 및 이익 실현 전략


생성 날짜: 2024-01-24 15:38:49 마지막으로 수정됨: 2024-01-24 15:38:49
복사: 5 클릭수: 688
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

무작위 진입을 기반으로 한 복합 손절매 및 이익 실현 전략

개요

이 전략의 주요 아이디어는 무작위 숫자를 통해 입문점을 결정하고, 3개의 스톱 스톱 포인트와 1개의 스톱 스팟 포인트를 설정하여 리스크를 관리하고, 각 거래의 손실을 제어하는 것이다.

전략 원칙

이 전략은 무작위적인 숫자rd_number_entry를 사용하여 11에서 13 사이에 더 많은 진입점을 결정하고,rd_number_exit를 사용하여 20에서 22 사이에 더 많은 진입점을 결정하고, 평점을 결정한다. 더 많은 진입을 한 후, 진입 가격에 진입 가격을 더하기 위해 세 개의 정지점을 설정하고, 첫 번째 정지점을 진입 가격에 추가하고, 두 번째 정지점을 진입 가격에 추가하고, 세 번째 정지점을 진입 가격에 추가합니다.

이 전략은 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)