Strategi kisaran akhir pekan


Tanggal Pembuatan: 2023-09-13 11:53:09 Akhirnya memodifikasi: 2023-09-13 11:53:09
menyalin: 1 Jumlah klik: 635
1
fokus pada
1617
Pengikut

Strategi ini diperdagangkan secara khusus untuk fluktuasi harga pada akhir pekan, dengan menentukan arah bullish melalui rentang kenaikan dan penurunan yang telah ditetapkan sebelumnya.

Prinsip-prinsip Strategi:

  1. Dengan merujuk pada harga penutupan pada hari Jumat pekan lalu, tentukan kisaran harga naik turun, misalnya kisaran harga penutupan di atas kisaran harga naik 4,5%.

  2. Bila harga melebihi batas atas, lakukan shorting; bila harga di bawah batas bawah, lakukan multiply.

  3. Dalam kasus posisi yang sudah ada, lanjutkan untuk menambah posisi sesuai dengan lebih dari satu lapisan baru, seperti mengosongkan atau menambah.

  4. Stop loss terjadi ketika keuntungan terakumulasi mencapai persentase tertentu, misalnya 10%.

  5. Posisi yang memegang paling banyak dua arah dalam satu waktu. Semua posisi kosong sebelum buka hari Senin.

Keuntungan dari strategi ini:

  1. Menetapkan rentang naik turun yang tetap, untuk melakukan operasi mekanis.

  2. Dengan cara ini, Anda bisa mendapatkan harga yang lebih murah.

  3. Hukum periodik stabil dan tidak dipengaruhi oleh fundamental.

Bahaya dari strategi ini:

  1. Tidak ada batasan untuk jumlah kerugian tunggal, dan ada risiko kerugian tunggal besar.

  2. Parameter tetap tidak dapat disesuaikan dengan fluktuasi pasar pada periode waktu yang berbeda.

  3. Periodisme dapat berubah, sehingga model dapat gagal.

Kesimpulannya, strategi ini memanfaatkan aturan periodik untuk perdagangan yang sering terjadi, tetapi ada masalah dengan kesulitan mengunci keuntungan tertentu. Perlu waspada parameter gagal dan risiko kerugian tunggal terlalu besar, operasi hati-hati.

Kode Sumber Strategi
/*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()