
Chiến lược này là một hệ thống giao dịch đa chiều kết hợp theo dõi xu hướng, chỉ số động lực và dừng lỗ thích ứng. Chiến lược xác định hướng xu hướng thị trường thông qua chỉ số SuperTrend, đồng thời xác nhận giao dịch kết hợp với chỉ số động lực RSI và hệ thống đường trung bình, và sử dụng chỉ số biến động ATR để thực hiện quản lý dừng lỗ động. Phương pháp phân tích đa chiều này có thể nắm bắt hiệu quả xu hướng thị trường, đồng thời kiểm soát rủi ro một cách hợp lý.
Logic cốt lõi của chiến lược này dựa trên ba chiều sau:
Các điều kiện mua phải được đáp ứng đồng thời: SuperTrend bullish ((màu xanh) + RSI <65 + giá trên đường trung bình 50 chu kỳ. Điều kiện bán: Khi SuperTrend chuyển sang giảm giá. Quản lý dừng: sử dụng dừng theo dõi dựa trên ATR, dừng khoảng cách gấp 1,5 lần giá trị ATR.
Chiến lược này xây dựng một hệ thống giao dịch logic hoàn chỉnh bằng cách sử dụng tổng hợp theo dõi xu hướng, động lực và hệ thống đường thẳng. Ưu điểm của chiến lược là cơ chế xác nhận tín hiệu đa chiều và hệ thống kiểm soát rủi ro hoàn hảo.
/*backtest
start: 2025-01-08 00:00:00
end: 2025-02-07 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Gladston_J_G
//@version=5
strategy("Trend Strategy with Stop Loss", overlay=true, margin_long=100, margin_short=100)
// ———— Inputs ———— //
atrLength = input(14, "ATR Length")
supertrendMultiplier = input(3.0, "Supertrend Multiplier")
rsiLength = input(14, "RSI Length")
maLength = input(50, "MA Length")
trailOffset = input(1.5, "Trailing Stop ATR Multiplier")
// ———— Indicators ———— //
// Supertrend for trend direction
[supertrend, direction] = ta.supertrend(supertrendMultiplier, atrLength)
// RSI for momentum filter
rsi = ta.rsi(close, rsiLength)
// Moving Average for trend confirmation
ma = ta.sma(close, maLength)
// ATR for volatility-based stop loss
atr = ta.atr(atrLength)
// ———— Strategy Logic ———— //
// Buy Signal: Supertrend bullish + RSI not overbought + Price above MA
buyCondition = direction < 0 and rsi < 65 and close > ma
// Sell Signal: Supertrend turns bearish
sellCondition = direction > 0
// ———— Stop Loss & Trailing ———— //
stopPrice = close - (atr * trailOffset)
var float trail = na
if buyCondition and strategy.position_size == 0
trail := stopPrice
else
trail := math.max(stopPrice, nz(trail[1]))
// ———— Execute Orders ———— //
strategy.entry("Long", strategy.long, when=buyCondition)
strategy.close("Long", when=sellCondition)
strategy.exit("Trail Exit", "Long", stop=trail)
// ———— Visuals ———— //
plot(supertrend, "Supertrend", color=direction < 0 ? color.green : color.red)
plot(ma, "MA", color=color.blue)
plot(strategy.position_size > 0 ? trail : na, "Trailing Stop", color=color.orange, style=plot.style_linebr)
// ———— Alerts ———— //
plotshape(buyCondition, "Buy", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(sellCondition, "Sell", shape.triangledown, location.abovebar, color.red, size=size.small)
plot(close)