
Trata-se de uma estratégia de negociação baseada na ruptura de áreas de resistência de suporte, combinando filtragem de tendências e um sistema de gerenciamento de risco. A estratégia identifica oportunidades de negociação potenciais identificando dinamicamente níveis de preços críticos e usa médias móveis para confirmar a direção da tendência do mercado.
A lógica central da estratégia inclui os seguintes componentes-chave:
Trata-se de uma estratégia de negociação bem estruturada, que fornece uma metodologia de negociação sistematizada por meio da combinação de análise técnica e princípios de gerenciamento de risco. A vantagem da estratégia reside em seus padrões de negociação abrangentes e rigorosos controles de risco, mas também requer que o comerciante entenda suas limitações e faça a otimização e adaptação adequadas de acordo com as condições reais de negociação.
/*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)