주말 범위 전략


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

이 전략은 특히 주말 가격 변동에 대해 거래하고, 미리 설정된 상승 하락 범위를 통해 다공간 방향을 판단한다. 전형적인 충격 거래 전략에 속한다.

전략적 원칙:

  1. 지난주 금요일 종결 가격을 기준으로 하락 하락의 범위를 설정합니다. 예를 들어, 종결 가격의 4.5% 상승으로 범위를 제한합니다.

  2. 가격이 상위 범위를 넘으면 하위 조작을 하고, 가격이 하위 범위를 넘으면 더 많은 조작을 한다.

  3. 기존의 포지션의 경우, 새로운 층을 초과하는 구간에 따라 포지션을 계속 추가합니다. 예를 들어, 공백 또는 추가.

  4. 누적 수익이 일정 비율에 도달했을 때, 매매가 중단됩니다. 예를 들어 10% .

  5. 한 번에 최대 2방향의 포지션을 보유한다. 월요일 상장 전까지 모든 포지션을 청산한다.

이 전략의 장점:

  1. 고정된 상승/하락 범위를 설정하고, 기계화된 작업을 수행한다.

  2. 단계적으로 매장하면 더 좋은 가격에 매장할 수 있다.

  3. 주기적 법칙은 안정적이고, 기본적 영향을 받지 않는다.

이 전략의 위험은:

  1. 단독 손실의 크기를 제한할 수 없으며, 큰 단독 손실의 위험이 있습니다.

  2. 고정된 매개 변수는 다른 기간의 시장 변동률에 적응할 수 없습니다.

  3. 주기적 규칙이 변할 수 있고, 모델이 실패할 위험이 있다.

요약하자면, 이 전략은 주기적 법칙을 활용하여 자주 거래하지만, 수익을 잠금하는 데는 약간의 어려움이 있습니다. 파라미터가 실패하고 단독 손실이 너무 큰 위험을 경계해야하며 신중하게 작동해야합니다.

전략 소스 코드
/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-12 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//Copyright Boris Kozak 
// strategy("XBT Weekend Trade Strategy", overlay=true, default_qty_type=strategy.percent_of_equity,)
strategy.initial_capital=50000
leverage = input(10,"Leverage")
profitTakingPercentThreshold = input(0.10,"Profit Taking Percent Threshold")

//****Code used for setting up backtesting.****///
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(12, "Backtest Start Month")
testStartDay = input(10, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2025, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FFFF : na
bgcolor(testPeriodBackgroundColor, transp=50)

testPeriod() => true
    
//****END Code used for setting up backtesting.****///


//*** Main entry point is here***//
// Figure out how many days since the Friday close 
days_since_friday = if dayofweek == 6
    0
else 
    if dayofweek == 7
        1
    else
        if dayofweek == 1
            2
        else
            if dayofweek == 2
                3
            else
                if dayofweek == 3
                    4
                else
                    if dayofweek == 4
                        5
                    else
                        6
    
// Grab the Friday close price
fridaycloseprice = security(syminfo.ticker,'D',close[days_since_friday])
plot(fridaycloseprice)

// Only perform backtesting during the window specified 
if testPeriod()
    // If we've reached out profit threshold, exit all positions 
    if ((strategy.openprofit/strategy.initial_capital) > profitTakingPercentThreshold)
        strategy.close_all()
    // Only execute this trade on saturday and sunday (UTC)
    if (dayofweek == 7.0 or dayofweek == 1.0)
        // Begin - Empty position (no active trades)
        if (strategy.position_size == 0)
            // If current close price > threshold, go short 
            if ((close>fridaycloseprice*1.045))
                strategy.entry("Short Entry", strategy.short, leverage)
            else
                // If current close price < threshold, go long
                if (close<(fridaycloseprice*0.955))
                    strategy.entry("Long Entry",strategy.long, leverage)
        // Begin - we already have a position
        if (abs(strategy.position_size) > 0)
            // We are short 
            if (strategy.position_size < 0)
                if ((close>strategy.position_avg_price*1.045))
                    // Add to the position
                    strategy.entry("Adding to Short Entry", strategy.short, leverage)
            else
                if ((close<strategy.position_avg_price*0.955))
                    strategy.entry("Adding to Long Entry",strategy.long,leverage)
    // On Monday, if we have any open positions, close them 
    if (dayofweek==2.0)
        strategy.close_all()