주말 범위 거래 전략

저자:차오장, 날짜: 2023-09-13 11:53:09
태그:

이 전략은 사전 설정된 비율 대역을 기반으로 긴 / 짧은 방향을 결정하여 주말 가격 변동을 구체적으로 거래합니다. 이것은 전형적인 범위 거래 시스템입니다.

전략 논리:

  1. 지난 금요일 종료 기준으로 비율 범위를 설정하십시오. 예를 들어 4.5% 상승/하락.

  2. 가격이 상향선을 넘으면 단축, 하향선을 넘으면 장거리

  3. 기존 방향의 새로운 범위에 도달할 때 위치를 추가합니다.

  4. 축적된 이익이 10%의 임계치를 달성하면 수익을 취합니다.

  5. 한쪽에서 한 쪽으로 동시에 두 개의 포지션을 허용합니다. 월요일까지 모두 닫습니다.

장점:

  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()
 






더 많은