Strategy · Pine Script v5 · Own pane

MACD VWMA Strategy

by g-moe· code credited to goodgains

This strategy calculates a Volume-Weighted Moving Average Convergence Divergence (VWMA MACD) and its histogram average to generate trade signals in a separate pane.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code79
Settings18inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

79 lines of Pine Script v5 from Tradingview/macd-vwma-strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

macd-vwma-strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
strategy("MACD VWMA Strategy", overlay=false, margin_long=100, margin_short=100)

// @keywords: macd, vwma-macd, volume-weighted-macd, histogram, signal-line, histogram-average, strategy-entry, strategy-close, crossover, crossunder, trading-hours, zero-line, lower-pane-oscillator, long-trades, short-trades, macd-histogram, fast-slow-ma, strategy-signals, panel-oscillator, entry-exit

// Getting inputs
fast_length = input(title="Fast Length", defval=13)
slow_length = input(title="Slow Length", defval=21)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 3)
sma_source = input.string(title="Oscillator MA Type",  defval="VWMA", options=["SMA", "EMA", "VWMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="VWMA", options=["SMA", "EMA", "VWMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating

fastMA = ta.ema(volume*close, fast_length)/ta.ema(volume, fast_length)
slowMA = ta.ema(volume*close, slow_length)/ta.ema(volume, slow_length)
vwmacd = fastMA - slowMA
signal = ta.ema(vwmacd, signal_length)
hist = vwmacd - signal
hline(0, "Zero Line", color=color.new(#787B86, 50))
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(vwmacd, title="MACD", color=col_macd, display = display.none)
plot(signal, title="Signal", color=col_signal, display = display.none)

strategy_length = input.int(title="Histogram Average",  minval = 1, maxval = 50, defval = 10)
hist_avg = ta.sma(hist, strategy_length)

plot(hist_avg, title = 'Histogram Average')



///////////////////////
/////CREATE SIGNALS////
///////////////////////
strategy_start = input.time(timestamp("01 January 2020 00:00:00 UTC-5"), "Strategy Start Date", group = "Strategy Settings", inline = '1')
use_trading_hours = input.bool(false, title = "Use Trading Hours", tooltip = "This is ignored if the chart timeframe is greater than or equal to the daily timeframe.", group = "Strategy Settings", inline = '2')
trading_time = input.session("0930-1600", title = " ", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "Strategy Settings", inline = '2')
trading_hours_cond = not use_trading_hours or time("",trading_time, "America/New_York")

long_trades = input.bool(true, title = "Long Trades", tooltip = "Do we want to take long trades?" , group = "Strategy Settings", inline = '3')
short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to take short trades?" , group = "Strategy Settings", inline = '4')

long_entry = long_trades and trading_hours_cond and ta.crossover(hist, hist_avg)
long_exit = not short_trades and ta.crossunder(hist, hist_avg)

short_entry = short_trades and trading_hours_cond and ta.crossunder(hist, hist_avg)
short_exit = not long_trades and ta.crossover(hist, hist_avg)

past_strategy_start_date = time >= strategy_start ? true : false


//ORDERS
if past_strategy_start_date

    //ENTRIES
    if long_entry
        strategy.entry("LE", direction = strategy.long)   
    else if short_entry
        strategy.entry("SS_E", direction = strategy.short)   
    
    //EXITS
    if long_exit
        strategy.close("LE", comment = "LX")
    else if short_exit
        strategy.close("SS_E", comment = "SS_X")
        
    if not trading_hours_cond
        strategy.close_all(comment = "TX", immediately = true)

Overview

MACD VWMA Strategy enters long positions when the MACD histogram crosses above its simple moving average and short positions when it crosses below. Users can filter trades by specific session hours, start date, and direction toggles. The script has no built-in stop loss or take profit orders, relying on signal crossovers or exits.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • 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
Fast Lengthint13fast_length
Slow Lengthint21slow_length
Sourcesourceclosesrc
Signal Smoothingint3signal_length
Oscillator MA TypestringVWMAsma_source
Signal Line MA TypestringVWMAsma_signal
MACD Line  color#2962FFcol_macd
Signal Line  color#FF6D00col_signal
Above   Growcolor#26A69Acol_grow_above
Fallcolor#B2DFDBcol_fall_above
Below Growcolor#FFCDD2col_grow_below
Fallcolor#FF5252col_fall_below
Show all 18 settings
SettingTypeDefaultVariable
Histogram Averageint10strategy_length
Strategy Start Datetimetimestamp("01 January 2020 00:00:00 UTC-5")strategy_start
Use Trading Hoursboolfalseuse_trading_hours
session0930-1600trading_time
Long Tradesbooltruelong_trades
Short Tradesbooltrueshort_trades
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

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD
13 stars

This strategy plots an On-Balance Volume oscillator in a separate pane and applies a fast and a slow exponential moving average to it. It enters long or short when those averages cross, with a strategy type that can reverse, stay long only, or stay short only,

Strategy v5 VolumeMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard QN OBVOsc A002
1 stars

This Pine Script strategy calculates the accumulation/distribution line with ta.accdist and its 21-period EMA. It plots these in a separate pane. The strategy issues long entries on ta.crossover of the accumulation/distribution line above its EMA and short ent

Strategy v6 VolumeMoving averages
Updated 7 days ago · Apache-2.0 GitHub repository of PF TA isolate - accdist EMA(21) cross
106 stars

This strategy enters long on an outside bar when the candle is bullish, the Klinger Volume Oscillator is positive, and price is above a Hull moving average. It enters short on an inside bar when the candle is bearish, the oscillator is negative, and price is b

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced OutSide Forex strategy
39 stars

This intraday strategy implements Mark Fisher's Opening Range Breakout (ORB) methodology tailored for index futures like ES and NQ. It calculates session opening ranges, volume z-scores, and VWAP bands to plot support, resistance, and confirmation levels on th

Strategy v6 BreakoutSessions & time Repaints
Updated 6 days ago · MIT GitHub repository of Futures Intraday Pro (ES/NQ) Strategy

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8

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