可扩展突破交易策略通过识别价格的关键支撑阻力区域,在价格突破这些区域时生成交易信号,是一个非常灵活可扩展的突破策略。该策略可以通过调整参数适用于不同时间周期,也可以轻松地集成各种额外的过滤条件和风险管理机制,从而针对特定资产进行优化。
该策略首先利用swings()
函数基于回看期计算出当前价格的波动高点和波动低点。回看期通过swingLookback
参数设置,默认为20根K线。之后,当价格突破波动高点时,做多;当价格跌破波动低点时,做空。
做多信号的具体逻辑是,当收盘价大于等于波动高价时,做多。做空信号的具体逻辑是,当收盘价小于等于波动低价时,做空。
此外,策略还设置了止损位,通过stopTargetPercent
参数来设定止损幅度。如做多止损价设置为最高价的5%以下,做空止损价设置为最低价的5%以上。
该策略的优势在于可以通过调整回看期来控制交易频率。回看期越短,对突破越敏感,交易频率越高。回看期过长则相反,交易频率下降但可能错过机会。所以找到最佳回看期对策略优化很关键。
对策:
该策略可以从以下几个方面进行优化:
测试不同的回看期参数,找到最优参数组合;
测试不同的交易周期,如5分钟、15分钟、1小时等,选择最佳周期;
优化止损幅度,平衡获利空间和风险控制;
增加过滤条件,如交易量过滤,涨跌幅过滤等,减少不优质信号;
集成更多风险管理机制,如移动止损、锁定利润等;
参数优化,使用步进优化、随机搜索等找到最优参数;
集成机器学习技术,利用AI对参数进行自动优化。
可扩展突破交易策略是一个非常实用的突破系统。它简单易用,可定制性强,可以通过调整回看期和集成各种过滤条件来针对不同资产进行优化。同时,可轻松集成各类风险管理机制来控制交易风险。通过参数优化和机器学习等技术的引入,该策略可以不断升级,适应市场的变化。总体来说,它是一个值得推荐的通用突破策略。
/*backtest start: 2023-09-29 00:00:00 end: 2023-10-29 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © deperp //@version=5 // strategy("Range Breaker", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.07, pyramiding=0) // Backtest Time Period useDateFilter = input.bool(true, title="Begin Backtest at Start Date", group="Backtest Time Period") backtestStartDate = input(timestamp("1 Jan 2020"), title="Start Date", group="Backtest Time Period", tooltip="This start date is in the time zone of the exchange " + "where the chart's instrument trades. It doesn't use the time " + "zone of the chart or of your computer.") inTradeWindow = true swingLookback = input.int(20, title="Swing Lookback", minval=3) stopTargetPercent = input.float(5, title="Stop Target Percentage", step=0.1) // Calculate lockback swings swings(len) => var highIndex = bar_index var lowIndex = bar_index var swingHigh = float(na) var swingLow = float(na) upper = ta.highest(len) lower = ta.lowest(len) if high[len] > upper highIndex := bar_index[len] swingHigh := high[len] if low[len] < lower lowIndex := bar_index[len] swingLow := low[len] [swingHigh, swingLow, highIndex, lowIndex] // Strategy logic [swingHigh, swingLow, highIndex, lowIndex] = swings(swingLookback) longCondition = inTradeWindow and (ta.crossover(close, swingHigh)) shortCondition = inTradeWindow and (ta.crossunder(close, swingLow)) if longCondition strategy.entry("Long", strategy.long) if shortCondition strategy.entry("Short", strategy.short) longStopTarget = close * (1 + stopTargetPercent / 100) shortStopTarget = close * (1 - stopTargetPercent / 100) strategy.exit("Long Stop Target", "Long", limit=longStopTarget) strategy.exit("Short Stop Target", "Short", limit=shortStopTarget) // Plot break lines // line.new(x1=highIndex, y1=swingHigh, x2=bar_index, y2=swingHigh, color=color.rgb(255, 82, 82, 48), width=3, xloc=xloc.bar_index, extend=extend.right) // line.new(x1=lowIndex, y1=swingLow, x2=bar_index, y2=swingLow, color=color.rgb(76, 175, 79, 47), width=3, xloc=xloc.bar_index, extend=extend.right) // Alert conditions for entry and exit longEntryCondition = inTradeWindow and (ta.crossover(close, swingHigh)) shortEntryCondition = inTradeWindow and (ta.crossunder(close, swingLow)) longExitCondition = close >= longStopTarget shortExitCondition = close <= shortStopTarget alertcondition(longEntryCondition, title="Long Entry Alert", message="Enter Long Position") alertcondition(shortEntryCondition, title="Short Entry Alert", message="Enter Short Position") alertcondition(longExitCondition, title="Long Exit Alert", message="Exit Long Position") alertcondition(shortExitCondition, title="Short Exit Alert", message="Exit Short Position")