코네티컷 바다 거북이 시스템


생성 날짜: 2023-11-06 10:23:12 마지막으로 수정됨: 2023-11-06 10:23:12
복사: 1 클릭수: 663
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

코네티컷 바다 거북이 시스템

개요

이 전략은 유명한 해파리 거래 시스템을 기반으로 개발되었으며, 원시적인 규칙을 최대한 따르고 있습니다. 이것은 트렌드를 추적하는 시스템이며, 쌍평선으로 입출력 신호를 형성합니다.

전략 원칙

  • 최고값을 계산한 N1 일선과 N2 일선 ((설정 20일과 55일) 을 사용하여 쌍평평선을 구성한다.
  • 최저값을 계산하는 N3 일선과 N4 일선 (기본 10일과 20일) 을 사용하여 쌍평평선을 구성한다.
  • N2 일선을 넘으면 더 많이 하고, N4 일선을 넘으면 평점으로 한다.
  • 더 많은 돈을 벌면 매번 N배의 ATR (기본 1배) 을 받고, 한 번, 최대 5번의 ATR을 받습니다.
  • 고정된 스톱로스를 설정하고, N배의 ATR을 기본으로 입점 가격 이하로 설정합니다.
  • 새로운 포지션은 이전 거래가 승리한 후에만 허용됩니다.

우위 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  • 트렌드 트레이딩 원칙에 따라 중·장선 트렌드를 포착할 수 있다.
  • 이중 평행선은 필터링 조건을 형성하여, 흔들림 중에 자주 거래되는 것을 방지한다.
  • 추적 스톱은 합리적으로 설정되어 너무 느슨하거나 너무 좁은 스톱을 피합니다.
  • 파라미탈 설정을 사용하여 시스템의 위험 수익 특성을 조정하기 편리하다.
  • 이 트렌드에서 더 많은 수익을 얻을 수 있습니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  • 트렌드 반전시 적시에 중단하지 못하면 큰 손실이 발생할 수 있습니다.
  • 너무 많은 포지션은 과도한 거래의 위험을 초래할 수 있습니다.
  • 잘못된 매개 변수 설정으로 인해 시스템이 너무 급진적이거나 보수적이 될 수 있습니다.
  • 복사 데이터 적합 위험, 실디 효과는 복사보다 약할 수 있다.

위험은 다음과 같은 방법으로 줄일 수 있습니다.

  • 역전 신호 판단을 높여 MACD 이탈과 같은 역전 손실을 줄인다.
  • 최적화 변수, 시스템의 변수를 안정하게한다.
  • 포지션 사이징 방법을 추가한다. 큰 손실이 발생했을 때 포지션을 줄인다.

최적화 방향

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

  • 공짜 거래 논리를 추가하여 전략이 하락 시에도 수익을 얻을 수 있도록 한다.
  • 스톱 라인 최적화 모듈을 추가하여 스톱 라인을 가격 변동에 따라 적절하게 조정할 수 있습니다.
  • 포지션 관리 모듈을 추가하여 매번 포지션 크기를 최적화합니다.
  • 트렌드 지수인 ADX와 함께 트렌드 강점을 판단하여 잘못된 거래를 피하십시오.
  • 더 평평한 수익 곡선을 얻기 위해 매개 변수를 최적화하십시오.
  • 실 디스크 거래의 슬라이드 포인트, 수수료 등 거래 비용을 고려하십시오.

요약하다

이 전략은 트렌드 추적을 통해 수익을 얻으며, 약간의 재검토 장점이 있습니다. 그러나 실장 효과는 여전히 검증되어야하며, 매개 변수 안정성을 추가로 최적화하고, 스톱로스 및 포지션 관리 모듈을 개선해야 합니다. 전략이 실장 거래에 더 적합하도록 하기 위해서는.

전략 소스 코드
/*backtest
start: 2022-10-30 00:00:00
end: 2023-11-05 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="Turtle", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1, pyramiding=5)

stopInput = input(2.0, "Stop N", step=.5)
pyramidInput = input(1, "Pyramid N", step=.5)
l1LongInput = input(20, "L1 Long", minval=5)
l2LongInput = input(55, "L2 Long", minval=5)
l1LongExitInput = input (10, "L1 Long Exit", minval=5)
l2LongExitInput = input (20, "L2 Long Exit", minval=5)

FromYear = input(2000, "From Year", minval=1900),   FromMonth = input(1, "From Month", minval=1, maxval=12),    FromDay = input(1, "From Day", minval=1, maxval=31)
ToYear = input(9999, "To Year", minval=1900),       ToMonth = input(1, "To Month", minval=1, maxval=12),        ToDay = input(1, "To Day", minval=1, maxval=31)
FromDate = timestamp(FromYear, FromMonth, FromDay, 00, 00),     ToDate = timestamp(ToYear, ToMonth, ToDay, 23, 59)
TradeDateIsAllowed() => time >= FromDate and time <= ToDate
l1Long = highest(l1LongInput)
l1LongExit = lowest(l1LongExitInput)
l2Long = highest(l2LongInput)
l2LongExit = lowest(l2LongExitInput)

// 
// ADX, +-DI
// https://www.tradingview.com/script/rlMJ05yl-ADX-and-DI-pine-script-3-0/
//
len = 14
th = 20
TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)

// Back to Turtle

filter = true // not (DIPlus < ADX and DIMinus < ADX) and DIPlus > DIMinus
var win = false
var totalPrice = 0.0
var buyPrice = 0.0
var avgPrice = 0.0
var nextBuyPrice = 0.0
var stopPrice = 0.0
var totalBuys = 0

var bool inBuy = false
var float l1LongPlot = highest(l1LongInput)
var float l2LongPlot = highest(l2LongInput)

n = atr(14)

var mode = 'L1'
string longLevel = na

if not inBuy 
    l1LongPlot := highest(l1LongInput)[1]
    l2LongPlot := highest(l2LongInput)[1]
    
    if (close > l2Long[1] and filter)
        mode := 'L2'
        if TradeDateIsAllowed() 
            strategy.close_all()
            strategy.entry("long", strategy.long, comment="L2")
            longLevel := 'L2'

        win := false
        buyPrice := close
        totalBuys := 1
        totalPrice := buyPrice
        avgPrice := buyPrice
        stopPrice := close-(stopInput*n)
        nextBuyPrice := high+(pyramidInput*n)
        inBuy := true
    else 
        if (close > l1Long[1] and filter)
            mode := 'L1'
            if not win
                if TradeDateIsAllowed()
                    strategy.close_all()
                    strategy.entry("long", strategy.long, comment="L1")
                    longLevel := 'L1'
            win := false
            buyPrice := close
            totalBuys := 1
            totalPrice := buyPrice
            avgPrice := buyPrice
            stopPrice := close-(stopInput*n)
            nextBuyPrice := high+(pyramidInput*n)
            inBuy := true
        else 
            inBuy := false

else
    l1LongPlot := l1LongPlot[1]
    l2LongPlot := l2LongPlot[1]
    
    if close > nextBuyPrice and TradeDateIsAllowed() and totalBuys < 6
        strategy.entry("long", strategy.long, comment="LP")
        longLevel := 'P'
        stopPrice := close-(stopInput*n)
        nextBuyPrice := high+(pyramidInput*n)
        totalBuys := totalBuys + 1
        totalPrice := totalPrice + buyPrice
        avgPrice := totalPrice / totalBuys

    if (close < stopPrice) 
        inBuy := false
        if TradeDateIsAllowed()
            if (close >= avgPrice)
                longLevel := 'SG'
            else 
                longLevel := 'SR'
            strategy.close("long", strategy.long)
        win := false
        buyPrice := 0
        avgPrice := 0
    else
        if (mode == 'L1' and close > l2Long[1] and filter)
            if win
                inBuy := true
                win := false
                mode := 'L2'
                if TradeDateIsAllowed()
                    strategy.close_all()
                    longLevel := 'L2'
                    strategy.entry("long", strategy.long, comment="L2")
                buyPrice := close
                totalBuys := 1
                totalPrice := buyPrice
                avgPrice := buyPrice
                stopPrice := close-(stopInput*n)
                nextBuyPrice := close+(pyramidInput*n)
        else
            if (close < l1LongExit[1] or close < l2LongExit[1])
                inBuy := false
                if TradeDateIsAllowed()
                    strategy.close("long", strategy.long)
                if close < avgPrice
                    longLevel := 'SR'
                    win := false
                else
                    longLevel := 'SG'
                    win := true
                buyPrice := 0

plot(l1LongPlot, title="l1 long", linewidth=3, style=plot.style_stepline, color=color.green)
plot(l1LongExit[1], title="l1 exit", linewidth=3, style=plot.style_stepline, color=color.red)

plot(l2LongPlot, title="l2 long", linewidth=2, style=plot.style_stepline, color=color.green)
plot(l2LongExit[1], title="l2 exit", linewidth=2, style=plot.style_stepline, color=color.red)

plot(stopPrice, title="stop", linewidth=2, style=plot.style_stepline, color=color.purple)

plotarrow(longLevel == 'L1' ? 1 : 0, colordown=color.black, colorup=color.green, transp=40)
plotarrow(longLevel == 'L2' ? 1 : 0, colordown=color.black, colorup=color.purple, transp=40)
plotarrow(longLevel == 'SR' ? -1 : 0, colordown=color.red, colorup=color.purple, transp=40)
plotarrow(longLevel == 'SG' ? -1 : 0, colordown=color.green, colorup=color.purple, transp=40)