策略
VWAP均线交叉动态ATR止损止盈策略-VWAP-Moving-Average-Crossover-with-Dynamic-ATR-Stop-Loss-and-Take-Profit-Strategy
ChaoZhang · PineScript · 波动率与通道 · 2024-04-01 10:51:46
概述
该策略基于VWAP(成交量加权平均价)指标与价格的交叉关系进行交易。当价格向上穿越VWAP时开多仓,向下穿越VWAP时开空仓。同时,利用ATR(平均真实波动幅度)指标计算动态止损和止盈水平,以控制风险和锁定利润。
策略原理
- 计算给定周期内的VWAP值,作为市场平均成本的参考。
- 判断价格与VWAP的交叉情况:当收盘价上穿VWAP时触发做多信号,下穿VWAP时触发做空信号。
- 使用ATR指标计算当前市场波动幅度,并根据ATR值和给定的倍数因子,设置动态止损和止盈水平。
- 开仓后,一旦价格达到止损或止盈水平,即平仓退出。
优势
- VWAP能够有效反映市场平均成本,与价格结合能更好判断趋势强度和潜在支撑/阻力位置。
- 动态止损和止盈基于ATR指标,能够适应不同市场状态下的波动幅度,控制风险的同时兼顾利润空间。
- 参数可调,如VWAP和ATR计算周期、止损止盈倍数等,可根据不同市场特点和风险偏好灵活设置。
风险
- VWAP作为趋势指标有一定滞后性,在震荡市中表现欠佳,可能产生较多虚假信号。
- 固定的ATR倍数止损止盈可能无法完全适应瞬息万变的市场情绪,导致止损过早或利润空间不足。
- 策略未考虑价格跳空缺口,开盘价直接跳过止损或止盈水平的情况,存在一定风险敞口。
优化方向
- 在VWAP基础上结合其他趋势指标或波动指标辅助判断,如MA、EMA等,提高信号可靠性。
- 对ATR倍数因子进行优化,引入自适应动态调整机制,根据近期价格波动特征动态调整倍数大小。
- 在止损止盈逻辑中加入价格跳空缺口处理,如开盘直接止损或止盈、挂单等应对机制。
- 考虑引入仓位管理和资金管理策略,如固定比例、固定风险等资金配置方法,提高整体回报风险比。
总结
该策略以VWAP为核心,通过与价格交叉产生交易信号,同时结合ATR实现动态止损止盈,在把握趋势的同时控制回撤风险,整体思路简单易懂。但策略还有进一步优化空间,通过引入辅助指标、优化止损止盈逻辑、加入资金管理等,可以更好地适应多变的市场环境,提升策略稳健性和盈利能力。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_1 | 40 | VWAP Period |
| v_input_2 | 14 | ATR Period |
| v_input_3 | 1.5 | ATR Multiplier for Stop Loss |
| v_input_4 | 3 | ATR Multiplier for Take Profit |
源码(44 行)
/*backtest
start: 2023-03-26 00:00:00
end: 2024-03-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Hannah Strategy Stop Loss and Take Profit", overlay=true)
// Inputs
cumulativePeriod = input(40, "VWAP Period")
atrPeriod = input(14, "ATR Period")
multiplier = input(1.5, "ATR Multiplier for Stop Loss")
targetMultiplier = input(3, "ATR Multiplier for Take Profit")
// Calculations for VWAP
typicalPrice = (high + low + close) / 3
typicalPriceVolume = typicalPrice * volume
cumulativeTypicalPriceVolume = sum(typicalPriceVolume, cumulativePeriod)
cumulativeVolume = sum(volume, cumulativePeriod)
vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume
// Plot VWAP on the chart
plot(vwapValue, color=color.blue, title="VWAP")
// Entry Conditions based on price crossing over/under VWAP
longCondition = crossover(close, vwapValue)
shortCondition = crossunder(close, vwapValue)
// ATR Calculation for setting dynamic stop loss and take profit
atr = atr(atrPeriod)
// Execute Trades with Dynamic Stop Loss and Take Profit based on ATR
if (longCondition)
strategy.entry("Long", strategy.long)
// Setting stop loss and take profit for long positions
strategy.exit("Long Exit", "Long", stop=close - atr * multiplier, limit=close + atr * targetMultiplier)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Setting stop loss and take profit for short positions
strategy.exit("Short Exit", "Short", stop=close + atr * multiplier, limit=close - atr * targetMultiplier)