
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 các chỉ số SuperTrend và chỉ số ngẫu nhiên (Stochastic Oscillator). Chiến lược này xác định hướng xu hướng thị trường thông qua các chỉ số SuperTrend, đồng thời sử dụng tín hiệu mua quá mức của các chỉ số ngẫu nhiên làm tín hiệu xác nhận giao dịch. Chiến lược sử dụng phương pháp chéo động lực để tìm kiếm thời gian vào và ra khỏi tốt nhất theo hướng xu hướng, thực hiện sự kết hợp hoàn hảo của theo dõi xu hướng với phân tích động lực.
Lý luận cốt lõi của chiến lược này dựa trên sự kết hợp của hai chỉ số chính:
Các quy tắc giao dịch là:
Chiến lược này kết hợp theo dõi xu hướng và phân tích động lực để xây dựng một hệ thống giao dịch hoàn chỉnh hơn. Nó không chỉ cung cấp tín hiệu nhập cảnh và xuất cảnh rõ ràng, mà còn bao gồm cả cơ sở quản lý rủi ro và tối ưu hóa tham số. Mặc dù có một số rủi ro vốn có, nhưng bằng cách cung cấp các đề xuất tối ưu hóa, bạn có thể nâng cao hơn nữa sự ổn định và thích ứng của chiến lược.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-01 00:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SuperTrend + Stochastic Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// SuperTrend Settings
superTrendFactor = input.float(3.0, title="SuperTrend Factor", step=0.1)
superTrendATRLength = input.int(10, title="SuperTrend ATR Length")
// Calculate SuperTrend
[superTrend, direction] = ta.supertrend(superTrendFactor, superTrendATRLength)
// Plot SuperTrend
plot(superTrend, color=direction == 1 ? color.green : color.red, title="SuperTrend")
bgcolor(direction == 1 ? color.new(color.green, 90) : color.new(color.red, 90), transp=90)
// Stochastic Settings
stochKLength = input.int(14, title="Stochastic %K Length")
stochDLength = input.int(3, title="Stochastic %D Length")
stochSmoothK = input.int(3, title="Stochastic %K Smoothing")
stochOverbought = input.int(80, title="Stochastic Overbought Level")
stochOversold = input.int(20, title="Stochastic Oversold Level")
// Calculate Stochastic
k = ta.sma(ta.stoch(close, high, low, stochKLength), stochSmoothK)
d = ta.sma(k, stochDLength)
// Plot Stochastic in separate pane
hline(stochOverbought, "Overbought", color=color.red)
hline(stochOversold, "Oversold", color=color.green)
plot(k, color=color.blue, title="%K", linewidth=2)
plot(d, color=color.orange, title="%D", linewidth=2)
// Long Condition: SuperTrend is up and Stochastic %K crosses above oversold
longCondition = direction == 1 and ta.crossover(k, stochOversold)
if (longCondition)
strategy.entry("Long", strategy.long)
// Short Condition: SuperTrend is down and Stochastic %K crosses below overbought
shortCondition = direction == -1 and ta.crossunder(k, stochOverbought)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit Long: SuperTrend turns down or Stochastic %K crosses below overbought
exitLong = direction == -1 or ta.crossunder(k, stochOverbought)
if (exitLong)
strategy.close("Long")
// Exit Short: SuperTrend turns up or Stochastic %K crosses above oversold
exitShort = direction == 1 or ta.crossover(k, stochOversold)
if (exitShort)
strategy.close("Short")