Strategi Pelacakan Persentase Kotak Dinamis

Penulis:ChaoZhang, Tanggal: 2023-11-23 10:32:39
Tag:

img

Gambaran umum

Strategi ini menggunakan perubahan persentase harga untuk menetapkan garis masuk dan garis stop loss. Ini memasuki posisi ketika harga menembus garis masuk dan keluar posisi ketika harga turun di bawah garis stop loss. Fitur utamanya adalah bahwa hanya mengambil satu unit risiko, yang berarti bahwa posisi baru hanya akan ditambahkan setelah posisi sebelumnya mencapai target keuntungan yang telah ditetapkan sebelumnya.

Prinsip-prinsip

Strategi pertama menetapkan harga acuan dan menggunakan 10% dari harga itu sebagai kisaran harga - batas atas adalah garis masuk dan batas bawah adalah garis stop loss. Ketika harga menembus garis masuk, jumlah tetap akan dibeli. Ketika harga turun di bawah garis stop loss, posisi akan ditutup. Setelah menghasilkan keuntungan, garis masuk dan stop loss akan disesuaikan dengan persentase untuk memperluas kisaran keuntungan. Ini memungkinkan strategi untuk melacak trend run.

Hal ini berarti bahwa posisi baru hanya akan ditambahkan setelah posisi saat ini mencapai target keuntungan. Posisi baru juga akan mengikuti garis entry dan stop loss baru. Hal ini membatasi risiko.

Analisis Keuntungan

Strategi ini menggabungkan keuntungan dari trailing stops dan ukuran posisi, yang memungkinkan pengendalian risiko yang efektif sambil menguntungkan.

  1. Menggunakan rentang persentase untuk garis masuk dan stop loss memungkinkan pelacakan tren otomatis
  2. Risiko terbatas pada satu digit, menghindari kerugian besar
  3. Posisi baru hanya ditambahkan setelah keuntungan, menghindari mengejar tren
  4. Stop loss line bergerak ke atas setelah keuntungan, mengunci keuntungan

Analisis Risiko

Ada juga beberapa risiko:

  1. Jika rentang persentase terlalu luas, risiko dapat berkembang
  2. Jika rentang terlalu sempit, potensi keuntungan terbatas
  3. Penempatan stop loss yang tidak tepat dapat menyebabkan keluar dini
  4. Penambahan agresif dapat memperkuat kerugian

Risiko ini dapat dihindari dengan menyesuaikan parameter seperti ukuran kisaran, filter masuk, dll.

Optimalisasi

Ada ruang untuk optimasi lebih lanjut:

  1. Menggabungkan dengan indikator tren untuk menentukan arah tren
  2. Menambahkan model pembelajaran mesin untuk jalur yang lebih adaptif
  3. Uji kondisi penambahan yang berbeda untuk mengurangi risiko
  4. Menemukan periode penyimpanan yang optimal melalui pengujian

Kesimpulan

Ini adalah sistem berbasis rentang persentase yang sederhana dan praktis. Melalui penyesuaian parameter dan pengoptimalan model, strategi ini dapat menjadi alat pelacakan tren yang dapat diandalkan, menghasilkan kinerja yang lebih stabil bagi investor.


/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HermanBrummer 4 April 2021

strategy ("The Box Percent Strat", shorttitle="The Box", overlay = true)

///     Designed for LONG only on Daily, 2D or 3D Charts
///     Uses fixed investment risk amount, meaning you're willing to lose that amount per trade
///     Limit buy to not overpay

RiskPerTrade            = input(10000, "Risk losing this much per trade", tooltip="This calculates how much you will lose based on difference between the entry price and stop loss price")
TradeAboveMAFilterPer   = input(50, "The System won't trade if price is below this MA")

UpBoxSize               = (input(10, "Box size in %") * 0.01)+1 // 1.1 == 10% up
DnBoxSize               = 1-(input(10, "Box size in %") * 0.01) // 0.9 == 10% dn


var FirstBar            = close > 0 ? close : na
var FirstTop            = FirstBar * UpBoxSize
var FirstBot            = FirstBar * DnBoxSize


var top                 = sma(FirstTop, 1)
var bot                 = sma(FirstBot, 1)

///     The Box Calcs
if  high[2] > top
    top                 := top * UpBoxSize
    bot                 := bot * UpBoxSize
if  low[1]  < bot
    top                 := top * DnBoxSize
    bot                 := bot * DnBoxSize

 
plot(bot,   "Bot",      #ff0000) // Green
plot(top,   "Top",      #00ff00) // Red

mid                     = ((top-bot)/2)+bot 
plot(mid,   "Mid", color.gray)

TradeAboveMAFilter      = sma(close, TradeAboveMAFilterPer)
plot(TradeAboveMAFilter, "Trade AboveMAF Filter", color.yellow, 3, style=plot.style_circles)

// col = high[1] < top and high >= top ? color.white : na
// bgcolor(col)


///     Shares
RiskRange                   = close * abs(DnBoxSize - 1) // 0.9 - 1 == 1.10 // 10% abs so you don't get a neg number NB NB
Shares                      = RiskPerTrade / RiskRange 
//plot(close-RiskRange, "RiskRange", color.fuchsia)

Enter   =   high >= top
             and close[1] > TradeAboveMAFilter
             and strategy.opentrades[0] == strategy.opentrades[1]
             and strategy.opentrades[1] == strategy.opentrades[2] 
             and strategy.opentrades[2] == strategy.opentrades[3]
             and strategy.opentrades[3] == strategy.opentrades[4] 
             and strategy.opentrades[4] == strategy.opentrades[5]
             and strategy.opentrades[5] == strategy.opentrades[6]
             // won't enter if new positon was taken in the last 6 bars
             // need better code for this.

///     Buy & Sell
//  (new highs)    and  (Close above moving average filter) and (No new trades were taken receently)
if  Enter //(high >= top)  and  (close[1] > TradeAboveMAFilter) and strategy.opentrades[0] == strategy.opentrades[1] 
    strategy.order("En", strategy.long, qty=Shares, limit=top)//, stop=top)
    
//barcolor(strategy.position_size != 0 ? #00ff00 : color.gray)


// ///     If ONE Position THEN this Stop Because: 
// if  strategy.position_size == 1
//     strategy.exit("Ex", "En", stop=bot)
///     If it has more than one trad OPEN
if  strategy.position_size > 0
    strategy.exit("Ex", "En", stop=bot[2] )   // puts stop on old bot

//plot(strategy.position_avg_price, "Avg Price", color.yellow)





Lebih banyak