RSI Moving Average Trailing Stop chiến lược

Tác giả:ChaoZhang, Ngày: 2023-09-13 14:26:43
Tags:

Chiến lược này kết hợp chỉ số RSI và trung bình động cho thiên hướng xu hướng và thêm các điểm dừng để quản lý rủi ro.

Chiến lược logic:

  1. Tính toán chỉ số RSI để đánh giá mức mua quá mức / bán quá mức.

  2. Tính toán các đường trung bình di chuyển nhanh và chậm, chữ thập vàng báo hiệu xu hướng tăng.

  3. RSI tăng liên tục cũng báo hiệu bước vào dài.

  4. Sau khi nhập, đặt dừng lỗ và lấy lợi nhuận.

  5. Dừng đường mất mát dưới giá, lấy đường lợi nhuận trên.

  6. Ra khỏi khi giá dừng lại hoặc lấy lợi nhuận.

Ưu điểm:

  1. RSI tránh theo đuổi đỉnh và đáy.

  2. Đường trung bình động xác định hướng xu hướng. Sự kết hợp cải thiện độ chính xác.

  3. Trailing dừng lại / lợi nhuận điều chỉnh năng động theo giá.

Rủi ro:

  1. RSI và MAs dễ bị tín hiệu sai trong các thị trường dao động.

  2. Chiều rộng dừng phía sau đòi hỏi hiệu chuẩn thận trọng, quá rộng hoặc quá hẹp là vấn đề.

  3. Không thể giới hạn kích thước lỗ, có nguy cơ thua lỗ lớn.

Tóm lại, chiến lược này kết hợp RSI và MAs sau đó sử dụng trailing stops để quản lý rủi ro. Với tối ưu hóa mạnh mẽ và kiểm soát rủi ro, nó có thể đạt được kết quả tốt.


/*backtest
start: 2022-09-06 00:00:00
end: 2023-09-12 00:00:00
period: 4d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI and MA Strategy with Trailing Stop Loss and Take Profit",
         overlay=true,
         initial_capital=1000,
         process_orders_on_close=true,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)
notInTrade = strategy.position_size <= 0

//==================================Buy Conditions============================================

//RSI
length = input(14)
rsi = ta.rsi(close, length)
buyCondition1 = rsi > 50

//MA
SMA9 = ta.sma(close, 9)
SMA50 = ta.sma(close, 50)
SMA100 = ta.sma(close, 100)
plot(SMA9, color = color.green)
plot(SMA50, color = color.orange)
plot(SMA100, color = color.blue)
buyCondition2 = SMA9 > SMA50//ta.crossover(SMA9, SMA100)

//RSI Increase
increase = 5
buyCondition3 = (rsi > rsi[1] + increase)


if (buyCondition1 and buyCondition2 and buyCondition3 and timePeriod) //and buyCondition
    strategy.entry("Long", strategy.long)

//==================================Sell Conditions============================================

//Trailing Stop Loss and Take Profit
longTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=2) * 0.01
shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01

longStopPrice = 0.0
shortStopPrice = 0.0

longStopPrice := if strategy.position_size > 0
    stopValue = close * (1 - longTrailPerc)
    math.max(stopValue, longStopPrice[1])
else
    0

shortStopPrice := if strategy.position_size < 0
    stopValue = close * (1 + shortTrailPerc)
    math.min(stopValue, shortStopPrice[1])
else
    999999


strategy.exit(id="Exit", stop = longStopPrice, limit = shortStopPrice)

Thêm nữa