该策略使用日线的VWAP(成交量加权平均价)作为进场和出场的信号。当收盘价上穿VWAP时触发做多,止损设置在VWAP下方的前一根K线低点,目标价设置在开仓价上方3个点;当收盘价下穿VWAP时触发做空,止损设置在VWAP上方的前一根K线高点,目标价设置在开仓价下方3个点。该策略没有包含出场条件,交易会一直持有直到反向信号出现。
通过跨周期的VWAP数据判断趋势,同时利用动态止损和固定点数止盈,可以有效把握趋势行情,控制回撤风险,并及时锁定利润。
该策略利用跨周期VWAP数据进行趋势判断和信号触发,同时采用动态止损和固定点数止盈的方式控制风险和锁定利润,是一个简单有效的量化交易策略。通过趋势过滤、动态止盈、仓位管理和交易时段选择等方面的优化,可以进一步提高策略的稳健性和收益潜力。但在实际应用中,仍需注意市场特点、交易成本和参数优化等因素,以期获得更好的策略表现。
/*backtest
start: 2024-03-06 00:00:00
end: 2024-03-07 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('Pine Script Tutorial Example Strategy 1', overlay=true, initial_capital=1000, default_qty_value=100, default_qty_type=strategy.percent_of_equity)
// fastEMA = ta.ema(close, 24)
// slowEMA = ta.ema(close, 200)
// Higher Time Frame
float sl = na
float tgt = na
posSize = 1
vwap_1d = request.security(syminfo.tickerid, "1D", ta.vwap(close))
// plot(vwap_1d)
// To avoid differences on historical and realtime bars, you can use this technique, which only returns a value from the higher timeframe on the bar after it completes:
// indexHighTF = barstate.isrealtime ? 1 : 0
// indexCurrTF = barstate.isrealtime ? 0 : 1
// nonRepaintingVWAP = request.security(syminfo.tickerid, "1D", close[indexHighTF])[indexCurrTF]
// plot(nonRepaintingVWAP, "Non-repainting VWAP")
enterLong = ta.crossover(close, vwap_1d)
exitLong = ta.crossunder(close, vwap_1d)
enterShort = ta.crossunder(close, vwap_1d)
exitShort = ta.crossover(close, vwap_1d)
if enterLong
sl := low[1]>vwap_1d ?low[1]:vwap_1d
tgt:=close+3
strategy.entry("EL", strategy.long, qty=posSize)
strategy.exit('exitEL', 'EL', stop=sl, limit=tgt)
if enterShort
sl := high[1]<vwap_1d ?high[1]:vwap_1d
tgt := close-3
strategy.entry("ES", strategy.short, qty=posSize)
strategy.exit('exitES', 'ES', stop=sl, limit=tgt)
// if exitLong
// strategy.close("EL")
// if exitShort
// strategy.close("ES")
// goLongCondition1 = ta.crossover(close, vwap_1d)
// timePeriod = time >= timestamp(syminfo.timezone, 2021, 01, 01, 0, 0)
// notInTrade = strategy.position_size <= 0
// if goLongCondition1 and timePeriod and notInTrade
// stopLoss = low[1]
// takeProfit = close+3
// strategy.entry('long', strategy.long)
// strategy.exit('exit', 'long', stop=stopLoss, limit=takeProfit)
plot(close, color=color.new(#00c510, 0))
plot(vwap_1d, color=color.new(#f05619, 0))
plot(sl, color=color.new(#fbff00, 0))
plot(tgt, color=color.new(#00e1ff, 0))