
This strategy combines Volume Weighted Average Price (VWAP) and Moving Average Convergence Divergence (MACD) for quantitative trading. It seeks optimal entry and exit points in market trends by combining price momentum indicators with volume weighting. The strategy uses VWAP as a crucial price reference level while utilizing MACD to capture market momentum changes, enabling more precise trading position timing.
The core logic is based on the following key elements: 1. VWAP calculates the volume-considered average price level to determine if current price is favorably positioned 2. MACD consists of fast EMA (12 periods) and slow EMA (26 periods) to capture price momentum 3. Long condition: MACD line crosses above signal line and price is above VWAP 4. Short condition: MACD line crosses below signal line and price is below VWAP 5. Exit logic: Close positions when MACD shows reverse crossover signals or price breaks VWAP
The VWAP-MACD dual indicator strategy provides reliable technical support for trading decisions by combining volume-weighted and momentum analysis. The strategy design is reasonable, logic is clear, and it has good practicality and scalability. Through continuous optimization and risk management improvements, this strategy has the potential to achieve stable returns in actual trading. Traders are advised to conduct thorough backtesting before live implementation and adjust parameters according to specific market characteristics.
/*backtest
start: 2025-01-08 00:00:00
end: 2025-02-06 08:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("VWAP + MACD Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// VWAP Calculation
vwapValue = ta.vwap(close)
// MACD Settings
fastLength = input.int(12, title="MACD Fast Length")
slowLength = input.int(26, title="MACD Slow Length")
signalSmoothing = input.int(9, title="MACD Signal Smoothing")
// MACD Calculation
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
macdHistogram = macdLine - signalLine
// Plot VWAP
plot(vwapValue, color=color.orange, title="VWAP")
// Plot MACD
hline(0, "Zero Line", color=color.gray)
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.red, title="Signal Line")
plot(macdHistogram, color=(macdHistogram >= 0 ? color.green : color.red), style=plot.style_histogram, title="MACD Histogram")
// Long Condition: MACD crosses above Signal and price is above VWAP
longCondition = ta.crossover(macdLine, signalLine) and close > vwapValue
if (longCondition)
strategy.entry("Long", strategy.long)
// Short Condition: MACD crosses below Signal and price is below VWAP
shortCondition = ta.crossunder(macdLine, signalLine) and close < vwapValue
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit Long: MACD crosses below Signal or price crosses below VWAP
exitLong = ta.crossunder(macdLine, signalLine) or close < vwapValue
if (exitLong)
strategy.close("Long")
// Exit Short: MACD crosses above Signal or price crosses above VWAP
exitShort = ta.crossover(macdLine, signalLine) or close > vwapValue
if (exitShort)
strategy.close("Short")