
Bài viết này giới thiệu một chiến lược giao dịch định lượng dựa trên tỷ lệ phần trăm giảm giá. Chiến lược này xác định thời điểm mua và bán bằng cách thiết lập một tỷ lệ phần trăm giảm giá và chọn chu kỳ thời gian thích hợp.
Cốt lõi của chiến lược này là tạo tín hiệu giao dịch dựa trên tỷ lệ phần trăm của sự thay đổi giá. Đầu tiên, người dùng cần thiết lập một mức giảm phần trăm, thể hiện mức độ biến động của giá so với giá đóng cửa trước đó. Đồng thời, người dùng cũng cần chọn một chu kỳ thời gian, chẳng hạn như 1 phút, 1 giờ, 1 ngày, để tính toán giá cao nhất, giá thấp nhất và giá đóng cửa trong khoảng thời gian đó.
Bài viết này giới thiệu một chiến lược giao dịch định lượng dựa trên tỷ lệ phần trăm giảm giá, tự động tạo ra tín hiệu mua và bán bằng cách thiết lập tỷ lệ phần trăm giảm giá và chu kỳ thời gian thay đổi giá. Chiến lược này hoạt động đơn giản, linh hoạt và có thể áp dụng rộng rãi, nhưng đồng thời cũng phải đối mặt với rủi ro của biến động thị trường, thiết lập tham số và quá phù hợp. Bằng cách kết hợp với cơ chế dừng lỗ, điều chỉnh tham số động và kết hợp với các chỉ số kỹ thuật khác, bạn có thể tối ưu hóa hơn nữa hiệu suất của chiến lược, tăng hiệu quả trong giao dịch thực tế.
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("GBS Percentage", overlay=true)
// Define input options for percentage settings and timeframe
percentage = input.float(1.04, title="Percentage Threshold", minval=0.01, step=0.01) / 100
timeframe = input.timeframe("D", title="Timeframe", options=["1", "3", "5", "15", "30", "60", "240", "D", "W", "M"])
// Calculate high, low, and close of the selected timeframe
high_timeframe = request.security(syminfo.tickerid, timeframe, high)
low_timeframe = request.security(syminfo.tickerid, timeframe, low)
close_timeframe = request.security(syminfo.tickerid, timeframe, close)
// Calculate the percentage threshold based on the previous close
threshold = close_timeframe[1] * percentage
// Define conditions for Buy and Sell
buyCondition = high_timeframe > (close_timeframe[1] + threshold)
sellCondition = low_timeframe < (close_timeframe[1] - threshold)
// Entry and exit rules
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.entry("Sell", strategy.short)
// Close the positions based on the conditions
if (sellCondition)
strategy.close("Buy")
if (buyCondition)
strategy.close("Sell")
// Plot Buy and Sell signals on the chart
plotshape(series=buyCondition, title="Buy Entry", color=color.green, style=shape.triangleup, location=location.belowbar)
plotshape(series=sellCondition, title="Sell Entry", color=color.red, style=shape.triangledown, location=location.abovebar)
// Plot the equity curve of the strategy
plot(strategy.equity, title="Equity", color=color.blue, linewidth=2)