
Đây là một chiến lược giao dịch dựa trên phá vỡ vùng kháng cự hỗ trợ, kết hợp với bộ lọc xu hướng và hệ thống quản lý rủi ro. Chiến lược xác định các cơ hội giao dịch tiềm năng bằng cách xác định động mức giá quan trọng và sử dụng đường trung bình di chuyển để xác nhận hướng xu hướng của thị trường. Chiến lược này sử dụng phương pháp quản lý tiền bảo thủ, hạn chế rủi ro trên mỗi giao dịch trong vòng 1% số tiền tài khoản, đồng thời sử dụng tỷ lệ rủi ro lợi nhuận 2: 1 để thiết lập vị trí dừng.
Lập luận cốt lõi của chiến lược bao gồm các thành phần quan trọng sau:
Đây là một chiến lược giao dịch có cấu trúc tốt, cung cấp một phương pháp giao dịch có hệ thống bằng cách kết hợp các nguyên tắc phân tích kỹ thuật và quản lý rủi ro. Ưu điểm của chiến lược là có quy tắc giao dịch toàn diện và kiểm soát rủi ro nghiêm ngặt, nhưng cũng đòi hỏi các nhà giao dịch phải hiểu được các hạn chế của nó và tối ưu hóa và điều chỉnh thích hợp theo tình hình giao dịch thực tế.
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("支撑/阻力区域突破策略(2倍止盈 + 蜡烛确认 + 趋势过滤)", overlay=true, initial_capital=10000, currency=currency.USD, pyramiding=0, calc_on_order_fills=true, calc_on_every_tick=true)
// 用户输入设置
pivotLen = input.int(title="枢轴识别窗口长度", defval=5, minval=1)
zoneOffsetPercent = input.float(title="区域偏移百分比 (%)", defval=0.1, step=0.1)
maLength = input.int(200, title="移动平均线周期")
// 趋势指标: 简单移动平均线(SMA)
trendMA = ta.sma(close, maLength)
// 识别高点和低点(枢轴高点/低点)
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
// 存储最近的阻力位和支撑位
var float resistanceLevel = na
var int resistanceBar = na
if not na(ph)
resistanceLevel := ph
resistanceBar := bar_index - pivotLen
var float supportLevel = na
var int supportBar = na
if not na(pl)
supportLevel := pl
supportBar := bar_index - pivotLen
// 将阻力和支撑区域绘制为区域框
if not na(resistanceLevel)
resOffset = resistanceLevel * (zoneOffsetPercent / 100)
resTop = resistanceLevel + resOffset
resBottom = resistanceLevel - resOffset
if not na(supportLevel)
supOffset = supportLevel * (zoneOffsetPercent / 100)
supTop = supportLevel + supOffset
supBottom = supportLevel - supOffset
// 风险管理: 定义资金、风险百分比和计算风险金额
riskCapital = 10000.0
riskPercent = 0.01
riskAmount = riskCapital * riskPercent // 1% of $10,000 = $100
// activeStop变量用于显示止损位
var float activeStop = na
if strategy.position_size == 0
activeStop := na
// 确定趋势方向
isUptrend = close > trendMA // 上升趋势(价格在MA之上)
isDowntrend = close < trendMA // 下降趋势(价格在MA之下)
// 定义突破蜡烛和确认蜡烛
var bool breakoutUp = false
var bool breakoutDown = false
if not na(resistanceLevel) and close[1] > resistanceLevel and open[1] < resistanceLevel
breakoutUp := true
else
breakoutUp := false
if not na(supportLevel) and close[1] < supportLevel and open[1] > supportLevel
breakoutDown := true
else
breakoutDown := false
// 突破确认: 下一根蜡烛必须在突破方向收盘
confirmLong = breakoutUp and close > close[1] and strategy.position_size == 0 and isUptrend
confirmShort = breakoutDown and close < close[1] and strategy.position_size == 0 and isDowntrend
// 做多入场: 确认蜡烛 + 在突破蜡烛低点设置止损
if confirmLong
entryPrice = close
stopLevelLong = low[1]
riskPerUnit = entryPrice - stopLevelLong
if riskPerUnit > 0
qty = riskAmount / riskPerUnit
activeStop := stopLevelLong
takeProfitLong = entryPrice + (riskPerUnit * 2) // 止盈设为止损的2倍
strategy.entry("Long", strategy.long, qty=qty)
strategy.exit("Exit Long", from_entry="Long", stop=stopLevelLong, limit=takeProfitLong)
// 做空入场: 确认蜡烛 + 在突破蜡烛高点设置止损
if confirmShort
entryPrice = close
stopLevelShort = high[1]
riskPerUnit = stopLevelShort - entryPrice
if riskPerUnit > 0
qty = riskAmount / riskPerUnit
activeStop := stopLevelShort
takeProfitShort = entryPrice - (riskPerUnit * 2) // 止盈设为止损的2倍
strategy.entry("Short", strategy.short, qty=qty)
strategy.exit("Exit Short", from_entry="Short", stop=stopLevelShort, limit=takeProfitShort)
// 当有持仓时在图表上显示止损线(水平线)
plot(strategy.position_size != 0 ? activeStop : na, title="止损线", color=color.red, linewidth=2, style=plot.style_line)
// 在图表上显示移动平均线
plot(trendMA, title="趋势MA", color=color.blue, linewidth=2)