策略
VWAP交易策略-VWAP-Trading-Strategy
ChaoZhang · PineScript · 波动率与通道 · 2024-04-29 14:20:39
概述
该策略是一个基于EMA、VWAP和成交量的交易策略。主要思路是在特定的交易时间内,当收盘价突破VWAP和EMA,且成交量大于前一根K线的成交量时产生开仓信号。同时设置了止损和止盈,以及在特定时间段内平仓的条件。
策略原理
- 计算EMA和VWAP指标。
- 判断是否在指定的交易时间内。
- 多头开仓条件:收盘价大于VWAP和EMA,成交量大于前一根K线,并且收盘价大于开盘价。
- 空头开仓条件:收盘价小于VWAP和EMA,成交量大于前一根K线,并且开盘价大于收盘价。
- 多头平仓条件:收盘价跌破VWAP或EMA,达到止盈或止损点位,或者到达指定的离场时间。
- 空头平仓条件:收盘价突破VWAP或EMA,达到止盈或止损点位,或者到达指定的离场时间。
优势
- 同时考虑了价格趋势(EMA)、市场公允价值(VWAP)和成交量,开仓条件更加严格,有助于提高策略的胜率。
- 设置了止损和止盈,以控制风险和锁定利润。
- 限定了交易时间和离场时间,避免了在非交易时段和持仓过夜的风险。
风险
- 该策略在震荡市中表现可能不佳,因为频繁的突破和回撤可能导致多次开仓和平仓,从而增加交易成本和滑点。
- 止损点位是固定的,在行情剧烈波动时,可能会被提前触发,导致策略承受较大损失。
- 该策略未考虑实际的市场深度和委托情况,在实盘交易中可能面临滑点和开仓失败等问题。
优化方向
- 可以考虑加入更多的过滤条件,如ATR、RSI等指标,以进一步确认趋势和动量的强度。
- 止损和止盈点位可以设置为动态的,如跟随ATR或百分比止损,以适应不同的市场波动。
- 可以对参数进行优化,如EMA长度、VWAP来源、止损止盈点位等,以提高策略的稳定性和盈利能力。
- 可以考虑加入仓位管理,如根据波动率或资金比例调整开仓量,以控制整体风险。
总结
该策略通过综合考虑价格趋势、市场公允价值和成交量,在特定的交易时间内进行交易。虽然设置了止损止盈和限定交易时间,但在实际应用中仍需注意震荡市和滑点等风险。未来可以通过加入更多过滤条件、优化参数和仓位管理等方式来提高策略的稳健性和盈利能力。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_int_1 | 21 | EMA Length |
| v_input_source_1_hlc3 | 0 | VWAP Source: hlc3 |
| v_input_float_1 | 100 | Stop Loss (points) |
| v_input_float_2 | 200 | Target (points) |
| v_input_1 | 0950-1430 | Only take entry during |
| v_input_2 | 1515-1525 | Exit Trade |
源码(50 行)
/*backtest
start: 2024-04-27 00:00:00
end: 2024-04-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA, VWAP, Volume Strategy", overlay=true, process_orders_on_close=true)
// Inputs
emaLength = input.int(21, title="EMA Length")
vwapSource = input.source(defval=hlc3, title='VWAP Source')
stopLossPoints = input.float(100, title="Stop Loss (points)")
targetPoints = input.float(200, title="Target (points)")
session = input("0950-1430", title='Only take entry during')
exit = input(defval='1515-1525', title='Exit Trade')
tradein = not na(time(timeframe.period, session))
exit_time = not na(time(timeframe.period, exit))
// Calculate indicators
ema = ta.ema(close, emaLength)
vwapValue = ta.vwap(vwapSource)
// Entry Conditions
longCondition = close > vwapValue and close > ema and volume > volume[1] and close > open and tradein
shortCondition = close < vwapValue and close < ema and volume > volume[1] and open > close and tradein
// Exit Conditions
longExitCondition = ta.crossunder(close, vwapValue) or ta.crossunder(close, ema) or close - strategy.position_avg_price >= targetPoints or close - strategy.position_avg_price <= -stopLossPoints or exit_time
shortExitCondition = ta.crossover(close, vwapValue) or ta.crossover(close, ema) or strategy.position_avg_price - close >= targetPoints or strategy.position_avg_price - close <= -stopLossPoints or exit_time
// Plotting
plot(vwapValue, color=color.blue, title="VWAP")
plot(ema, color=color.green, title="EMA")
// Strategy
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
if longExitCondition
strategy.close('Long', immediately=true)
if shortExitCondition
strategy.close("Short", immediately=true)