Chiến lược này là một hệ thống giao dịch theo thời gian động dựa trên tỷ lệ biến động, kết hợp các đặc điểm của theo dõi xu hướng và quản lý rủi ro. Cốt lõi của chiến lược là xác định sự thay đổi của xu hướng thị trường thông qua kênh biến động, đồng thời giới thiệu cơ chế quản lý vị trí động dựa trên ATR để kiểm soát chính xác rủi ro giao dịch. Chiến lược này đặc biệt phù hợp để hoạt động trong môi trường thị trường biến động, có thể tự điều chỉnh vị trí giữ.
Logic cốt lõi của chiến lược này dựa trên các thành phần chính sau:
Đây là một hệ thống giao dịch hoàn chỉnh kết hợp biến động, theo dõi xu hướng và quản lý rủi ro. Chiến lược nắm bắt sự thay đổi xu hướng thông qua kênh biến động, đồng thời sử dụng phương pháp quản lý tài chính khoa học để kiểm soát rủi ro. Mặc dù có thể không hoạt động tốt trong thị trường xung đột, nhưng nó có thể hoạt động ổn định trong hầu hết các môi trường thị trường thông qua tối ưu hóa tham số hợp lý và cơ chế lọc bổ sung.
/*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("BNF FUT 5 min Volatility Strategy", overlay=true)
// Inputs
length = input.int(20, "Length", minval=2)
src = input.source(close, "Source")
factor = input.float(2.0, "Multiplier", minval=0.25, step=0.25)
initial_capital = input.float(100000, "Initial Capital ($)")
risk_per_trade = input.float(1.0, "Risk per Trade (%)", minval=0.1, maxval=10.0)
// Volatility Stop Function
volStop(src, atrlen, atrfactor) =>
if not na(src)
var max = src
var min = src
var uptrend = true
var float stop = na
atrM = nz(ta.atr(atrlen) * atrfactor, ta.tr)
max := math.max(max, src)
min := math.min(min, src)
stop := nz(uptrend ? math.max(stop, max - atrM) : math.min(stop, min + atrM), src)
uptrend := src - stop >= 0.0
if uptrend != nz(uptrend[1], true)
max := src
min := src
stop := uptrend ? max - atrM : min + atrM
[stop, uptrend]
// Calculate Volatility Stop
[vStop, uptrend] = volStop(src, length, factor)
// Plot Volatility Stop
plot(vStop, "Volatility Stop", style=plot.style_cross, color=uptrend ? #009688 : #F44336)
// Risk Management and Position Sizing
atr = ta.atr(length)
stop_distance = math.abs(close - vStop) // Distance to stop level
position_size = (initial_capital * (risk_per_trade / 100)) / stop_distance // Position size based on risk per trade
position_size := math.max(position_size, 1) // Ensure minimum size of 1
// Strategy Logic
if not na(vStop)
if uptrend and not uptrend[1] // Transition to uptrend
strategy.close("Short")
strategy.entry("Long", strategy.long, qty=position_size)
if not uptrend and uptrend[1] // Transition to downtrend
strategy.close("Long")
strategy.entry("Short", strategy.short, qty=position_size)
// Exit on Stop Hit
if strategy.position_size > 0 and low < vStop // Exit long if stop hit
strategy.close("Long", comment="Stop Hit")
if strategy.position_size < 0 and high > vStop // Exit short if stop hit
strategy.close("Short", comment="Stop Hit")
if (hour == 15 and minute == 15)
strategy.close_all()