
Đây là một chiến lược giao dịch lưới cao cấp dựa trên chỉ số Brin Belt. Chiến lược này xác định vị trí lưới thông qua các động thái đường ray lên xuống và đường ray trung tâm của Brin Belt và tự động điều chỉnh khoảng cách lưới theo biến động của thị trường. Hệ thống thực hiện giao dịch đa không gian tương ứng khi giá phá vỡ đường lưới, thực hiện giao dịch lưới tự động hoàn toàn.
Chiến lược sử dụng đường trung bình di chuyển 20 chu kỳ làm đường trung tâm của dải Brin, và chênh lệch chuẩn gấp 2 lần như băng thông. Dựa trên dải Brin, chiến lược thiết lập 4 lớp lưới giữa đường lên và xuống, với khoảng cách lưới là 1%.
Giải pháp:
Chiến lược này, kết hợp giữa giao dịch băng tròn và lưới, tạo ra một hệ thống giao dịch tự động với sự linh hoạt và ổn định. Ưu điểm cốt lõi của chiến lược là có thể thích ứng với các môi trường thị trường khác nhau, đồng thời kiểm soát rủi ro thông qua điều chỉnh tham số. Mặc dù có một số rủi ro vốn có, nhưng có thể xây dựng một hệ thống giao dịch ổn định hơn bằng cách tối ưu hóa và hoàn thiện liên tục.
/*backtest
start: 2024-12-19 00:00:00
end: 2025-02-19 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Grid Bot based on Bollinger Bands with Adjustable Levels", overlay=true)
// Settings
source = close
length = input.int(20, minval=1, title="Bollinger Bands Length")
mult = input.float(2.0, minval=0.001, maxval=50, title="Bollinger Bands Multiplier")
gridDistancePercent = input.float(1.0, title="Distance Between Levels (%)") / 100 // Distance between grid levels in percentage
gridSize = input.int(4, title="Number of Grid Levels") // Number of grid levels
// Bollinger Bands Calculation
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev
// Middle line between the upper and lower Bollinger Bands
middle = (upper + lower) / 2
// Levels for long and short positions
var float[] longLevels = array.new_float(gridSize)
var float[] shortLevels = array.new_float(gridSize)
// Filling levels for long and short positions
for i = 0 to gridSize - 1
array.set(longLevels, i, lower * (1 + gridDistancePercent * (i + 1))) // For longs, increase the lower band
array.set(shortLevels, i, upper * (1 - gridDistancePercent * (i + 1))) // For shorts, decrease the upper band
// Logic for entering a long position (buy) at the first level crossover
longCondition = ta.crossover(source, array.get(longLevels, 0)) // Condition for buying — crossover with the first long level
if longCondition
strategy.entry("GridLong", strategy.long, comment="GridLong")
// Logic for entering a short position (sell) at the first level crossunder
shortCondition = ta.crossunder(source, array.get(shortLevels, 0)) // Condition for selling — crossunder with the first short level
if shortCondition
strategy.entry("GridShort", strategy.short, comment="GridShort")
// Logic for additional buys/sells when reaching subsequent levels
// For longs:
for i = 1 to gridSize - 1
if ta.crossover(source, array.get(longLevels, i))
strategy.entry("GridLong" + str.tostring(i), strategy.long, comment="GridLong")
// For shorts:
for i = 1 to gridSize - 1
if ta.crossunder(source, array.get(shortLevels, i))
strategy.entry("GridShort" + str.tostring(i), strategy.short, comment="GridShort")
// Visualization of the levels
plot(upper, color=color.red, linewidth=2, title="Upper Bollinger Band")
plot(lower, color=color.green, linewidth=2, title="Lower Bollinger Band")
plot(middle, color=color.blue, linewidth=2, title="Middle Line")
// Display additional grid levels (fixed titles)
plot(array.get(longLevels, 0), color=color.green, linewidth=1, title="Long Level 1") // For the 1st long level
plot(array.get(longLevels, 1), color=color.green, linewidth=1, title="Long Level 2") // For the 2nd long level
plot(array.get(longLevels, 2), color=color.green, linewidth=1, title="Long Level 3") // For the 3rd long level
plot(array.get(longLevels, 3), color=color.green, linewidth=1, title="Long Level 4") // For the 4th long level
plot(array.get(shortLevels, 0), color=color.red, linewidth=1, title="Short Level 1") // For the 1st short level
plot(array.get(shortLevels, 1), color=color.red, linewidth=1, title="Short Level 2") // For the 2nd short level
plot(array.get(shortLevels, 2), color=color.red, linewidth=1, title="Short Level 3") // For the 3rd short level
plot(array.get(shortLevels, 3), color=color.red, linewidth=1, title="Short Level 4") // For the 4th short level