
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng kết hợp hai đường trung bình và chỉ số RSI ngẫu nhiên. Xác định xu hướng thị trường thông qua đường trung bình di chuyển đơn giản 21 chu kỳ và chu kỳ 55, sử dụng các RSI ngẫu nhiên để tìm kiếm các điểm vào và điểm ra tốt nhất trong khu vực mua quá mức để tối ưu hóa giao dịch theo xu hướng.
Chiến lược này dựa trên logic cốt lõi sau:
Chiến lược này được xây dựng bằng cách kết hợp các chỉ số kỹ thuật cổ điển để xây dựng một hệ thống giao dịch theo dõi xu hướng hoàn chỉnh. Chiến lược này được tăng cường độ tin cậy bằng cách xác nhận nhiều tín hiệu trong khi vẫn đơn giản và trực quan. Với sự tối ưu hóa tham số hợp lý và quản lý rủi ro, chiến lược này có giá trị thực tế tốt.
/*backtest
start: 2022-02-11 00:00:00
end: 2025-02-08 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("SMA & Stoch RSI Buy Strategy with K > 80 Exit", overlay=true)
// Input parameters for the SMAs
sma21Length = input(21, title="21 SMA Length")
sma55Length = input(55, title="55 SMA Length")
// Input parameters for the Stochastic RSI
stochRsiLength = input(14, title="Stoch RSI Length")
stochRsiK = input(3, title="Stoch RSI %K Smoothing")
stochRsiD = input(3, title="Stoch RSI %D Smoothing")
// Calculate the SMAs
sma21 = ta.sma(close, sma21Length)
sma55 = ta.sma(close, sma55Length)
// Calculate the Stochastic RSI
rsiValue = ta.rsi(close, stochRsiLength)
stochRsi = ta.stoch(rsiValue, rsiValue, rsiValue, stochRsiLength)
stochRsiKLine = ta.sma(stochRsi, stochRsiK)
stochRsiDLine = ta.sma(stochRsiKLine, stochRsiD)
// Buy signal conditions
smaCondition = sma21 > sma55
stochRsiCondition = ta.crossover(stochRsiKLine, stochRsiDLine) and stochRsiKLine < 20
// Entry condition
buySignal = smaCondition and stochRsiCondition
// Exit condition: Stochastic RSI K > 80 and K crosses below D
exitCondition = ta.crossunder(stochRsiKLine, stochRsiDLine) and stochRsiKLine > 80
// Execute buy order on signal
if (buySignal)
strategy.entry("Buy", strategy.long)
// Exit the trade on the modified exit condition
if (exitCondition)
strategy.close("Buy")
// Plot the SMAs
plot(sma21, color=color.blue, title="21 SMA")
plot(sma55, color=color.red, title="55 SMA")
// Plot Stochastic RSI for reference (not overlayed)
hline(20, "Stoch RSI 20", color=color.gray, linestyle=hline.style_dotted)
hline(80, "Stoch RSI 80", color=color.gray, linestyle=hline.style_dotted)
plot(stochRsiKLine, title="%K Line", color=color.green)
plot(stochRsiDLine, title="%D Line", color=color.red)