Xu hướng tăng dựa trên chỉ số RSI theo chiến lược

Tác giả:ChaoZhang, Ngày: 2023-12-25 14:32:19
Tags:

img

Tổng quan

Chiến lược này được thiết kế dựa trên chỉ số chỉ số sức mạnh tương đối (RSI) để mua tại các điểm thấp của RSI và lấy lợi nhuận và dừng lỗ tại các điểm cao của RSI. Nó tạo ra tín hiệu mua khi RSI giảm xuống dưới đường bán quá mức và bán tín hiệu khi RSI tăng lên trên đường mua quá mức. Chiến lược được tối ưu hóa để theo dõi xu hướng với kiểm soát rủi ro hiệu quả.

Chiến lược logic

Chiến lược này sử dụng chỉ số RSI để xác định xem một cổ phiếu có được định giá quá cao hay thấp. RSI kết hợp với các đường mua quá cao và bán quá cao tạo thành tín hiệu mua và bán. Cụ thể, nếu RSI vượt trên đường bán quá cao 20, một tín hiệu mua sẽ được tạo ra; nếu RSI vượt dưới đường mua quá cao 80, một tín hiệu bán sẽ được tạo ra.

Sau khi nhập vào một vị trí dài, chiến lược thiết lập một mức dừng lỗ ban đầu để kiểm soát rủi ro giảm giá. Đồng thời, hai đường lấy lợi nhuận với tỷ lệ khác nhau được thiết lập để lấy lợi nhuận theo lô và khóa lợi nhuận. Cụ thể, 50% vị trí sẽ lấy lợi nhuận đầu tiên ở mức 3% trên giá nhập cảnh; sau đó, vị trí 50% còn lại sẽ lấy lợi nhuận ở mức 5% trên giá nhập cảnh.

Chiến lược sử dụng hiệu quả chỉ số RSI để xác định thời gian nhập cảnh.

Ưu điểm

  • Sử dụng chỉ số RSI để xác định các vị trí dài / ngắn và tránh giao dịch mù quáng
  • Các thông số RSI được tối ưu hóa để có hiệu ứng chỉ số tốt hơn
  • Thiết kế lấy lợi nhuận kép hợp lý cho phép lấy lợi nhuận theo lô để khóa nhiều lợi nhuận hơn
  • Stop Loss ban đầu và trailing stop loss ngăn ngừa tổn thất lớn

Rủi ro

  • Hiệu suất kém trong thị trường tăng mà không thể duy trì lợi nhuận
  • Có khả năng các tín hiệu không chính xác từ RSI tồn tại và có thể làm tăng tổn thất do đánh giá tín hiệu không chính xác
  • Rủi ro không thể kích hoạt lệnh dừng nếu các điểm dừng lỗ được đặt quá sâu
  • Rủi ro mất mát tăng cường không giới hạn về thời gian và tỷ lệ kim tự tháp

Cải tiến

  • Thêm các chỉ số khác để lọc các tín hiệu RSI và cải thiện độ chính xác
  • Đặt giới hạn về thời gian và tỷ lệ kim tự tháp
  • Hiệu ứng thử nghiệm của các thông số RSI khác nhau
  • Tối ưu hóa stop loss và lấy điểm lợi nhuận để giảm rủi ro

Tóm lại

Chiến lược sử dụng chỉ số RSI để đánh giá tình trạng thị trường và có cấu hình dừng lỗ và lấy lợi nhuận hợp lý. Nó có thể xác định hiệu quả xu hướng thị trường và kiểm soát rủi ro giao dịch, phù hợp với xu hướng tăng theo chiến lược.


/*backtest
start: 2023-12-17 00:00:00
end: 2023-12-24 00:00:00
period: 1m
basePeriod: 1m
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/

//@version=5

strategy(title='RSI Long Strategy', overlay=true, pyramiding=5, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.075)
strat_dir_input = input.string(title='Strategy Direction', defval='long', options=['long', 'short', 'all'])
strat_dir_value = strat_dir_input == 'long' ? strategy.direction.long : strat_dir_input == 'short' ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
//INPUTS


length = input(21)
overSold = input(20)
overBought = input(80)
p = close

vrsi = ta.rsi(p, length)
price = close
var bool long = na
var bool short = na

long := ta.crossover(vrsi, overSold)
short := ta.crossunder(vrsi, overBought)

var float last_open_long = na
var float last_open_short = na

last_open_long := long ? close : nz(last_open_long[1])
last_open_short := short ? close : nz(last_open_short[1])
mpoint=(last_open_long+last_open_short)/2

entry_value = last_open_long
entry_value1 = last_open_short

// Rounding levels to min tick
nround(x) =>
    n = math.round(x / syminfo.mintick) * syminfo.mintick
    n
//
disp_panels = input(true, title='Display info panels?')
fibs_label_off = input(40, title='fibs label offset')
fibs_label_size = input.string(size.normal, options=[size.tiny, size.small, size.normal, size.large, size.huge], title='fibs label size')
r1_x = timenow + math.round(ta.change(time) * fibs_label_off)
r1_y = last_open_short
text1 = 'High : ' + str.tostring(nround(last_open_short))
s1_y = last_open_long
text3 = 'low : ' + str.tostring(nround(last_open_long))

R1_label = disp_panels ? label.new(x=r1_x, y=r1_y, text=text1, xloc=xloc.bar_time, yloc=yloc.price, color=color.orange, style=label.style_label_down, textcolor=color.black, size=fibs_label_size) : na
S1_label = disp_panels ? label.new(x=r1_x, y=s1_y, text=text3, xloc=xloc.bar_time, yloc=yloc.price, color=color.lime, style=label.style_label_up, textcolor=color.black, size=fibs_label_size) : na

label.delete(R1_label[1])
label.delete(S1_label[1])
//
plot(mpoint, title='avreage', color=color.new(color.red, 40), style=plot.style_linebr, linewidth=3, trackprice=true, offset=-9999)
plot(last_open_short, title='high', color=color.new(color.red, 40), style=plot.style_linebr, linewidth=3, trackprice=true, offset=-9999)
plot(last_open_long, title='low', color=color.new(color.blue, 40), style=plot.style_linebr, linewidth=3, trackprice=true, offset=-9999)
//
trend = input(false)
if barstate.islast and trend == true
    line z = line.new(bar_index[1], last_open_short[1], bar_index, last_open_short, extend=extend.both, color=color.red, style=line.style_dashed, width=1)
    line f = line.new(bar_index[1], mpoint[1], bar_index, mpoint, extend=extend.both, color=color.blue, style=line.style_dashed, width=1)
    line w = line.new(bar_index[1], last_open_long[1], bar_index, last_open_long, extend=extend.both, color=color.green, style=line.style_dashed, width=1)
    line.delete(z[1])
    line.delete(f[1])
    line.delete(w[1])
    
//bu = ta.crossover(close, mpoint)
//sz = ta.crossunder(close, mpoint)
//bu1 = ta.crossover(close, last_open_short)
sz1 = ta.crossunder(close, last_open_short)
bu2 = ta.crossover(close, last_open_long)
//sz2 = ta.crossunder(close, last_open_long)
//plotshape(sz, style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0), size=size.tiny)
//plotshape(bu, style=shape.triangleup, location=location.belowbar, color=color.new(color.blue, 0), size=size.tiny)
//plotshape(sz1, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny)
//plotshape(bu1, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny)
//plotshape(sz2, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny)
//plotshape(bu2, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny)

l = bu2
s = sz1 
if l
    strategy.entry('buy', strategy.long)
if s
    strategy.entry('sell', strategy.short)
per(pcnt) =>
    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)
stoploss = input.float(title=' stop loss', defval=5, minval=0.01)
los = per(stoploss)
q1 = input.int(title=' qty_percent1', defval=50, minval=1)
q2 = input.int(title=' qty_percent2', defval=50, minval=1)
tp1 = input.float(title=' Take profit1', defval=3, minval=0.01)
tp2 = input.float(title=' Take profit2', defval=5, minval=0.01)
//tp4 = input.float(title=' Take profit4', defval=5, minval=0.01)
strategy.exit('x1', qty_percent=q1, profit=per(tp1), loss=los)
strategy.exit('x2', qty_percent=q2, profit=per(tp2), loss=los)



Thêm nữa