
Chiến lược này là một hệ thống giao dịch thông minh dựa trên chỉ số tương đối yếu ((RSI), kết hợp nhiều đường trung bình di chuyển và các chỉ số Bollinger Bands để giao dịch khi chọn bằng cách xác định các khu vực quá mua quá bán trên thị trường. Cốt lõi của chiến lược là xác nhận xu hướng thông qua các tín hiệu phá vỡ và lùi của RSI, kết hợp với các loại đường trung bình di chuyển khác nhau, để vận hành các băng tần hiệu quả. Chiến lược này có khả năng thích ứng mạnh mẽ, có thể điều chỉnh các tham số theo môi trường thị trường khác nhau.
Chiến lược sử dụng RSI 14 chu kỳ làm chỉ số cốt lõi để tạo ra tín hiệu giao dịch bằng cách theo dõi sự giao thoa giữa RSI và hai mức quan trọng 30⁄70. Khi RSI vượt quá 30, hệ thống cho rằng thị trường chuyển từ bán tháo sang bán tháo, gây ra nhiều tín hiệu. Khi RSI giảm xuống dưới 70, hệ thống đánh giá thị trường chuyển từ mua tháo sang mua, gây ra tín hiệu cân bằng.
Chiến lược này nắm bắt cơ hội quá mua quá bán thị trường thông qua chỉ số RSI, kết hợp với nhiều chỉ số kỹ thuật để xác nhận tín hiệu, có tính thực tế và độ tin cậy tốt hơn. Thiết kế chiến lược xem xét đầy đủ kiểm soát rủi ro, có thể thích ứng với các môi trường thị trường khác nhau thông qua tối ưu hóa tham số và kết hợp các chỉ số.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Demo GPT - Relative Strength Index", shorttitle="RSI Strategy", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.1, slippage=3)
// Inputs
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
calculateDivergence = input.bool(false, title="Calculate Divergence", group="RSI Settings", tooltip="Calculating divergences is needed in order for divergence alerts to fire.")
// RSI Calculation
change = ta.change(rsiSourceInput)
up = ta.rma(math.max(change, 0), rsiLengthInput)
down = ta.rma(-math.min(change, 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
// RSI Plots
rsiPlot = plot(rsi, "RSI", color=#7E57C2)
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
plot(50, color=na, editable=false, display=display.none)
// Moving Averages
maTypeInput = input.string("SMA", "Type", options=["None", "SMA", "SMA + Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving Average")
maLengthInput = input.int(14, "Length", group="Moving Average")
bbMultInput = input.float(2.0, "BB StdDev", minval=0.001, maxval=50, step=0.5, group="Moving Average")
enableMA = maTypeInput != "None"
isBB = maTypeInput == "SMA + Bollinger Bands"
// MA Calculation
ma(source, length, MAtype) =>
switch MAtype
"SMA" => ta.sma(source, length)
"SMA + Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
smoothingMA = enableMA ? ma(rsi, maLengthInput, maTypeInput) : na
smoothingStDev = isBB ? ta.stdev(rsi, maLengthInput) * bbMultInput : na
plot(smoothingMA, "RSI-based MA", color=color.yellow, display=enableMA ? display.all : display.none)
bbUpperBand = plot(smoothingMA + smoothingStDev, title="Upper Bollinger Band", color=color.green, display=isBB ? display.all : display.none)
bbLowerBand = plot(smoothingMA - smoothingStDev, title="Lower Bollinger Band", color=color.green, display=isBB ? display.all : display.none)
fill(bbUpperBand, bbLowerBand, color=isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill", display=isBB ? display.all : display.none)
// Trade Logic
longCondition = ta.crossover(rsi, 30)
exitCondition = ta.crossunder(rsi, 70)
// Start Date & End Date
startDate = input(timestamp("2018-01-01 00:00"), "Start Date", group="Date Range")
endDate = input(timestamp("2069-12-31 23:59"), "End Date", group="Date Range")
inDateRange = true
// Execute Trades
if (longCondition and inDateRange)
strategy.entry("Long", strategy.long)
if (exitCondition and inDateRange)
strategy.close("Long")