Triple SuperTrend dan Strategi RSI Stoch

Penulis:ChaoZhang, Tarikh: 2023-12-06 14:29:00
Tag:

img

Ringkasan

Strategi Triple SuperTrend dan Stoch RSI adalah strategi perdagangan kuantitatif yang menggabungkan trend pelbagai jangka masa berikut penunjuk SuperTrend dan isyarat overbought / oversold dari penunjuk Stoch RSI. Strategi ini menggunakan tiga penunjuk SuperTrend dengan tetapan parameter yang berbeza untuk menentukan trend pasaran dan menggabungkan isyarat Stoch RSI untuk menapis isyarat perdagangan. Khususnya, apabila dua penunjuk SuperTrend yang lebih cepat memberikan isyarat beli / jual serentak, jika penunjuk Stoch RSI mengesahkan, kedudukan panjang / pendek yang sesuai akan diambil.

Logika Strategi

Logik teras strategi Triple SuperTrend dan Stoch RSI adalah untuk menggabungkan penunjuk SuperTrend dengan parameter yang berbeza dan penunjuk Stoch RSI untuk penapisan isyarat perdagangan untuk meningkatkan kualiti isyarat dan mengurangkan isyarat palsu.

Pertama, strategi ini menggunakan tiga penunjuk SuperTrend dengan tetapan parameter yang berbeza untuk menentukan trend pasaran utama. Tiga penunjuk SuperTrend mempunyai parameter yang berkisar dari jangka masa yang cepat hingga lambat, untuk menangkap perubahan trend pada tahap yang berbeza. Apabila penunjuk SuperTrend yang paling cepat dan kedua paling cepat memberikan isyarat beli / jual serentak, kami membuat penilaian awal bahawa isyarat itu mempunyai kebolehpercayaan tertentu.

Kedua, penunjuk Stoch RSI diperkenalkan untuk menentukan sama ada pasaran terlalu banyak dibeli atau terlalu banyak dijual apabila isyarat berlaku. Penunjuk Stoch RSI menggabungkan kekuatan penunjuk RSI dan Stochastic, yang membolehkan penilaian yang berkesan mengenai keadaan pasaran yang terlalu banyak dibeli / terlalu banyak dijual. Apabila isyarat SuperTrend terpantas dan kedua terpantas sejajar dengan isyarat Stoch RSI, isyarat beli / jual akhir dapat dicetuskan.

Melalui gabungan pelbagai penunjuk dan jangka masa, strategi Triple SuperTrend dan Stoch RSI dapat menapis bunyi bising pasaran dengan berkesan, meningkatkan kebolehpercayaan isyarat, dan mengurangkan perdagangan yang salah.

Kelebihan Strategi

Kelebihan terbesar strategi Triple SuperTrend dan Stoch RSI terletak pada gabungan yang berkesan dari pelbagai penunjuk dan jangka masa, yang membawa manfaat berikut:

  1. Mengurangkan isyarat perdagangan yang salah. Gabungan tiga indikator SuperTrend dan Stoch RSI dapat mengurangkan bunyi bising dan isyarat palsu yang datang dengan indikator individu.

  2. Meningkatkan nisbah isyarat yang menguntungkan. Walaupun turun frekuensi isyarat, nisbah isyarat yang menguntungkan melihat peningkatan yang ketara.

  3. Sesuai untuk pasaran trend. Penapisan pelbagai jangka masa memudahkan menangkap trend jangka sederhana hingga panjang, sesuai dengan persekitaran pasaran trend dengan baik.

  4. Pengoptimuman mudah untuk prestasi yang lebih baik. Penunjuk tiga membolehkan kemungkinan yang lebih luas untuk pengoptimuman parameter.

  5. Parameter yang boleh disesuaikan untuk gaya perdagangan peribadi. Parameter boleh disesuaikan secara bebas untuk lebih sesuai dengan gaya perdagangan seseorang.

Risiko Strategi

Terdapat juga beberapa risiko yang berkaitan dengan strategi Triple SuperTrend dan Stoch RSI:

  1. Frekuensi isyarat yang berkurangan. Mekanisme penapis pelbagai lapisan mengurangkan kekerapan perdagangan strategi dengan ketara.

  2. Kecenderungan untuk terlepas beberapa isyarat yang berpotensi. sifat konservatif menjadikan strategi mungkin kehilangan beberapa peluang yang menguntungkan.

  3. Peningkatan pergantungan parameter. Lebih banyak penunjuk bermakna kesukaran yang lebih besar dalam pengoptimuman.

  4. Keupayaan mengikuti trend terhad. Gabungan pelbagai jangka masa juga mengehadkan fleksibiliti mengikuti trend strategi.

Untuk menangani risiko ini, langkah-langkah pengoptimuman seperti menyesuaikan parameter penunjuk dan memperkenalkan lebih banyak penunjuk tambahan boleh diterima pakai untuk meningkatkan kawalan risiko sambil meningkatkan kualiti keuntungan.

Arahan pengoptimuman

Masih ada ruang untuk pengoptimuman strategi Triple SuperTrend dan Stoch RSI:

  1. Sesuaikan parameter penunjuk untuk kombinasi terbaik. Set parameter yang lebih banyak boleh diuji untuk mencari yang optimum.

  2. Memperkenalkan stop loss / mengambil keuntungan untuk kawalan risiko yang lebih baik.

  3. Masukkan lebih banyak penunjuk untuk pengesahan isyarat, contohnya penunjuk jumlah.

  4. Membina keupayaan penyesuaian untuk mengoptimumkan parameter secara automatik mengikut dinamik pasaran yang berubah.

  5. Menggabungkan algoritma pembelajaran mesin untuk ramalan prestasi, menilai ketepatan isyarat.

Dengan pengoptimuman berterusan, strategi Triple SuperTrend dan Stoch RSI boleh berkembang menjadi sistem perdagangan yang stabil dan cekap, memberikan alpha yang cukup.

Kesimpulan

Strategi Triple SuperTrend dan Stoch RSI berjaya menggabungkan analisis pelbagai jangka masa dan penilaian overbought / oversold ke dalam strategi perdagangan berikut trend yang unik. Ia mengekalkan dua kelebihan trend berikut dan penapisan penunjuk, meningkatkan isyarat yang menguntungkan sambil mengurangkan isyarat palsu. Walaupun risiko dan ruang pengoptimuman masih wujud, keuntungan dan kestabihannya dapat ditingkatkan lagi melalui penyesuaian parameter dan pengoptimuman strategi. Secara keseluruhan, strategi Triple SuperTrend dan Stoch RSI menyediakan pilihan strategi perdagangan kuantitatif berkualiti tinggi.


/*backtest
start: 2022-11-29 00:00:00
end: 2023-04-17 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/
// © M3RZI

//@version=4
strategy("3x Supertrend and Stoch RSI", overlay = true, max_bars_back = 1000)

//INPUTS
STATRLENGTH1 = input(10, title = "Fast Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT1 = input(1, title = "Fast Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH2 = input(11, title = "Medium Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT2 = input(2, title = "Medium Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH3 = input(12, title = "Slow Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT3 = input(3, title = "Slow Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")

stochK = input(3, title = "K (Stochastic Fast)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochD = input(3, title = "D (Signal Line)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiLength = input(14, title = "RSI Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochLength = input(14, title = "Stochastic Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiSource = input(close, title = "RSI Source", type = input.source, group = "STOCHASTIC RSI SETTINGS")
stochRestrictions = input(false, title = "Restrict crosses to overbought/oversold territory", type = input.bool, group = "STOCHASTIC RSI SETTINGS")
overboughtLine = input(80, title = "Stochastic  RSI Upper Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
oversoldLine = input(20, title = "Stochastic RSI Lower Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")

EMALength  = input(200, title = "EMA Length", type = input.integer, group = "EMA SETTINGS")

SLStrategy = input("ATR Based", title = "Stop Loss Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
SLATRLength = input(14, title = "Stop Loss ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
SLATRMult = input(2.7, title = "Stop Loss ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")
TPStrategy = input("ATR Based", title = "Take Profit Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
TPATRLength = input(14, title = "Take Profit ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
TPATRMult = input(1.6, title = "Take Profit ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")

//SUPERTRENDS
[superTrend1,dir1] = supertrend(STATRMULT1,STATRLENGTH1)
[superTrend2,dir2] = supertrend(STATRMULT2,STATRLENGTH2)
[superTrend3,dir3] = supertrend(STATRMULT3,STATRLENGTH3)

directionST1 = dir1 == 1 and dir1[1] == 1 ? false : dir1 == -1 and dir1[1] == -1 ? true : na
directionST2 = dir2 == 1 and dir2[1] == 1 ? false : dir2 == -1 and dir2[1] == -1 ? true : na
directionST3 = dir3 == 1 and dir3[1] == 1 ? false : dir3 == -1 and dir3[1] == -1 ? true : na

//STOCH RSI
rsi = rsi(rsiSource, rsiLength)
k = sma(stoch(rsi, rsi, rsi, stochLength), stochK)
d = sma(k, stochD)

//EMA
ema = ema(close,EMALength)

//CONDITIONS LONG AND SHORT

var long = false
var longCondition = false
var short = false
var shortCondition = false
var drawing = false
var TP = 0.0
var SL = 0.0
var middle = 0.0
var initial = 0

stopSize = atr(SLATRLength) * SLATRMult
profitSize = atr(TPATRLength) * TPATRMult
longStop = close - stopSize
longProfit = close + profitSize
current = close
shortStop = close + stopSize
shortProfit = close - profitSize
barInitial = bar_index

if  stochRestrictions
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and k < oversoldLine and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and k > overboughtLine and not short and not drawing
else
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and not short and not drawing

if longCondition
    long := true
    short := false
    drawing := true
    TP := longProfit
    middle := current
    SL := longStop
    initial := barInitial
    strategy.entry("Long", strategy.long, 10)
    strategy.exit("Long exit","Long", limit = TP, stop = SL)
    alert("Long signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,low,text = "Long\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.belowbar, textcolor = color.white, color = color.green, size = size.small,  style = label.style_label_up)

if shortCondition
    short := true
    long := false
    drawing := true
    TP := shortProfit
    middle := current
    SL := shortStop
    initial := barInitial
    strategy.entry("Short", strategy.short, 10)
    strategy.exit("Short exit","Short",limit = TP , stop = SL)
    alert("Short signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,high,text = "Short\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.abovebar, textcolor = color.white, color = color.red, size = size.small,  style = label.style_label_down)

if long and (high[1] >= TP or low[1] <= SL)
    drawing := false
    long := false
    if high[1] >= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (Long)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_down)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (Long)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_up)

if short and (low[1] <= TP or high[1] >= SL)
    drawing :=  false
    short := false
    if low[1] <= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (short)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_up)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (short)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_down)

//STRATEGY
//strategy.entry("buy", strategy.long, 10, when = longCondition)
//strategy.exit("bracket", "buy",  10, limit = TP, stop = SL)
//strategy.entry("short", strategy.long, 10, when = shortCondition)
//strategy.exit("bracket", "short",  10, limit = TP, stop = SL)

//DRAWING
plotshape(longCondition, title = "Long Signal", location=location.belowbar, style=shape.labelup, color=color.green, textcolor=color.white, size=size.small, text="Long")
plotshape(shortCondition, title = "Short Signal", location=location.abovebar, style=shape.labeldown, color=color.red, textcolor=color.white, size=size.small, text="Short")
profitLine = plot(drawing and drawing[1] ? TP : na, title = "Take profit", color = color.green, style = plot.style_linebr)
currentLine =plot(drawing and drawing[1]  ? middle : na, title = "Middle Line", color = color.white, style = plot.style_linebr)
lossLine = plot(drawing and drawing[1]  ? SL : na, title = "Stop Loss", color = color.red, style = plot.style_linebr)
fill(currentLine,profitLine, title = "Profit Background" ,color = color.new(color.green,75))
fill(currentLine,lossLine, title = "Loss Background" ,color = color.new(color.red,75))
plot(superTrend1, title = "Fast Supertrend", color = dir1 == 1 and dir1[1] == 1 ? color.red : dir1 == -1 and dir1[1] == -1 ? color.green : na)
plot(superTrend2, title = "Medium Supertrend", color = dir2 == 1 and dir2[1] == 1 ? color.red : dir2 == -1 and dir2[1] == -1 ? color.green : na)
plot(superTrend3, title = "Slow Supertrend", color = dir3 == 1 and dir3[1] == 1 ? color.red : dir3 == -1 and dir3[1] == -1 ? color.green : na)
plot(ema, title = "EMA",color = color.yellow)
//plot(k, color = color.blue)
//plot(d, color = color.orange)
//h1 = hline(80)
//h2 = hline(20)
//fill(h1,h2, color = color.new(color.purple,60))




Lebih lanjut