
Đây là một chiến lược giao dịch tự động dựa trên các chỉ số kỹ thuật kép RSI và MACD. Chiến lược này xác định cơ hội giao dịch tiềm năng bằng cách kết hợp tín hiệu mua quá mức và xác nhận xu hướng để nắm bắt chính xác thị trường. Chiến lược này sử dụng quản lý vị trí tỷ lệ phần trăm và có cơ chế chống trượt tích hợp, có tính thực tế và thích ứng mạnh mẽ.
Lập luận cốt lõi của chiến lược dựa trên các yếu tố then chốt sau:
Chiến lược này xây dựng một hệ thống giao dịch tương đối ổn định thông qua sự phối hợp của RSI và MACD. Mặc dù có một số rủi ro bị tụt hậu, chiến lược vẫn có giá trị thực tế tốt thông qua kiểm soát rủi ro và tối ưu hóa tham số hợp lý.
//@version=6
strategy("Debugging Demo GPT",
overlay=true,
initial_capital=100,
default_qty_type=strategy.percent_of_equity,
default_qty_value=3,
pyramiding=1,
calc_on_order_fills=true,
calc_on_every_tick=true,
slippage=3)
// -----------------------------------------------------------------------
// (1) Inputs: Start and End Date
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// (2) Indicators (RSI, MACD)
// -----------------------------------------------------------------------
// === RSI ===
rsiLen = input.int(14, "RSI Length")
rsiOB = input.int(80, "RSI Overbought")
rsiOS = input.int(20, "RSI Oversold")
rsiVal = ta.rsi(close, rsiLen)
// === MACD ===
fastLen = input.int(12, "MACD Fast Length")
slowLen = input.int(26, "MACD Slow Length")
sigLen = input.int(9, "MACD Signal Length")
[macdLine, sigLine, histLine] = ta.macd(close, fastLen, slowLen, sigLen)
// -----------------------------------------------------------------------
// (3) Trading Logic: LONG/SHORT Filters
// -----------------------------------------------------------------------
bool rsiLongOk = (rsiVal < rsiOB)
bool rsiShortOk = (rsiVal > rsiOS)
bool macdLongOk = (macdLine > sigLine)
bool macdShortOk = (macdLine < sigLine)
bool longCondition = rsiLongOk and macdLongOk
bool shortCondition = rsiShortOk and macdShortOk
// -----------------------------------------------------------------------
// (4) Entry Conditions
// -----------------------------------------------------------------------
// Debugging: Visualizing the conditions
plotshape(series=longCondition, location=location.belowbar, color=color.blue, style=shape.circle, title="LongCondition", size=size.tiny)
plotshape(series=shortCondition, location=location.abovebar, color=color.orange, style=shape.circle, title="ShortCondition", size=size.tiny)
// Entries only when all conditions are met
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
// -----------------------------------------------------------------------
// (5) Plotting for Visualization
// -----------------------------------------------------------------------
// RSI Plots
hline(rsiOB, "RSI Overbought", color=color.red, linestyle=hline.style_dotted)
hline(rsiOS, "RSI Oversold", color=color.green, linestyle=hline.style_dotted)
plot(rsiVal, title="RSI", color=color.purple)
// MACD Plots
plot(macdLine, color=color.teal, title="MACD Line")
plot(sigLine, color=color.orange, title="MACD Signal")
plot(histLine, style=plot.style_histogram, color=(histLine >= 0 ? color.lime : color.red), title="MACD Histogram")