週末の取引戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-13 11:53:09
タグ:

この戦略は,前もって設定された百分比帯に基づいて長/短方向を決定することによって,週末の価格変動を特別の取引します.これは典型的な範囲取引システムです.

戦略論理:

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






もっと