Chiến lược đảo ngược-bắt

Tác giả:ChaoZhang, Ngày: 2023-11-24 16:43:25
Tags:

img

Tổng quan

Chiến lược Reversal-Catcher là một chiến lược giao dịch đảo ngược sử dụng chỉ số biến động Bollinger Bands và chỉ số động lực RSI. Nó thiết lập kênh Bollinger Bands và các đường mua quá mức / bán quá mức RSI như là tín hiệu để tìm cơ hội đảo ngược khi hướng xu hướng thay đổi.

Chiến lược logic

Chiến lược sử dụng Bollinger Bands làm chỉ số kỹ thuật chính, kết hợp với RSI và các chỉ số đà khác để xác minh tín hiệu giao dịch.

  1. Sử dụng EMA 50 ngày và EMA 21 ngày chéo vàng / chéo chết để xác định xu hướng.
  2. Trong một xu hướng giảm, khi giá vượt qua Bollinger Lower Band, và RSI chỉ bật trở lại từ khu vực bán quá mức, tạo thành một thánh giá vàng, nó cho thấy khu vực bán quá mức đã chạm đáy, cho tín hiệu mua.
  3. Trong một xu hướng tăng, khi giá phá vỡ dưới Bollinger Upper Band, và RSI giảm trở lại từ khu vực mua quá mức, tạo thành một đường chéo chết, nó cho thấy khu vực mua quá mức bắt đầu quay trở lại, cung cấp tín hiệu bán.
  4. Các tín hiệu mua và bán trên phải được kích hoạt cùng nhau để tránh các tín hiệu sai.

Phân tích lợi thế

Những lợi thế của chiến lược này bao gồm:

  1. Kết hợp các chỉ số biến động và động lực làm cho tín hiệu đáng tin cậy hơn.
  2. Giao dịch đảo ngược có rủi ro thấp hơn, phù hợp với giao dịch ngắn hạn.
  3. Các quy tắc giao dịch có thể lập trình cho giao dịch tự động.
  4. Kết hợp với giao dịch xu hướng tránh sự mở ra rối loạn trong quá trình củng cố thị trường.

Phân tích rủi ro

Những rủi ro của chiến lược này bao gồm:

  1. Bollinger Bands breakout rủi ro tín hiệu sai, cần lọc RSI.
  2. Rủi ro đảo ngược thất bại, cần dừng lỗ kịp thời.
  3. Rủi ro thời gian đảo ngược, có thể vào quá sớm hoặc bỏ lỡ điểm vào tốt nhất.

Để kiểm soát rủi ro, chúng ta có thể đặt mức dừng lỗ để hạn chế rủi ro và tối ưu hóa các thông số như thời gian Bollinger Bands hoặc số liệu RSI để cải thiện hiệu suất hệ thống.

Hướng dẫn tối ưu hóa

Các hướng tối ưu hóa chính bao gồm:

  1. Tối ưu hóa các thông số Bollinger Bands, điều chỉnh thời gian và độ lệch chuẩn để tìm thiết lập tối ưu.
  2. Tối ưu hóa thời gian trung bình động để xác định thời gian tốt nhất để đánh giá xu hướng.
  3. Điều chỉnh các thông số RSI để tìm ra phạm vi mua/bán quá tốt nhất.
  4. Thêm các chỉ số khác như KDJ, MACD để đa dạng hóa tín hiệu nhập cảnh.
  5. Giới thiệu các mô hình học máy để tìm các thông số tối ưu.

Kết luận

Chiến lược Reversal-Catcher là một chiến lược giao dịch ngắn hạn hiệu quả nói chung. Bằng cách kết hợp lọc xu hướng và tín hiệu đảo ngược, nó có thể tránh các tín hiệu sai trong quá trình củng cố thị trường và tránh chiến đấu chống lại xu hướng. Thông qua các tham số liên tục và tối ưu hóa mô hình, hiệu suất chiến lược tốt hơn có thể đạt được.


/*backtest
start: 2023-10-24 00:00:00
end: 2023-11-23 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This is an Open source work. Please do acknowledge in case you want to reuse whole or part of this code.
// Please see the documentation to know the details about this.

//@version=5
strategy('Strategy:Reversal-Catcher', shorttitle="Reversal-Catcher", overlay=true , currency=currency.NONE, initial_capital=100000)

// Inputs
src = input(close, title="Source (close, high, low, open etc.")

BBlength = input.int(defval=20, minval=1,title="Bollinger Period Length, default 20")
BBmult = input.float(defval=1.5, minval=1.0, maxval=4, step=0.1, title="Bollinger Bands Standard Deviation, default is 1.5")

fastMovingAvg = input.int(defval=21, minval=5,title="Fast Exponential Moving Average, default 21", group = "Trends")
slowMovingAvg = input.int(defval=50, minval=8,title="Slow Exponential Moving Average, default 50", group = "Trends")

rsiLenght = input.int(defval=14, title="RSI Lenght, default 14", group = "Momentum")
overbought = input.int(defval=70, title="Overbought limit (RSI), default 70", group = "Momentum")
oversold = input.int(defval=30, title="Oversold limit (RSI), default 30", group = "Momentum")

hide = input.bool(defval=true, title="Hide all plots and legends from the chart (default: true)")


// Trade related
tradeType = input.string(defval='Both', group="Trade settings", title="Trade Type", options=['Both', 'TrendFollowing', 'Reversal'], tooltip="Consider all types of trades? Or only Trend Following or only Reversal? (default: Both).")
endOfDay = input.int(defval=1500, title="Close all trades, default is 3:00 PM, 1500 hours (integer)", group="Trade settings")
mktAlwaysOn = input.bool(defval=false, title="Markets that never closed (Crypto, Forex, Commodity)", tooltip="Some markers never closes. For those cases, make this checked. (Default: off)", group="Trade settings")


// Utils
annotatePlots(txt, val, hide) => 
    if (not hide)
        var l1 = label.new(bar_index, val, txt, style=label.style_label_left, size = size.tiny, textcolor = color.white, tooltip = txt)
        label.set_xy(l1, bar_index, val)

/////////////////////////////// Indicators /////////////////////
vwap = ta.vwap(src)
plot(hide ? na : vwap, color=color.purple, title="VWAP", style = plot.style_line)
annotatePlots('VWAP', vwap, hide)

// Bollinger Band of present time frame
[BBbasis, BBupper, BBlower] = ta.bb(src, BBlength, BBmult)
p1 = plot(hide ? na : BBupper, color=color.blue,title="Bollinger Bands Upper Line")
p2 = plot(hide ? na : BBlower, color=color.blue,title="Bollinger Bands Lower Line")
p3 = plot(hide ? na : BBbasis, color=color.maroon,title="Bollinger Bands Width", style=plot.style_circles, linewidth = 1)
annotatePlots('BB-Upper', BBupper, hide)
annotatePlots('BB-Lower', BBlower, hide)
annotatePlots('BB-Base(20-SMA)', BBbasis, hide)

// RSI
rsi = ta.rsi(src, rsiLenght)

// Trend following
ema50 = ta.ema(src, slowMovingAvg)
ema21 = ta.ema(src, fastMovingAvg)
annotatePlots('21-EMA', ema21, hide)
annotatePlots('50-EMA', ema50, hide)


// Trend conditions
upTrend = ema21 > ema50 
downTrend = ema21 < ema50


// Condition to check Special Entry: HH_LL
// Long side:
hhLLong = barstate.isconfirmed and (low > low[1]) and (high > high[1]) and (close > high[1])
hhLLShort = barstate.isconfirmed and (low < low[1]) and (high < high[1]) and (close < low[1])

longCond =  barstate.isconfirmed and (high[1] < BBlower[1]) and (close > BBlower) and (close < BBupper) and hhLLong and ta.crossover(rsi, oversold) and downTrend
shortCond = barstate.isconfirmed and (low[1] > BBupper[1]) and (close < BBupper) and (close > BBlower) and hhLLShort and ta.crossunder(rsi, overbought) and upTrend

// Trade execute
h = hour(time('1'), syminfo.timezone)
m = minute(time('1'), syminfo.timezone)
hourVal = h * 100 + m
totalTrades = strategy.opentrades + strategy.closedtrades
if (mktAlwaysOn or (hourVal < endOfDay))
    // Entry
    var float sl = na
    var float target = na
    if (longCond)
        strategy.entry("enter long", strategy.long, 1, limit=na, stop=na, comment="Long[E]")
        sl := low[1]
        target := high >= BBbasis ? BBupper : BBbasis
        alert('Buy:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)
    if (shortCond)
        strategy.entry("enter short", strategy.short, 1, limit=na, stop=na, comment="Short[E]")
        sl := high[1]
        target := low <= BBbasis ? BBlower : BBbasis
        alert('Sell:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)

    // Exit: target or SL
    if ((close >= target) or (close <= sl))
        strategy.close("enter long", comment=close < sl ? "Long[SL]" : "Long[T]")
    if ((close <= target) or (close >= sl))
        strategy.close("enter short", comment=close > sl ? "Short[SL]" : "Short[T]")
else if (not mktAlwaysOn)
    // Close all open position at the end if Day
    strategy.close_all(comment = "EoD[Exit]", alert_message = "EoD Exit", immediately = true)


Thêm nữa