Chiến lược RSI-Bollinger Band để nắm bắt biến động

Tác giả:ChaoZhang, Ngày: 2023-12-01 14:17:55
Tags:

img

Tổng quan

Chiến lược RSI-Bollinger Band nắm bắt biến động là một chiến lược giao dịch tích hợp các khái niệm Bollinger Bands (BB), Chỉ số sức mạnh tương đối (RSI) và Trung bình di chuyển đơn giản (SMA) để tạo ra các tín hiệu giao dịch.

Các thị trường tiền điện tử và chứng khoán rất biến động, làm cho chúng phù hợp với một chiến lược sử dụng Bollinger Bands.

Làm thế nào nó hoạt động

Phạm vi Bollinger động: Chiến lược đầu tiên tính toán các Phạm vi Bollinger trên và dưới dựa trên chiều dài và nhân được xác định bởi người dùng. Sau đó nó sử dụng các Phạm vi Bollinger và giá đóng để điều chỉnh động giá trị BollingBand hiện tại. Cuối cùng, nó tạo ra một tín hiệu dài khi giá vượt qua Phạm vi Bolling hiện tại và một tín hiệu ngắn khi giá vượt dưới.

RSI: Nếu người dùng chọn sử dụng RSI cho tín hiệu, chiến lược cũng tính toán RSI và SMA của nó và sử dụng chúng để tạo ra các tín hiệu dài và ngắn bổ sung.

Chiến lược sau đó kiểm tra hướng giao dịch đã chọn và nhập các vị trí dài hoặc ngắn theo đó.

Cuối cùng, chiến lược thoát khỏi một vị trí khi giá đóng vượt qua dưới/trên Bolling Band hiện tại cho các vị trí dài / ngắn tương ứng.

Phân tích lợi thế

Chiến lược kết hợp các điểm mạnh của Bollinger Bands, RSI và SMA để thích nghi với sự biến động của thị trường, nắm bắt biến động một cách năng động và tạo ra các tín hiệu giao dịch ở mức mua quá mức / bán quá mức.

Chỉ số RSI bổ sung cho các tín hiệu Bollinger, tránh các mục nhập sai trong các thị trường dao động.

Các tham số có thể tùy chỉnh cho phép điều chỉnh dựa trên sở thích rủi ro cá nhân.

Phân tích rủi ro

Chiến lược dựa trên các chỉ số kỹ thuật và không thể dự đoán sự đảo ngược lớn do các yếu tố cơ bản.

Cài đặt tham số Bollinger không chính xác có thể tạo ra tín hiệu quá thường xuyên hoặc quá thưa thớt.

Giao dịch hai chiều làm tăng rủi ro, hãy cẩn thận với những lỗ ngắn ngược.

Sử dụng dừng để kiểm soát rủi ro được khuyến cáo.

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

  1. Thêm các bộ lọc khác như MACD để lọc tín hiệu.

  2. Bao gồm các chiến lược dừng lỗ.

  3. Tối ưu hóa các thông số Bollinger và RSI.

  4. Điều chỉnh các thông số cho các sản phẩm và khung thời gian khác nhau.

  5. Xem xét các thông số điều chỉnh trực tiếp để phù hợp với điều kiện thực tế.

Tóm lại

Chiến lược RSI-Bollinger nắm bắt biến động là một chiến lược dựa trên chỉ số kỹ thuật, kết hợp các điểm mạnh của Bollinger Bands, RSI và SMA bằng cách điều chỉnh năng động các Bollinger Bands để nắm bắt biến động thị trường. Chiến lược cho phép tùy biến và tối ưu hóa cao nhưng không thể dự đoán những thay đổi cơ bản.


/*backtest
start: 2023-11-23 00:00:00
end: 2023-11-30 00:00:00
period: 15m
basePeriod: 5m
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/
// © PresentTrading

//@version=5
// Define the strategy settings
strategy('Volatility Capture RSI-Bollinger - Strategy [presentTrading]', overlay=true)

// Define the input parameters for the indicator
priceSource  = input.source(title='Source', defval=hlc3, group='presentBollingBand') // The price source to use
lengthParam   = input.int(50, 'lengthParam', minval=1, group='presentBollingBand') // The length of the moving average
multiplier = input.float(2.7183, 'Multiplier', minval=0.1, step=.1, group='presentBollingBand') // The multiplier for the ATR
useRSI = input.bool(true, 'Use RSI for signals', group='presentBollingBand') // Boolean input to decide whether to use RSI for signals
rsiPeriod = input.int(10, 'RSI Period', minval=1, group='presentBollingBand') // The period for the RSI calculation
smaPeriod = input.int(5, 'SMA Period', minval=1, group='presentBollingBand') // The period for the SMA calculation
boughtRange = input.float(55, 'Bought Range Level', minval=1, group='presentBollingBand') // The level for the bought range
soldRange = input.float(50, 'Sold Range Level', minval=1, group='presentBollingBand') // The level for the sold range

// Add a parameter for choosing Long or Short
tradeDirection = input.string("Both", "Trade Direction", options=["Long", "Short", "Both"], group='presentBollingBand') // Dropdown input for trade direction

// Calculate the bollingerBand
barIndex = bar_index // The current bar index
upperBollingerBand = ta.sma(high, lengthParam) + ta.stdev(high, lengthParam) * multiplier // Calculate the upper Bollinger Band
lowerBollingerBand = ta.sma(low, lengthParam) - ta.stdev(low, lengthParam) * multiplier // Calculate the lower Bollinger Band

var float presentBollingBand = na // Initialize the presentBollingBand variable
crossCount = 0 // Initialize the crossCount variable

// Calculate the buy and sell signals
longSignal1 = ta.crossover(priceSource, presentBollingBand) // Calculate the long signal
shortSignal1 = ta.crossunder(priceSource, presentBollingBand) // Calculate the short signal

// Calculate the RSI
rsiValue = ta.rsi(priceSource, rsiPeriod) // Calculate the RSI value
rsiSmaValue = ta.sma(rsiValue, smaPeriod) // Calculate the SMA of the RSI value

// Calculate the buy and sell signals
longSignal2 = rsiSmaValue > boughtRange // Calculate the long signal based on the RSI SMA
shortSignal2 = rsiSmaValue < soldRange // Calculate the short signal based on the RSI SMA

presentBollingBand := na(lowerBollingerBand) or na(upperBollingerBand)?0.0 : close>presentBollingBand?math.max(presentBollingBand,lowerBollingerBand) : close<presentBollingBand?math.min(presentBollingBand,upperBollingerBand) : 0.0


if (tradeDirection == "Long" or tradeDirection == "Both") and longSignal1 and (useRSI ? longSignal2 : true) // Use RSI for signals if useRSI is true
    presentBollingBand := lowerBollingerBand // If the trade direction is "Long" or "Both", and the long signal is true, and either useRSI is false or the long signal based on RSI is true, then assign the lowerBollingerBand to the presentBollingBand.
    strategy.entry("Long", strategy.long) // Enter a long position.

if (tradeDirection == "Short" or tradeDirection == "Both") and shortSignal1 and (useRSI ? shortSignal2 : true) // Use RSI for signals if useRSI is true
    presentBollingBand := upperBollingerBand // If the trade direction is "Short" or "Both", and the short signal is true, and either useRSI is false or the short signal based on RSI is true, then assign the upperBollingerBand to the presentBollingBand.
    strategy.entry("Short", strategy.short) // Enter a short position.

// Exit condition
if (strategy.position_size > 0 and ta.crossunder(close, presentBollingBand)) // If the strategy has a long position and the close price crosses under the presentBollingBand, then close the long position.
    strategy.close("Long")
if (strategy.position_size < 0 and ta.crossover(close, presentBollingBand)) // If the strategy has a short position and the close price crosses over the presentBollingBand, then close the short position.
    strategy.close("Short")

//~~ Plot
plot(presentBollingBand,"presentBollingBand", color=color.blue) // Plot the presentBollingBand on the chart.

Thêm nữa