Strategi Dagangan Berasaskan Saluran Donchain

Penulis:ChaoZhang, Tarikh: 2024-02-27 14:57:37
Tag:

img

Ringkasan

Ini adalah strategi perdagangan yang menggunakan saluran Donchain dalam beberapa jangka masa untuk menentukan titik masuk dan keluar.

Logika Strategi

Strategi ini terutamanya memanfaatkan konsep saluran Donchain, yang terdiri daripada saluran atas, bawah dan garis tengah. Lebar saluran berbeza dalam jangka masa yang berbeza. Khususnya, kami membina saluran Donchain dalam dua skala masa:

  1. Gunakan 52 tempoh untuk membina saluran Donchain jangka panjang dan mendapatkan garis atas, bawah dan tengahnya.

  2. Gunakan 12 tempoh untuk membina saluran Donchain jangka pendek dan mendapatkan garis atas, bawah dan tengahnya.

Logik kemasukan: Apabila harga pecah di atas bahagian atas saluran jangka panjang, kita menentukan sebagai isyarat kemasukan panjang. Untuk mengelakkan pecah palsu, kita memerlukan sekurang-kurangnya 1 lilin dalam 3 terakhir ditutup di atas bahagian atas saluran.

Logik keluar: Apabila harga pecah di bawah bahagian bawah saluran jangka pendek, kita tentukan sebagai isyarat keluar untuk menutup kedudukan panjang.

Kelebihan

  1. Strategi ini menggabungkan kelebihan kedua-dua perdagangan trend berikut dan purata pembalikan.

  2. Menggunakan analisis pelbagai jangka masa membantu mengatasi masalah dengan pecah palsu dan membuat entri / keluar lebih sah.

  3. Parameter boleh dioptimumkan untuk produk dan rejimen pasaran yang berbeza.

Risiko & Penyelesaian

  1. Strategi ini sensitif terhadap parameter. Parameter yang berbeza boleh membawa kepada hasil yang berbeza secara drastik. Ujian dan pengoptimuman yang mencukupi diperlukan untuk mencari set parameter yang optimum.

  2. Ia boleh mencetuskan perdagangan yang berlebihan di pasaran yang berbeza.

  3. Ia tidak mengambil kira rejim pasaran secara keseluruhan. Ia mungkin gagal pada titik pembalikan trend utama. Penunjuk lain harus digunakan untuk mengukur trend utama.

Arahan pengoptimuman

  1. Melakukan pengoptimuman parameter untuk mencari parameter terbaik, termasuk tempoh saluran, jenis saluran dan lain-lain.

  2. Menggabungkan logik stop loss dengan stop trailing yang munasabah untuk mengawal kerugian.

  3. Gabungkan penunjuk lain untuk menentukan trend utama, seperti EMA, Saluran Keltner, MACD dll, mengelakkan kegagalan pada titik perubahan utama.

Kesimpulan

Ringkasnya, ini adalah strategi penembusan saluran Donchain pelbagai jangka masa yang tipikal. Ia mengintegrasikan kedua-dua trend berikut dan pembalikan purata dengan baik untuk menangkap pembalikan tempatan dalam trend. Dengan parameter yang dioptimumkan, ia dapat melakukan dengan sangat baik di pasaran yang sedang berkembang. Walau bagaimanapun, strategi itu sendiri rapuh, sensitif terhadap parameter dan rejim pasaran secara keseluruhan. Adalah disyorkan untuk digabungkan dengan strategi atau penunjuk lain untuk mencapai hasil yang lebih kukuh.


/*backtest
start: 2023-02-20 00:00:00
end: 2024-02-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © venkyrocker7777

//@version=5

strategy('Donchain channel based investment strategy', shorttitle='Donchain channel strategy', overlay=true)

Length = input.int(21, minval=1)
xPrice = close
xvnoise = math.abs(xPrice - xPrice[1])
nAMA = 0.0
nfastend = 0.666
nslowend = 0.0645
nsignal = math.abs(xPrice - xPrice[Length])
nnoise = math.sum(xvnoise, Length)
nefratio = nnoise != 0 ? nsignal / nnoise : 0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
plot(nAMA, color=color.new(color.blue, 0), title='KAMA')

// Function to get Lower Channel, Upper Channel, Middle Channel for a period length
getLCUCMC(PeriodLength) =>
    lowestValueInThePeriod = ta.lowest(PeriodLength)  // LC
    highestValueInThePeriod = ta.highest(PeriodLength)  // UC
    middleChannelInTheperiod = math.avg(highestValueInThePeriod, lowestValueInThePeriod)  // MC
    // Returns Lower Channel, Upper Channel, Middle Channel for a period length
    [lowestValueInThePeriod, highestValueInThePeriod, middleChannelInTheperiod]

// Longer time frame for entry
longerPeriod = 52

// Shorter time frame for exit
shorterPeriod = 12

if timeframe.period == 'D'
    // Longer time frame for entry
    longerPeriod := 52 * 5

    // Shorter time frame for exit
    shorterPeriod := 12 * 5
    shorterPeriod

if timeframe.period == 'M'
    // Longer time frame for entry
    longerPeriod := 12

    // Shorter time frame for exit
    shorterPeriod := 3
    shorterPeriod

// Get Lower Channel, Upper Channel, Middle Channel for longerPeriod, shorterPeriod
[lowestValueInTheLongerPeriodLength, highestValueInTheLongerPeriodLength, middleChannelInLongerperiod] = getLCUCMC(longerPeriod)
[lowestValueInTheShorterPeriodLength, highestValueInTheShorterPeriodLength, middleChannelInShorterperiod] = getLCUCMC(shorterPeriod)


// Plot Upper Channel of longerPeriod in dark green
plot(highestValueInTheLongerPeriodLength, 'highestValueInTheLongerPeriodLength', color=color.new(color.green, 0))

// Plot Lower Channel of shorterPeriod in dark red
plot(lowestValueInTheShorterPeriodLength, 'lowestValueInTheShorterPeriodLength', color=color.new(color.red, 0))

// Entry Plan
// Will start to see if we can enter when high crosses up longer period high (high >= highestValueInTheLongerPeriodLength)
// Check if any of the three past candles and enter when any of the 3 past candles satisfy
// 1) high of that candle >= highestValueInTheLongerPeriodLength of that candle (high[i] >= highestValueInTheLongerPeriodLength[i])
// 2) close of entry point consideration candle is above close of that candle (close > close[i])
isThisPointAnEntry() =>
// Check last 3 bars
    isThisPointAnEntry = false
    offset = 0
    for i = 1 to 3 by 1
        isCurrentCandleALongerPeriodHigh = high >= highestValueInTheLongerPeriodLength
        isCurrentCandleCloseGreaterThanPreiousIthOne = close > close[i]
        isPreviousIthCandleAlsoALongerPeriodHigh = high[i] >= highestValueInTheLongerPeriodLength[i]
        isThisPointAnEntry := isCurrentCandleALongerPeriodHigh and isCurrentCandleCloseGreaterThanPreiousIthOne and isPreviousIthCandleAlsoALongerPeriodHigh
        if isThisPointAnEntry
            offset := -i
            break
    [isThisPointAnEntry, offset]

// Exit Plan - same as entry plan, with things reversed and also on a shorter time frame
// Will start to see if we should exit when low crosses down longer period low (low <= lowestValueInTheShorterPeriodLength)
// Check if any of the three past candles and exit when any of the 3 past candles satisfy
// 1) low of that candle <= highestValueInTheLongerPeriodLength of that candle (low[i] <= lowestValueInTheShorterPeriodLength[i])
// 2) close of exit point consideration candle is below close of that candle (close < close[i])
isThisPointAnExit() =>
// Check last 3 bars
    isThisPointAnExit = false
    for i = 1 to 3 by 1
        isCurrentCandleAShorterPeriodLow = low <= lowestValueInTheShorterPeriodLength
        isCurrentCandleCloseLesserThanPreiousIthOne = close < close[i]
        isPreviousIthCandleAlsoAShorterPeriodLow = low[i] <= lowestValueInTheShorterPeriodLength[i]
        isThisPointAnExit := isCurrentCandleAShorterPeriodLow and isCurrentCandleCloseLesserThanPreiousIthOne and isPreviousIthCandleAlsoAShorterPeriodLow
        break
    isThisPointAnExit

[isEntry, offset] = isThisPointAnEntry()


if isEntry
    strategy.entry('Buy', strategy.long)

strategy.close_all(when=isThisPointAnExit() == true)

if year(timenow) == year(time) and month(timenow) == month(time) and dayofmonth(timenow) - 2 == dayofmonth(time)
    strategy.close_all()



Lebih lanjut