Skip to content

Instantly share code, notes, and snippets.

@major
Created February 3, 2025 13:04
Show Gist options
  • Save major/f33289da5ca3c6459298aa5efe580798 to your computer and use it in GitHub Desktop.
Save major/f33289da5ca3c6459298aa5efe580798 to your computer and use it in GitHub Desktop.
SMA/VWMA TradingView Indicator
//@version=6
indicator(title="SMA vs VWMA (thetanerd) πŸ€“", shorttitle="SMA/VWMA πŸ€“", overlay=true, timeframe="", timeframe_gaps=true)
// MarketSurge colors by default, just because.
defaultSMAColor = color.new(#e040fb, 0)
defaultVWMAColor = color.new(#2962ff, 0)
// CONFIGURABLES
var GRP0 = "Let's get nerdy because why not? πŸ€“"
len = input.int(50, minval=1, title="Length", group=GRP0)
src = input(close, title="Source", group=GRP0)
var GRP1 = "Line colors"
smaColor = input.color(color.new(#e040fb, 35), title="SMA", inline="colors", group=GRP1)
vwmaColor = input.color(color.new(#2962ff, 35), title="VWMA", inline="colors", group=GRP1)
var GRP2 = "Fill colors"
fillColorDown = input.color(color.new(#2962ff, 85), title="SMA above VWMA", group=GRP2)
fillColorUp = input.color(color.new(#e040fb, 85), title="VWMA above SMA", group=GRP2)
// Set up the two MA lines and plot them.
sma = ta.sma(src, len)
vwma = ta.vwma(src, len)
plotSMA = plot(sma, color=smaColor, title="SMA")
plotVWMA = plot(vwma, color=vwmaColor, title="VWMA")
// Apply fill between SMA and VWMA
fillColor = sma > vwma ? fillColorUp : fillColorDown
fill(plotSMA, plotVWMA, color=fillColor)
// Everyone likes an alert from time to time. πŸ˜‰
alertcondition(ta.crossover(sma, vwma), title="SMA Crosses Above VWMA", message="SMA has crossed above VWMA!")
alertcondition(ta.crossover(vwma, sma), title="VWMA Crosses Above SMA", message="VWMA has crossed above SMA!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment