
Chiến lược này dựa trên Bollinger Bands Gold Fork Dead Fork để thực hiện nhiều giao dịch ngắn hạn. Khi giá phá vỡ Bollinger Bands lên đường, hãy tháo dỡ; Khi giá phá vỡ Bollinger Bands xuống đường, hãy làm nhiều. Trong thời gian giữ vị trí, sẽ có thêm vị trí và theo dõi dừng lỗ.
Chiến lược này sử dụng 3 quỹ đạo trên và dưới của Brin. quỹ đạo trung tâm của Brin là trung bình chuyển động n ngày, quỹ đạo trên là chênh lệch tiêu chuẩn n ngày của quỹ đạo trung tâm + k lần, quỹ đạo dưới là quỹ đạo trung tâm - k lần của chênh lệch tiêu chuẩn n ngày.
Khi giá từ dưới lên phá vỡ đường xuống, cho thấy giá bắt đầu tăng, lúc này làm nhiều; khi giá từ trên xuống phá vỡ đường lên, cho thấy giá bắt đầu giảm, lúc này làm trống.
Sau khi thực hiện tháo lỗ nhiều hơn, sẽ tiếp tục gia tăng vị thế. Điều kiện của việc gia tăng vị thế là dựa trên vị trí đã nắm giữ, nếu giá chạm lại đường trung bình, sẽ mở thêm vị trí hoặc tháo lỗ.
Theo dõi dừng của tất cả các vị trí cũng được cập nhật trong thời gian thực. Đường dừng sẽ được thiết lập dựa trên giá trung bình của vị trí hiện tại và giá Brin.
Chiến lược này có những ưu điểm sau:
Chiến lược này cũng có một số rủi ro:
Những rủi ro này có thể được tối ưu hóa bằng cách:
Chiến lược này có thể được tối ưu hóa theo các khía cạnh sau:
Chiến lược này nói chung là một chiến lược theo dõi xu hướng điển hình. Nó có thể theo dõi và thu lợi nhuận khi xu hướng xuất hiện. Đồng thời, nó cũng có một số rủi ro cần được tối ưu hóa và cải tiến hơn nữa để thích ứng với nhiều tình huống thị trường hơn, giảm nguy cơ phá vỡ giả.
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title='Bollinger Band strategy with split, limit, stop', shorttitle='bb strategy', overlay=true,commission_type = strategy.commission.percent, commission_value = 0.01, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, pyramiding = 4)
//Summary: Going Long or Short when Entering after Breaking the Bollinger Bands\
//At this time, the stop-loss, profit-taking price, and pyramiding standard\
// are determined from the difference between the position average price and the band price.
//After entering the position, if the price crosses the mid-band line, the stop loss is adjusted to the mid-band line.
//each trade, entry position size = 10% of total cash
//max pyramiding is 4
//commission = 0.01%
in_period = true
bb_length = input.int(20)
bb_mult = input.int(2)
[middle, upper, lower] = ta.bb(close,bb_length, bb_mult)
plot(middle, color=color.aqua)
plot(upper, color=color.orange)
plot(lower, color=color.orange)
long_cond = ta.crossover(close,lower)
short_cond = ta.crossunder(close,upper)
var saved_ph = 0.0
if strategy.opentrades>0 and strategy.opentrades[1]==0 and strategy.position_size > 0
saved_ph := upper[1]
var saved_pl = 0.0
if strategy.opentrades>0 and strategy.opentrades[1]==0 and strategy.position_size < 0
saved_pl := lower[1]
avg = strategy.position_avg_price
long_diff = saved_ph-avg
short_diff = saved_pl-avg
long_stoploss = avg - 1*long_diff
short_stoploss = avg - 1*short_diff
long_avgdown = avg - 0.5*long_diff
short_avgup = avg - 0.5*short_diff
long_profit_price = avg + 0.5*long_diff
short_profit_price = avg + 0.5*short_diff
var label _label = na
if in_period
if long_cond and strategy.opentrades==0
strategy.entry("Long",strategy.long)
if long_cond and strategy.opentrades >0 and (close[1]<long_avgdown or close[2]<long_avgdown)
strategy.entry("Long",strategy.long)
if short_cond and strategy.opentrades==0
strategy.entry("Short", strategy.short)
if short_cond and strategy.opentrades>0 and (close[1]>short_avgup or close[2]>short_avgup)
strategy.entry("Short",strategy.short)
plot(avg, style=plot.style_linebr)
plot(strategy.position_size > 0? long_profit_price: na,color=color.green, style=plot.style_linebr)
plot(strategy.position_size > 0? long_avgdown: na,color=color.yellow, style=plot.style_linebr)
plot(strategy.position_size > 0? long_stoploss: na,color=color.red, style=plot.style_linebr)
plot(strategy.position_size < 0? short_profit_price: na,color=color.green, style=plot.style_linebr)
plot(strategy.position_size < 0? short_avgup: na,color=color.yellow, style=plot.style_linebr)
plot(strategy.position_size < 0? short_stoploss: na,color=color.red, style=plot.style_linebr)
if strategy.position_size > 0
if ta.crossover(close, middle)
strategy.exit("Long Exit", "Long", limit=long_profit_price, stop=middle)
else
strategy.exit("Long Exit", "Long", limit=long_profit_price, stop=long_stoploss)
if strategy.position_size < 0
if ta.crossunder(close, middle)
strategy.exit("Short Exit", "Short", limit=short_profit_price, stop=middle)
else
strategy.exit("Short Exit", "Short", limit=short_profit_price, stop=short_stoploss)