
This is a trading strategy based on support and resistance zone breakouts, incorporating trend filtering and risk management systems. The strategy dynamically identifies key price levels to determine potential trading opportunities and uses moving averages to confirm market trend direction. It employs a conservative money management approach, limiting risk to 1% of account capital per trade, while using a 2:1 reward-to-risk ratio for profit targets.
The core logic includes several key components: 1. Using pivot highs and lows to identify potential support and resistance zones 2. Creating support/resistance zones through price offset percentages 3. Utilizing a 200-day moving average as a trend filter 4. Confirming breakout validity through candlestick patterns 5. Implementing strict money management rules to control risk per trade The system enters long positions when price breaks above resistance in an uptrend and short positions when price breaks below support in a downtrend.
This is a well-structured trading strategy that combines technical analysis and risk management principles to provide a systematic trading approach. Its strengths lie in comprehensive trading rules and strict risk control, but traders need to understand its limitations and make appropriate optimizations based on actual trading conditions. Through continuous improvement and validation, the strategy has the potential to maintain stable performance across different market environments.
/*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)