该策略是一个基于EMA、VWAP和成交量的交易策略。主要思路是在特定的交易时间内,当收盘价突破VWAP和EMA,且成交量大于前一根K线的成交量时产生开仓信号。同时设置了止损和止盈,以及在特定时间段内平仓的条件。
该策略通过综合考虑价格趋势、市场公允价值和成交量,在特定的交易时间内进行交易。虽然设置了止损止盈和限定交易时间,但在实际应用中仍需注意震荡市和滑点等风险。未来可以通过加入更多过滤条件、优化参数和仓位管理等方式来提高策略的稳健性和盈利能力。
/*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)