Tren ATR dan RSI adaptif mengikut strategi dengan Stop Loss Trailing

Penulis:ChaoZhang, Tarikh: 2024-01-23 11:31:14
Tag:

img

Ringkasan

Strategi ini menggabungkan Julat Benar Purata (ATR), Indeks Kekuatan Relatif (RSI) dan Stop Loss Trailing untuk mencapai trend yang mengikuti adaptif.

Prinsip-prinsip

  1. Mengira ATR. ATR menunjukkan turun naik pasaran dan tahap risiko. Strategi ini menggunakan ATR untuk mengira stop loss dinamik untuk kawalan risiko adaptif.

  2. Mengira RSI. RSI menilai status overbought/oversold. Apabila RSI melebihi 50 ia menandakan prospek bullish, apabila di bawah 50 prospek bearish. Strategi ini menggunakan RSI untuk menentukan arah trend.

  3. Mengikut tahap stop loss yang dikira oleh ATR dan arah trend oleh RSI, strategi ini terus bergerak stop loss untuk mengesan turun naik harga, untuk memaksimumkan keuntungan sambil memastikan stop loss yang berkesan.

  4. Secara khusus, panjang apabila RSI melebihi 50, pendek apabila di bawah 50, kemudian bergerak stop loss berdasarkan ATR untuk mengunci keuntungan di sepanjang trend.

Analisis Kelebihan

  1. ATR adaptif stop loss mengambil kira turun naik pasaran, mengelakkan stop loss yang terlalu luas atau terlalu ketat.

  2. RSI dapat diandalkan mengenal pasti trend, mengelakkan whipsaws.

  3. Penghentian kerugian menyusuri trend untuk meningkatkan sasaran keuntungan.

Analisis Risiko

  1. Parameter ATR dan RSI memerlukan pengoptimuman backtest, jika tidak, kesan prestasi strategi.

  2. Walaupun dengan perlindungan stop loss, risiko masih wujud untuk lompatan harga tiba-tiba untuk menembusi stop loss.

  3. Prestasi strategi sangat bergantung pada penyesuaian parameter untuk produk yang berbeza.

Peningkatan

  1. Pertimbangkan algoritma pembelajaran mesin untuk pengoptimuman parameter adaptif.

  2. Tambah kawalan saiz kedudukan untuk pelarasan dinamik berdasarkan keadaan pasaran, untuk mengurangkan kebarangkalian penembusan stop loss.

  3. Tambah lebih banyak penunjuk trend untuk mengelakkan kehilangan titik pembalikan trend utama.

Kesimpulan

Strategi ini mengintegrasikan ATR, RSI dan penangguhan stop loss untuk sistem trend berikut yang tipikal. Melalui penyesuaian parameter, ia boleh disesuaikan dengan fleksibel dengan produk perdagangan yang berbeza, strategi trend berikut universal yang disyorkan. Dengan lebih banyak penilaian dan pengoptimuman pembelajaran mesin, ia dapat mencapai prestasi yang lebih baik.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-19 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title="UTBot Strategy", overlay = true )
   
// CREDITS to @HPotter for the orginal code. 
// CREDITS to @Yo_adriiiiaan for recently publishing the UT Bot study based on the original code -
// CREDITS to @TradersAITradingPlans for making this Strategy. 
// Strategy fixed with Time period by Kirk65.
// I am using this UT bot with 2 hours time frame with god resultss. Alert with "Once per bar" and stoploss 1.5%. If Alerts triggered and price goes against Alert. Stoploss will catch it. Wait until next Alert.
// While @Yo_adriiiiaan mentions it works best on a 4-hour timeframe or above, witch is a lot less risky, but less profitable. 

testStartYear = input(2019, "BACKTEST START YEAR", minval = 1980, maxval = 2222) 
testStartMonth = input(01, "BACKTEST START MONTH", minval = 1, maxval = 12)
testStartDay = input(01, "BACKTEST START DAY", minval = 1, maxval = 31)
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2222, "BACKTEST STOP YEAR", minval=1980, maxval = 2222)
testStopMonth = input(12, "BACKTEST STOP MONTH", minval=1, maxval=12)
testStopDay = input(31, "BACKTEST STOP DAY", minval=1, maxval=31)
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod = true

SOURCE = input(hlc3)
RSILENGTH = input(14, title = "RSI LENGTH")
RSICENTERLINE = input(52, title = "RSI CENTER LINE")
MACDFASTLENGTH = input(7, title = "MACD FAST LENGTH")
MACDSLOWLENGTH = input(12, title = "MACD SLOW LENGTH")
MACDSIGNALSMOOTHING = input(12, title = "MACD SIGNAL SMOOTHING")
a = input(10, title = "Key Vaule. 'This changes the sensitivity'") 
SmoothK = input(3)
SmoothD = input(3)
LengthRSI = input(14)
LengthStoch = input(14)
RSISource = input(close) 
c = input(10, title="ATR Period")
xATR = atr(c)
nLoss = a * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
     iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), 
     iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos =	iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
     iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 
color = pos == -1 ? red: pos == 1 ? green : blue 
ema= ema(close,1)
above = crossover(ema,xATRTrailingStop )
below = crossover(xATRTrailingStop,ema)
buy = close > xATRTrailingStop and above 
sell = close < xATRTrailingStop and below
barbuy = close > xATRTrailingStop 
barsell = close < xATRTrailingStop 
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= green,textcolor = white, transp = 0, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= red,textcolor = white, transp = 0, size = size.tiny)
barcolor(barbuy? green:na)
barcolor(barsell? red:na)
//alertcondition(buy, title='Buy', message='Buy')
//alertcondition(sell, title='Sell', message='Sell')

if (buy)
    strategy.entry("UTBotBuy",strategy.long, when=testPeriod)
if (sell)
    strategy.entry("UTBotSell",strategy.short, when=testPeriod)

Lebih lanjut