
Chiến lược này là một hệ thống giao dịch định lượng kết hợp các tín hiệu chéo của MACD trong nhiều khung thời gian với các mức áp lực hỗ trợ động của MACD trong 52 tuần. Chiến lược này xác nhận tín hiệu giao dịch bằng cách chéo các chỉ số MACD trong hai chu kỳ thời gian của đường tuần hoàn và đường mặt trời, đồng thời sử dụng các đường áp lực hỗ trợ động của MACD trong 52 tuần để giúp đánh giá xu hướng thị trường, do đó đưa ra quyết định giao dịch vững chắc hơn. Chiến lược sử dụng cơ chế dừng lỗ động, đồng thời bảo đảm lợi nhuận cũng có thể kiểm soát rủi ro hiệu quả.
Chiến lược này dựa trên những logic cốt lõi sau:
Chiến lược này xây dựng một hệ thống giao dịch theo dõi xu hướng hoàn chỉnh bằng cách kết hợp tín hiệu chéo đa khung thời gian MACD với đường áp lực hỗ trợ động của 52 tuần cao thấp. Ưu điểm của chiến lược là độ tin cậy của tín hiệu xác nhận và tính toàn vẹn của kiểm soát rủi ro, nhưng vẫn cần chú ý đối phó với rủi ro thị trường xung đột và tụt hậu.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MACD Bitcoin strategy con 52W High/Low (linee estese)", overlay=true)
// === MACD SETTINGS ===
fastLength = 12
slowLength = 26
signalSmoothing = 9
// Funzione per ottenere i valori MACD
getMACD(source, timeframe) =>
[macdLine, signalLine, _] = ta.macd(source, fastLength, slowLength, signalSmoothing)
[macdLine, signalLine]
// Valori MACD Settimanali
[macdWeekly, signalWeekly] = request.security(syminfo.tickerid, "W", getMACD(close, "W"), lookahead=barmerge.lookahead_on)
// Valori MACD Giornalieri
[macdDaily, signalDaily] = getMACD(close, "D")
// Variabile per lo stop loss
var float lowOfSignalCandle = na
// Condizione per l'ingresso
longConditionWeekly = ta.crossover(macdWeekly, signalWeekly)
exitConditionDaily = ta.crossunder(macdDaily, signalDaily)
// Imposta Stop Loss sulla candela giornaliera
if (exitConditionDaily)
lowOfSignalCandle := low
// Condizione di ingresso nel trade
enterTradeCondition = macdWeekly > signalWeekly and ta.crossover(macdDaily, signalDaily)
if (enterTradeCondition)
strategy.entry("MACD Long", strategy.long)
if (not na(lowOfSignalCandle))
strategy.exit("Stop Loss", "MACD Long", stop=lowOfSignalCandle)
if (strategy.position_size == 0)
lowOfSignalCandle := na
// // === 52 WEEK HIGH/LOW SETTINGS ===
// // Input per selezionare tra Highs/Lows o Close
// high_low_close = input.string(defval="Highs/Lows", title="Base 52 week values on candle:", options=["Highs/Lows", "Close"])
// // Calcolo dei valori delle 52 settimane
// weekly_hh = request.security(syminfo.tickerid, "W", ta.highest(high, 52), lookahead=barmerge.lookahead_on)
// weekly_ll = request.security(syminfo.tickerid, "W", ta.lowest(low, 52), lookahead=barmerge.lookahead_on)
// weekly_hc = request.security(syminfo.tickerid, "W", ta.highest(close, 52), lookahead=barmerge.lookahead_on)
// weekly_lc = request.security(syminfo.tickerid, "W", ta.lowest(close, 52), lookahead=barmerge.lookahead_on)
// // Selezione dei valori in base all'input
// high_plot = high_low_close == "Highs/Lows" ? weekly_hh : weekly_hc
// low_plot = high_low_close == "Highs/Lows" ? weekly_ll : weekly_lc
// // === LINEE ORIZZONTALI ESTESE FINO AL PREZZO ATTUALE ===
// var line highLine = na
// var line lowLine = na
// // Linea Orizzontale per il 52W High
// if (na(highLine))
// highLine := line.new(bar_index, high_plot, bar_index + 1, high_plot, color=color.green, width=2, style=line.style_dashed, extend=extend.right)
// else
// line.set_y1(highLine, high_plot)
// line.set_y2(highLine, high_plot)
// // Linea Orizzontale per il 52W Low
// if (na(lowLine))
// lowLine := line.new(bar_index, low_plot, bar_index + 1, low_plot, color=color.red, width=2, style=line.style_dashed, extend=extend.right)
// else
// line.set_y1(lowLine, low_plot)
// line.set_y2(lowLine, low_plot)
// // Etichette per le linee orizzontali
// var label highLabel = na
// var label lowLabel = na
// if (na(highLabel))
// highLabel := label.new(bar_index, high_plot, "52W High", color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
// else
// label.set_y(highLabel, high_plot)
// label.set_x(highLabel, bar_index)
// if (na(lowLabel))
// lowLabel := label.new(bar_index, low_plot, "52W Low", color=color.red, textcolor=color.white, style=label.style_label_up, size=size.small)
// else
// label.set_y(lowLabel, low_plot)
// label.set_x(lowLabel, bar_index)
// // Tracciamento delle Linee Estese
// plot(high_plot, title="52W High", color=color.green, style=plot.style_linebr)
// plot(low_plot, title="52W Low", color=color.red, style=plot.style_linebr)