
Chiến lược này là một hệ thống giao dịch định lượng dựa trên chỉ số WaveTrend kết hợp với cơ chế quản lý rủi ro động. Chiến lược này thực hiện quản lý giao dịch toàn diện bằng cách tính toán cường độ của xu hướng biến động giá, lọc tín hiệu trong khu vực quá mua quá bán, đồng thời áp dụng các phương tiện kiểm soát rủi ro như dừng lỗ, dừng và theo dõi dừng lỗ.
Cốt lõi của chiến lược là tính toán chỉ số WaveTrend thông qua giá HLC3. Đầu tiên tính toán đường trung bình di chuyển của chỉ số ((EMA) của chu kỳ n1 làm đường viền, sau đó tính toán độ lệch của giá so với đường viền và xử lý thống nhất bằng 0.015 làm hệ số. Cuối cùng, hai đường sóng wt1 và wt2, tương ứng đại diện cho đường nhanh và đường chậm.
Chiến lược này thực hiện một chiến lược giao dịch định lượng toàn diện hơn bằng cách kết hợp các chỉ số WaveTrend và hệ thống quản lý rủi ro tốt. Ưu điểm cốt lõi của chiến lược là nó có khả năng thích ứng và có thể kiểm soát rủi ro, nhưng vẫn yêu cầu các nhà giao dịch tối ưu hóa tham số và cải tiến chiến lược dựa trên tình hình thị trường thực tế. Bằng cách tối ưu hóa và hoàn thiện liên tục, chiến lược này có thể đạt được lợi nhuận ổn định trong giao dịch thực tế.
/*backtest
start: 2024-11-12 00:00:00
end: 2024-12-11 08:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="WaveTrend [LazyBear] with Risk Management", shorttitle="WT_LB_RM", overlay=true)
// Input Parameters
n1 = input.int(10, "Channel Length")
n2 = input.int(21, "Average Length")
obLevel1 = input.int(60, "Over Bought Level 1")
obLevel2 = input.int(53, "Over Bought Level 2")
osLevel1 = input.int(-60, "Over Sold Level 1")
osLevel2 = input.int(-53, "Over Sold Level 2")
// Risk Management Inputs
stopLossPercent = input.float(50.0, "Stop Loss (%)", minval=0.1, maxval=100)
takeProfitPercent = input.float(5.0, "Take Profit (%)", minval=0.1, maxval=100)
trailingStopPercent = input.float(3.0, "Trailing Stop (%)", minval=0.1, maxval=100)
trailingStepPercent = input.float(2.0, "Trailing Stop Step (%)", minval=0.1, maxval=100)
// WaveTrend Calculation
ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 4)
// Plotting Original Indicators
plot(0, color=color.gray)
plot(obLevel1, color=color.red)
plot(osLevel1, color=color.green)
plot(obLevel2, color=color.red, style=plot.style_line)
plot(osLevel2, color=color.green, style=plot.style_line)
plot(wt1, color=color.green)
plot(wt2, color=color.red, style=plot.style_line)
plot(wt1-wt2, color=color.blue, style=plot.style_area, transp=80)
// Buy and Sell Signals with Risk Management
longCondition = ta.crossover(wt1, osLevel1) or ta.crossover(wt1, osLevel2)
shortCondition = ta.crossunder(wt1, obLevel1) or ta.crossunder(wt1, obLevel2)
// Strategy Entry with Risk Management
if (longCondition)
entryPrice = close
stopLossPrice = entryPrice * (1 - stopLossPercent/100)
takeProfitPrice = entryPrice * (1 + takeProfitPercent/100)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long",
stop=stopLossPrice,
limit=takeProfitPrice,
trail_price=close * (1 + trailingStopPercent/100),
trail_offset=close * (trailingStepPercent/100))
if (shortCondition)
entryPrice = close
stopLossPrice = entryPrice * (1 + stopLossPercent/100)
takeProfitPrice = entryPrice * (1 - takeProfitPercent/100)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short",
stop=stopLossPrice,
limit=takeProfitPrice,
trail_price=close * (1 - trailingStopPercent/100),
trail_offset=close * (trailingStepPercent/100))