Chiến lược này dựa trên chỉ số UT Bot được phát triển bởi QuantNomad, kết hợp với tư duy dừng lỗ di động. Mã gốc được viết bởi @Yo_adriiiiaan, @HPotter đã sửa đổi. Chiến lược này sẽ được sử dụng với các khái niệm tiền thông minh của LuxAlgo.
Các nguyên tắc chính của chiến lược này là:
Chiến lược này dựa trên chỉ số UT Bot, thêm logic dừng di động, có thể đóng vai trò bảo vệ lợi nhuận trong tình huống xu hướng. Đồng thời, chiến lược thiết lập dừng lỗ cho vị trí nhiều đầu và vị trí trống, có khả năng thích ứng mạnh mẽ. Sử dụng ATR làm cơ sở tham chiếu cho dừng di động, có thể điều chỉnh vị trí dừng lỗ động, tăng tính linh hoạt. Tuy nhiên, chiến lược có thể đối mặt với rủi ro chi phí giao dịch cao do tổn thất thường xuyên trong tình huống xung đột, và thiếu thiết lập dừng di động, có thể mất lợi nhuận. Ngoài ra, lựa chọn tham số có ảnh hưởng lớn đến hiệu suất của chiến lược.
Trong tương lai, có thể cải thiện chiến lược để đạt được lợi nhuận ổn định hơn từ việc tối ưu hóa điều kiện nhập cảnh, khám phá các phương pháp dừng chân di động phức tạp hơn, thêm cơ chế dừng chân di động, tối ưu hóa tham số cho các giống và chu kỳ khác nhau. Nhìn chung, ý tưởng chiến lược này đơn giản, dễ hiểu và thực hiện, nhưng vẫn còn không gian tối ưu hóa hơn nữa, đáng để tiếp tục khám phá và cải thiện.
/*backtest
start: 2023-03-05 00:00:00
end: 2024-03-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Trailingstop", overlay=true)
if close > sma(close, 50)
strategy.entry("long", strategy.long)
// Trailing stop loss for long positions
Trailperc = 0.20
price_stop_long = 0.0
if (strategy.position_size > 0)
stopValue = close * (1 - Trailperc)
price_stop_long := max(stopValue, price_stop_long[1])
else
price_stop_long := 0
if (strategy.position_size > 0)
strategy.exit(id="stoploss_long", stop=price_stop_long)
// Trailing stop loss for short positions
Trailperc_short = 0.20
price_stop_short = 0.0
if (strategy.position_size < 0)
stopValue_short = close * (1 + Trailperc_short)
price_stop_short := min(stopValue_short, price_stop_short[1])
else
price_stop_short := 0
if (strategy.position_size < 0)
strategy.exit(id="stoploss_short", stop=price_stop_short)
// ATR Trailing Stop for visualization
keyvalue = input(3, title="Key Value. 'This changes the sensitivity'", step=0.5)
atrperiod = input(10, title="ATR Period")
xATR = atr(atrperiod)
nLoss = keyvalue * xATR
xATRTrailingStop = 0.0
xATRTrailingStop := iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos = 0
pos := iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue
plot(xATRTrailingStop, color = xcolor, title = "Trailing Stop")