
Chiến lược này là một hệ thống giao dịch dựa trên các chỉ số phân tích kỹ thuật, kết hợp các cơ chế xác nhận tín hiệu kép RSI (chỉ số tương đối mạnh yếu) và MACD (trung bình di chuyển hướng đi ngược) để quản lý rủi ro bằng cách tìm kiếm cơ hội giao dịch trong khu vực quá mua quá bán và sử dụng lệnh dừng lỗ động. Chiến lược được thiết kế chủ yếu cho giao dịch đường ngắn, phù hợp để nắm bắt cơ hội giao dịch trong môi trường thị trường nhanh.
Chiến lược sử dụng RSI và MACD, hai chỉ số kỹ thuật cổ điển để xây dựng hệ thống tín hiệu giao dịch. SIGNAL mua được kích hoạt khi RSI thấp hơn 35 ((vùng bán tháo) và MACD xuất hiện Gold Forks; SIGNAL bán được kích hoạt khi RSI cao hơn 70 ((vùng mua tháo) và MACD xuất hiện Dead Forks.
Chiến lược này xây dựng một hệ thống giao dịch tương đối đáng tin cậy bằng cách kết hợp các chỉ số RSI và MACD với các thiết lập dừng lỗ hợp lý, có một số giá trị ứng dụng thực tế. Tuy nhiên, vẫn cần tối ưu hóa theo tình hình thị trường thực tế, đặc biệt là cần phải hoàn thiện thêm về kiểm soát rủi ro và lọc tín hiệu.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Scalping XAU/USD m5 (Protected)", overlay=true)
// Parâmetros do usuário
rsiPeriod = input(14, title="Período do RSI")
rsiOverbought = input(70, title="Nível de Sobrecompra do RSI") // Ajustado para aumentar trades
rsiOversold = input(35, title="Nível de Sobrevenda do RSI") // Ajustado para aumentar trades
macdFast = input(6, title="Média Rápida do MACD") // Ajustado para aumentar a frequência
macdSlow = input(13, title="Média Lenta do MACD") // Ajustado para aumentar a frequência
macdSignal = input(7, title="Sinal do MACD")
lotSize = input(1, title="Tamanho do Lote")
slPips = input(300, title="Stop-Loss (pips)") // Definido pelo usuário
tpPips = input(600, title="Take-Profit (pips)") // Definido pelo usuário
// Cálculos do RSI e MACD
rsi = ta.rsi(close, rsiPeriod)
[macdLine, signalLine, _] = ta.macd(close, macdFast, macdSlow, macdSignal)
// Condições de compra
buyCondition = (rsi < rsiOversold) and (macdLine > signalLine) and (ta.crossover(macdLine, signalLine))
// Condições de venda
sellCondition = (rsi > rsiOverbought) and (macdLine < signalLine) and (ta.crossunder(macdLine, signalLine))
// Executa a compra
if (buyCondition)
strategy.entry("Compra", strategy.long, qty=lotSize)
label.new(bar_index, close, "Compra", color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)
// Executa a venda
if (sellCondition)
strategy.entry("Venda", strategy.short, qty=lotSize)
label.new(bar_index, close, "Venda", color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
// Saídas com Stop-Loss e Take-Profit
if (strategy.position_size > 0) // Para posições de compra
strategy.exit("Saída Compra", from_entry="Compra", stop=close - slPips * syminfo.mintick, limit=close + tpPips * syminfo.mintick)
if (strategy.position_size < 0) // Para posições de venda
strategy.exit("Saída Venda", from_entry="Venda", stop=close + slPips * syminfo.mintick, limit=close - tpPips * syminfo.mintick)
// Plota o RSI e suas linhas de sobrecompra/sobrevenda
hline(rsiOverbought, "Sobrecompra", color=color.red)
hline(rsiOversold, "Sobrevenda", color=color.green)
plot(rsi, "RSI", color=color.blue)
// Plota o MACD
macdHist = macdLine - signalLine
plot(macdHist, title="Histograma MACD", color=color.green, style=plot.style_histogram)