Strategy · Pine Script v5 · On the chart

MACD & Anchored VWAP Strategy

by adminalphabots

This strategy enters long when the MACD line crosses above its signal, price is above a rolling VWAP, and ADX is at least the minimum trend strength.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code46
Settings6inputs
LicenceMIT
Last update8 months ago28 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

46 lines of Pine Script v5 from tradingview/strategies/macd_vwap_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

macd_vwap_strategy.pine
//@version=5
strategy("MACD & Anchored VWAP Strategy", overlay=true)

// === Input Parameters ===
fastMACD = input.int(12, "MACD Fast Length")
slowMACD = input.int(26, "MACD Slow Length")
signalPeriods = input.int(9, "MACD Signal Periods")
vwapBars = input.int(20, "VWAP Rolling Bars", minval=1)
minADX = input.int(20, "Minimum ADX Trend Strength")

// === Indicators ===
[macdLine, signalLine, _] = ta.macd(close, fastMACD, slowMACD, signalPeriods)
// Rolling VWAP calculation
varip float cumulativePV = 0.0
varip float cumulativeVol = 0.0
varip int barsCount = 0

if bar_index % vwapBars == 0
    cumulativePV := close * volume
    cumulativeVol := volume
    barsCount := 1
else
    cumulativePV += close * volume
    cumulativeVol += volume
    barsCount += 1

vwap = cumulativePV / cumulativeVol
[adx, _, _] = ta.dmi(14, 14)

// === Entry Conditions ===
longCondition = ta.crossover(macdLine, signalLine) and close > vwap and adx >= minADX
shortCondition = ta.crossunder(macdLine, signalLine) and close < vwap and adx >= minADX

// === Strategy Execution ===
if (longCondition)
    strategy.entry("MACD-VWAP Long", strategy.long)
    
if (shortCondition)
    strategy.entry("MACD-VWAP Short", strategy.short)

// === Alert Messages ===
symbolName = input.string("NSE:NIFTY25APRFUT", "Alert Symbol")
alertJson = '{"order":[{"type":"ENTRY","symbol":"' + symbolName + '","side":"' + (longCondition ? "B" : "S") + '"}]}'
alert(alertJson, alert.freq_once_per_bar_close)

plot(vwap, "Rolling VWAP", color=color.purple)

Overview

MACD & Anchored VWAP Strategy enters short on the opposite MACD cross when price is below that VWAP and ADX meets the same threshold. Settings change MACD lengths, the VWAP reset window, the ADX cutoff, and the alert symbol. It draws the rolling VWAP on the price chart. There are no exit, stop-loss, or take-profit rules. Values built with varip can change on the live bar.

Details

Published by

adminalphabots on GitHub

Draws

On the price chart

Markets

Indices

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
MACD Fast Lengthint12fastMACD
MACD Slow Lengthint26slowMACD
MACD Signal Periodsint9signalPeriods
VWAP Rolling Barsint20vwapBars
Minimum ADX Trend Strengthint20minADX
Alert SymbolstringNSE:NIFTY25APRFUTsymbolName
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Altered OBV On MACD

by hasnocool
106 stars

This strategy calculates and plots 9, 21, 50, 90, and 200-period Simple Moving Averages on the main price chart. It constructs a modified On-Balance Volume (OBV) metric and calculates a MACD oscillator based on this custom volume series rather than price. Long

Strategy v5 Moving averagesVolume
Updated 2 years ago · GPL-3.0 GitHub repository of Altered OBV On MACD
12 stars

This strategy plots on the price chart and looks for three-candle fair value gaps and inverse gaps on Bitcoin. It enters long when a wide enough bullish gap appears in an uptrend with RSI above 30 and volume above its average, and short on the opposite bearish

Strategy v6 SMC / ICT / price actionTrend Repaints
Updated 4 months ago · None stated GitHub repository of BTC 4h FVG/iFVG Strategy

Combined Strategy

by Dropio12
7 stars

This strategy plots buy and sell markers on the price chart by combining a fast and slow ALMA crossover with a simple close-to-close momentum check. A long marker appears when the fast ALMA crosses above the slow ALMA and momentum is positive. A short marker a

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Combined Strategy
6 stars

Capital41 Fusion Core Strategy is an overlay trading strategy that combines an exponential moving average trend filter, RSI, Williams %R, and volume/ATR expansion into a composite momentum oscillator. It executes long trades when the smoothed oscillator crosse

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MIT GitHub repository of Capital41 Fusion Core Strategy

Antigravity Superstar

by eltonaguiar
4 stars

This strategy draws on the price chart and combines a triple EMA stack, a volume spike with a minimum price move, and a MACD line-signal crossover. It enters long or short only when at least the chosen number of those three signals agree, with an optional RSI

Strategy v6 TrendMoving averages
Updated 2 days ago · None stated GitHub repository of Antigravity Superstar
4 stars

This strategy draws on the price chart and is set up for daily ETF trading. It can enter through a classic surge-and-consolidation breakout, a pullback toward stacked EMAs, a relative-volume spike with price momentum, or a pause inside a strong trend. EMA leng

Strategy v6 BreakoutTrend
Updated 7 months ago · None stated GitHub repository of Qullamaggie Breakout Strategy

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers