本策略名称为“Price Channel VWAP Trading Strategy”,它是一个基于价格通道来实现VWAP交易的策略。该策略的主要思想是:在价格通道内,利用VWAP指标的均线及其上下偏移通道线来进行买卖点判断,在突破通道线时按照固定头寸占总资产的百分比进行开仓,在回归VWAP均线时平仓。
该策略通过VWAP指标计算当前价格的平均成交价。VWAP代表价格的平均价,是成交额和成交量的比值。VWAP指标反映了当前价格和历史成交平均价的偏离程度。
策略使用VWAP指标的均线及其偏移通道线。偏移通道线的比例通过参数“longlevel1”和“shortlevel1”设置。当价格突破上偏移通道线时,按照参数“lotsizelong”的头寸百分比开多单;当价格突破下偏移通道线时,按照参数“lotsizeshort”的头寸百分比开空单。开仓后当价格回归到VWAP均线附近时,选择平仓离场。
该策略的参数设置充分反映了通道交易的思路。用户可以根据自己的偏好,调整通道宽度和头寸占比大小,从而实现不同程度的交易频率。
该交易策略具有以下几个优势:
由于VWAP指标能很好地反映价格的平均水平,基于其通道线进行交易,可以有效锁定价值中枢,避免被短期波动带偏。同时采用不同参数通道进行组合,分批建仓,能够有效控制风险,防止单边风险集中爆仓。最后,通过及时止盈回归VWAP均线附近平仓,可以减少价格反转造成的损失。
该策略也存在一些风险需要注意:
VWAP指标对高频交易波动不敏感,如果遇到价格极端跳空或短期异常,依然会引发不必要的交易信号和亏损。此外,如果通道参数设置过于宽松,会容易形成价格穿透无效信号。最后,回归操作的平仓范围如果设置太宽,可能错过最佳止盈时机而套牢损失。
对策是合理评估参数设置,适当调整通道参数;同时结合其他指标判断价格异常,避免盲目跟单;最后评估不同层级通道及回归范围的参数优化,实现更好的止盈效果。
该策略可以从以下几个方向进行优化:
可以增加更多层级的通道线,并组合参数进行优化,实现更稳定的交易效果。此外,可以加入交易量的判断规则,避免无效的价格跳空造成交易亏损。最后,也可以设置止损规则,当持仓亏损达到一定比例时止损离场,有效控制风险。
本策略将VWAP指标与价格通道结合,实现了相对稳定的交易策略。策略参数设置灵活,用户可以根据自己的偏好进行调整。该策略能有效判断价值中枢方向,通过参数组合及分批建仓,实现稳定的盈利效果。虽然策略也存在一定改进空间,但总体来说是一种实用性较强的量化交易策略。
/*backtest start: 2023-02-12 00:00:00 end: 2024-02-18 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title = "VWAP Bands Backtest", shorttitle = "VWAP Bands Backtest", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 3) //Settings lotsizelong = input(100, defval = 100, minval = 0, maxval = 10000, title = "Lot long, %") lotsizeshort = input(100, defval = 100, minval = 0, maxval = 10000, title = "Lot short, %") short1 = input(true, title = "short 1") long1 = input(true, title = "long 1") shortlevel1 = input(1.0, title = "Short line 1") longlevel1 = input(-1.0, title = "Long line 1") needoffset = input(true, title = "Offset") fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year") toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year") frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month") tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month") fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day") today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day") //Variables size = strategy.position_size mult = 1 / syminfo.mintick truetime = true //VWAP ma = vwap(hlc3) //Levels longline1 = long1 ? round(ma * ((100 + longlevel1) / 100) * mult) / mult : close shortline1 = short1? round(ma * ((100 + shortlevel1) / 100) * mult) / mult : close //Lines colorlong1 = long1 ? color.lime : na colorshort1 = short1 ? color.red : na offset = needoffset ? 1 : 0 plot(shortline1, offset = offset, color = colorshort1, title = "Short line 1") plot(ma, offset = offset, color = color.blue, title = "MA line") plot(longline1, offset = offset, color = colorlong1, title = "Long line 1") //Trading lotlong = 0.0 lotshort = 0.0 lotlong := size == 0 ? (strategy.equity / close) * (lotsizelong / 100) : lotlong[1] lotshort := size == 0 ? (strategy.equity / close) * (lotsizeshort / 100) : lotshort[1] if ma > 0 if lotlong > 0 lotslong = 0.0 lotslong := strategy.position_size > 0 ? round(strategy.position_size / lotlong) : 0.0 strategy.entry("L1", strategy.long, lotlong, limit = longline1, when = (lotslong == 0 and long1 and truetime)) if lotshort > 0 lotsshort = 0.0 lotsshort := strategy.position_size < 0 ? round(strategy.position_size / lotshort) : 0.0 strategy.entry("S1", strategy.short, lotshort, limit = shortline1, when = (lotsshort == 0 and short1 and truetime)) if strategy.position_size > 0 strategy.exit("TPL", "L1", limit = ma) if strategy.position_size < 0 strategy.exit("TPS", "S1", limit = ma) if time > timestamp(toyear, tomonth, today, 23, 59) strategy.close_all() strategy.cancel("L1") strategy.cancel("S1") strategy.cancel("TPL") strategy.cancel("TPS")