Name
基于价格通道的VWAP交易策略Price-Channel-VWAP-Trading-Strategy
Author
ChaoZhang
Strategy Description
本策略名称为“Price Channel VWAP Trading Strategy”,它是一个基于价格通道来实现VWAP交易的策略。该策略的主要思想是:在价格通道内,利用VWAP指标的均线及其上下偏移通道线来进行买卖点判断,在突破通道线时按照固定头寸占总资产的百分比进行开仓,在回归VWAP均线时平仓。
该策略通过VWAP指标计算当前价格的平均成交价。VWAP代表价格的平均价,是成交额和成交量的比值。VWAP指标反映了当前价格和历史成交平均价的偏离程度。
策略使用VWAP指标的均线及其偏移通道线。偏移通道线的比例通过参数“longlevel1”和“shortlevel1”设置。当价格突破上偏移通道线时,按照参数“lotsizelong”的头寸百分比开多单;当价格突破下偏移通道线时,按照参数“lotsizeshort”的头寸百分比开空单。开仓后当价格回归到VWAP均线附近时,选择平仓离场。
该策略的参数设置充分反映了通道交易的思路。用户可以根据自己的偏好,调整通道宽度和头寸占比大小,从而实现不同程度的交易频率。
该交易策略具有以下几个优势:
- 使用VWAP指标判断价值中枢,能捕捉市场主流方向
- 通道范围内交易,避免noise干扰,使操作更明确
- 不同层级通道组合操作,分批分步部署,降低风险
- 回归操作及时止盈,避免快速反转带来的亏损
由于VWAP指标能很好地反映价格的平均水平,基于其通道线进行交易,可以有效锁定价值中枢,避免被短期波动带偏。同时采用不同参数通道进行组合,分批建仓,能够有效控制风险,防止单边风险集中爆仓。最后,通过及时止盈回归VWAP均线附近平仓,可以减少价格反转造成的损失。
该策略也存在一些风险需要注意:
- VWAP指标对高频交易不敏感,无法反映极端价格异常
- 通道宽度参数设置不当可能导致过于激进交易
- 回归操作平仓范围如果太宽可能带来套牢损失
VWAP指标对高频交易波动不敏感,如果遇到价格极端跳空或短期异常,依然会引发不必要的交易信号和亏损。此外,如果通道参数设置过于宽松,会容易形成价格穿透无效信号。最后,回归操作的平仓范围如果设置太宽,可能错过最佳止盈时机而套牢损失。
对策是合理评估参数设置,适当调整通道参数;同时结合其他指标判断价格异常,避免盲目跟单;最后评估不同层级通道及回归范围的参数优化,实现更好的止盈效果。
该策略可以从以下几个方向进行优化:
- 增加通道的层级,进行参数组合优化
- 结合交易量指标判断突破的有效性
- 增加止损策略,设置回撤比例止损
可以增加更多层级的通道线,并组合参数进行优化,实现更稳定的交易效果。此外,可以加入交易量的判断规则,避免无效的价格跳空造成交易亏损。最后,也可以设置止损规则,当持仓亏损达到一定比例时止损离场,有效控制风险。
本策略将VWAP指标与价格通道结合,实现了相对稳定的交易策略。策略参数设置灵活,用户可以根据自己的偏好进行调整。该策略能有效判断价值中枢方向,通过参数组合及分批建仓,实现稳定的盈利效果。虽然策略也存在一定改进空间,但总体来说是一种实用性较强的量化交易策略。
||
This strategy is called "Price Channel VWAP Trading Strategy". It is a strategy that implements VWAP trading based on price channels. The main idea of this strategy is: within the price channel, use the moving average line of the VWAP indicator and its upper and lower offset channel lines for buy and sell point judgment. When the channel lines are broken, open positions according to the fixed percentage of the total assets, and close positions when prices regress to the VWAP moving average line.
This strategy calculates the current average transaction price through the VWAP indicator. VWAP represents the average price and is the ratio of turnover to trading volume. The VWAP indicator reflects the degree of deviation between the current price and the historical average trading price.
The strategy uses the moving average line of the VWAP indicator and its offset channel lines. The proportions of the offset channel lines are set through the parameters "longlevel1" and "shortlevel1". When the price breaks through the upper offset channel line, open long positions according to the percentage of positions set by the parameter "lotsizelong"; when the price breaks through the lower offset channel line, open short positions according to the percentage of positions set by the parameter "lotsizeshort". After opening positions, choose to close positions when prices regress to around the VWAP moving average line.
The parameter settings of this strategy fully reflect the idea of channel trading. Users can adjust the channel width and size of positions as a percentage of total assets according to their own preferences, thereby realizing different degrees of trading frequency.
This trading strategy has the following advantages:
- Using VWAP indicators to determine value midpoints can capture mainstream market direction
- Trading within channel ranges avoids noise interference for clearer operation
- Combining channels of different levels, deploying in batches reduces risk
- Timely profit taking by regression avoids losses caused by rapid reversals
Since the VWAP indicator can well reflect the average price level, trading based on its channel lines can effectively lock in value midpoints and avoid being biased by short-term fluctuations. At the same time, combining channels with different parameters and building positions in batches can effectively control risks and prevent one-sided risk concentrations resulting in forced liquidations. Finally, by timely profit taking to close positions near the regression of the VWAP moving average line can reduce losses caused by price reversals.
This strategy also has some risks to note:
- The VWAP indicator is insensitive to high-frequency trading and cannot reflect extreme price anomalies
- Improper channel width parameter settings may lead to overly aggressive trading
- If the range of regression operations to close positions is too wide, it may cause trapped losses
The VWAP indicator is insensitive to high-frequency trading volatility. In case of extreme price gaps or short-term anomalies, it will still trigger unnecessary trading signals and losses. In addition, if the channel parameters are set too loose, it will easily form invalid price penetration signals. Finally, if the range of positions closing in regression operations is set too wide, it may miss the best timing for profit taking and cause trapped losses.
The countermeasures are to reasonably assess parameter settings and appropriately adjust channel parameters; while combining other indicators to judge price anomalies and avoid blind following signals; finally evaluating parameter optimization of channels of different levels and regression ranges to achieve better profit taking effects.
This strategy can be optimized in the following directions:
- Increase the level of channels and optimize parameter combinations
- Combine trading volume indicators to determine the validity of breakthroughs
- Add stop loss strategies and set stop loss by drawdown ratio
More levels of channel lines can be added and parameters combined for optimization to achieve more stable trading effects. In addition, trading volume judgment rules can be added to avoid invalid price gaps causing trading losses. Finally, stop loss rules can also be set so that when the loss of positions reaches a certain percentage, stop loss to exit positions, effectively controlling risks.
This strategy combines the VWAP indicator with price channels to achieve a relatively stable trading strategy. The strategy parameter settings are flexible for users to adjust according to their own preferences. This strategy can effectively determine the direction of value midpoints. Through parameter combination and batch building of positions, stable profitability can be achieved. Although there is still room for improvement in the strategy, overall it is a quantitative trading strategy with high practicality.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 100 | Lot long, % |
v_input_2 | 100 | Lot short, % |
v_input_3 | true | short 1 |
v_input_4 | true | long 1 |
v_input_5 | true | Short line 1 |
v_input_6 | -1 | Long line 1 |
v_input_7 | true | Offset |
v_input_8 | 1900 | From Year |
v_input_9 | 2100 | To Year |
v_input_10 | true | From Month |
v_input_11 | 12 | To Month |
v_input_12 | true | From day |
v_input_13 | 31 | To day |
Source (PineScript)
/*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")
Detail
https://www.fmz.com/strategy/442111
Last Modified
2024-02-19 14:25:18