
Chiến lược này kết hợp các chỉ số Brin và MACD, sử dụng Brin để đánh giá cơ hội bán tháo thị trường và MACD để đánh giá xu hướng đảo ngược, để thực hiện chiến lược giao dịch định lượng mua thấp và bán cao. Tên chiến lược được đặt tên là Brin MACD đảo ngược chiến lược.
Chiến lược này đầu tiên tính các vùng Brin 20 ngày, bao gồm đường trung, đường trên và đường dưới. Khi giá chạm đường xuống, thị trường được coi là đang bán tháo.
Cụ thể, Brin tạo ra tín hiệu mua khi chạm đường ray xuống và MACD chênh lệch đang hướng tới đường tín hiệu phá vỡ đồng thời; tạo ra tín hiệu dừng khi giá đóng cửa tăng vượt quá điểm dừng.
Chiến lược này tích hợp các tín hiệu đảo ngược xu hướng của Brin và MACD để đạt được giá mua thấp hơn. Ngoài ra, chiến lược này cũng có thêm phương thức dừng để khóa lợi nhuận và tránh thua lỗ.
Cụ thể, những lợi thế là:
Chiến lược này cũng có một số rủi ro, chủ yếu tập trung vào các khía cạnh sau:
Các biện pháp phòng ngừa có thể được áp dụng cho các rủi ro trên:
Chiến lược này còn có thể được tối ưu hóa hơn nữa, bao gồm:
Chiến lược này kết hợp các phán đoán bán tháo Brin và MACD, cho phép lựa chọn điểm mua tương đối tốt hơn. Đồng thời, thiết lập kiểm soát rủi ro bằng cách dừng lỗ. Đây là một chiến lược bán tháo giá thấp đáng để học hỏi và tối ưu hóa.
/*backtest
start: 2023-11-19 00:00:00
end: 2023-12-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji
//@version=4
strategy("[KL] BOLL + MACD Strategy v2 (published)",overlay=true)
// BOLL bands {
BOLL_length = 20
BOLL_src = close
BOLL_mult = 2.0
BOLL_basis = sma(BOLL_src, BOLL_length)
BOLL_dev = BOLL_mult * stdev(BOLL_src, BOLL_length)
BOLL_upper = BOLL_basis + BOLL_dev
BOLL_lower = BOLL_basis - BOLL_dev
BOLL_offset = 0
plot(BOLL_basis, "Basis", color=#872323, offset = BOLL_offset)
BOLL_p1 = plot(BOLL_upper, "Upper", color=color.navy, offset = BOLL_offset, transp=50)
BOLL_p2 = plot(BOLL_lower, "Lower", color=color.navy, offset = BOLL_offset, transp=50)
fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)
// }
// MACD signals {
MACD_fastLen = 12
MACD_slowLen = 26
MACD_Len = 9
MACD = ema(close, MACD_fastLen) - ema(close, MACD_slowLen)
aMACD = ema(MACD, MACD_Len)
MACD_delta = MACD - aMACD
// }
backtest_timeframe_start = input(defval = timestamp("01 Nov 2010 13:30 +0000"), title = "Backtest Start Time", type = input.time)
//backtest_timeframe_end = input(defval = timestamp("05 Mar 2021 19:30 +0000"), title = "Backtest End Time", type = input.time)
TARGET_PROFIT_MODE = input(false,title="Exit when Risk:Reward met")
REWARD_RATIO = input(3,title="Risk:[Reward] (i.e. 3) for exit")
// Trailing stop loss {
var entry_price = float(0)
ATR_multi_len = 26
ATR_multi = input(2, "ATR multiplier for stop loss")
ATR_buffer = atr(ATR_multi_len) * ATR_multi
risk_reward_buffer = (atr(ATR_multi_len) * ATR_multi) * REWARD_RATIO
take_profit_long = low > entry_price + risk_reward_buffer
take_profit_short = low < entry_price - risk_reward_buffer
var bar_count = 0 //number of bars since entry
var trailing_SL_buffer = float(0)
var stop_loss_price = float(0)
stop_loss_price := max(stop_loss_price, close - trailing_SL_buffer)
// plot TSL line
trail_profit_line_color = color.green
if strategy.position_size == 0
trail_profit_line_color := color.blue
stop_loss_price := low
plot(stop_loss_price,color=trail_profit_line_color)
// }
var touched_lower_bb = false
if true// and time <= backtest_timeframe_end
if low <= BOLL_lower
touched_lower_bb := true
else if strategy.position_size > 0
touched_lower_bb := false//reset state
expected_rebound = MACD > MACD[1] and abs(MACD - aMACD) < abs(MACD[1] - aMACD[1])
buy_condition = touched_lower_bb and MACD > aMACD or expected_rebound
//ENTRY:
if strategy.position_size == 0 and buy_condition
entry_price := close
trailing_SL_buffer := ATR_buffer
stop_loss_price := close - ATR_buffer
strategy.entry("Long",strategy.long, comment="buy")
bar_count := 0
else if strategy.position_size > 0
bar_count := bar_count + 1
//EXIT:
// Case (A) hits trailing stop
if strategy.position_size > 0 and close <= stop_loss_price
if close > entry_price
strategy.close("Long", comment="take profit [trailing]")
stop_loss_price := 0
else if close <= entry_price and bar_count
strategy.close("Long", comment="stop loss")
stop_loss_price := 0
bar_count := 0
// Case (B) take targeted profit relative to risk
if strategy.position_size > 0 and TARGET_PROFIT_MODE
if take_profit_long
strategy.close("Long", comment="take profits [risk:reward]")
stop_loss_price := 0
bar_count := 0