
Chiến lược này kết hợp các chỉ số siêu xu hướng và chỉ số Brin để nắm bắt cơ hội xu hướng của thị trường. Chỉ số siêu xu hướng được sử dụng để xác định xu hướng của thị trường hiện tại, trong khi chỉ số Brin được sử dụng để đo lường tỷ lệ biến động của thị trường.
Chiến lược kết hợp bẫy liên kết siêu xu hướng là một chiến lược theo dõi xu hướng, có thể nắm bắt cơ hội xu hướng một cách hiệu quả hơn bằng cách kết hợp hai yếu tố thị trường xu hướng và biến động. Tuy nhiên, chiến lược này cũng có một số hạn chế, chẳng hạn như nhạy cảm với tham số, tăng rủi ro trong môi trường biến động cao. Do đó, trong ứng dụng thực tế, chiến lược cũng cần được tối ưu hóa và cải tiến thích hợp theo đặc điểm của thị trường và sở thích rủi ro của riêng bạn.
/*backtest
start: 2024-03-21 00:00:00
end: 2024-03-28 00:00:00
period: 5m
basePeriod: 1m
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/
// © sabhiv27
//@version=4
strategy("Supertrend & Bollinger Bands Strategy", shorttitle="ST_BB_Strategy", overlay=true)
// Input options
factor = input(3, title="Supertrend Factor")
length = input(10, title="ATR Length")
bollinger_length = input(20, title="Bollinger Bands Length")
bollinger_deviation = input(2, title="Bollinger Bands Deviation")
// Calculate True Range for Supertrend
truerange = rma(tr, length)
// Calculate Supertrend
var float up_trend = na
var float dn_trend = na
var float trend = na
up_signal = hl2 - (factor * truerange)
dn_signal = hl2 + (factor * truerange)
up_trend := close[1] > up_trend[1] ? max(up_signal, up_trend[1]) : up_signal
dn_trend := close[1] < dn_trend[1] ? min(dn_signal, dn_trend[1]) : dn_signal
trend := close > dn_trend ? 1 : close < up_trend ? -1 : nz(trend[1], 1)
// Calculate Bollinger Bands
basis = sma(close, bollinger_length)
dev = stdev(close, bollinger_length)
upper_band = basis + bollinger_deviation * dev
lower_band = basis - bollinger_deviation * dev
// Entry conditions
long_condition = crossover(close, up_trend) and close < lower_band
short_condition = crossunder(close, dn_trend) and close > upper_band
// Exit conditions
exit_long_condition = crossover(close, dn_trend)
exit_short_condition = crossunder(close, up_trend)
// Plot Supertrend
plot(trend == 1 ? up_trend : dn_trend, color=trend == 1 ? color.green : color.red, linewidth=2)
// Plot Bollinger Bands
plot(upper_band, color=color.blue)
plot(lower_band, color=color.blue)
// Generate buy and sell signals
strategy.entry("Long", strategy.long, when=long_condition)
strategy.entry("Short", strategy.short, when=short_condition)
strategy.close("Long", when=exit_long_condition)
strategy.close("Short", when=exit_short_condition)