SPY VWAP For ThinkOrSwim

Hutch

New member
VIP
The author states:
SPY VWAP adds the VWAP indicator for SPY on your current chart, and shows the current SPY VWAP level converted to ES / MES value. It uses the last close price of SPY and ES / MES to calculate the level.

By adding the regular VWAP indicator to your MES / ES chart, you will clearly see the difference between the VWAP of SPY and the futures chart. This is helpful when trading as price may respect both VWAP levels.

This indicator should only be used on ES and MES futures chart. It will behave weirdly if used on different tickers and it is not supported in the current version.
MGS3gxg.png



would deeply appreciate the gurus here to please take a look at the original TV code:
https://www.tradingview.com/script/AZLVVm1t-SPY-VWAP/
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

The following works perfectly on tradingview and returns excellent entry/exit targets.
I can get the spy vwap to show on the /es chart, but I am struggling with the conversion to /ES scale, and the spy vwap does not always plot (gaps for no apparent reason), and I have no clue how to approach the "smoothing". Could also work with /NQ-QQQ if inputs are adjustable.
Perhaps this is a limitation with TOS. Rather than post my cobbled up attempts with thinkscript, would deeply appreciate the gurus here to please take a look at the original TV code:

//@version=5
indicator(title="SPY VWAP", shorttitle = "SPY VWAP", overlay=true)

input_vwap_source = input.source(defval = hlc3, title = "VWAP Source", tooltip = "Source used to calculate VWAP")
input_vwap_smoothing = input.int(defval = 5, title = "VWAP Smoothing", minval = 0 , maxval = 9, tooltip = "Min 0, Max 9. SMA to smooth VWAP line, evens out the calculation flucations but will cause inaccuracy if set too high. 0 for no smoothing.")

// Calculate SPY to ES ratio
t = ticker.new("amex", "SPY", session.extended)
SPYClose = request.security(t, timeframe.period, close, barmerge.gaps_on)
CurClose = request.security(symbol = syminfo.ticker, timeframe = timeframe.period, expression = close)
Diff = CurClose / SPYClose

// Calculate corect value of SPY VWAP
spyvwap = request.security(t, timeframe.period, ta.vwap(input_vwap_source)) * Diff
line_spy_vwap = if input_vwap_smoothing >= 1
ta.sma(source = spyvwap, length = input_vwap_smoothing)
else
spyvwap

// Plot SPY VWAP
plot(line_spy_vwap, color = color.white, linewidth = 2, title = "SPY VWAP")


View attachment 18909
The above shows /ES vwap in purple, converted spy vwap in blue. This is what I'm looking for as an end result. TIA
check the below.
P.S: disable the future extended hours.

CSS:
#//@version=5
#indicator(title="SPY VWAP", shorttitle = "SPY VWAP", overlay=true)
# Converted by Sam4Cok@Samer800    - 04/2024

input vwap_source = FundamentalType.HLC3; #, title = "VWAP Source"
input vwap_smoothing = 3; # "VWAP Smoothing"


def na = Double.NaN;
def last = isNaN(close);
#// Calculate SPY to ES ratio
def spCl = close(Symbol = "SPY");
def spVol = volume(Symbol = "SPY");
def spSrc = Fundamental(FundamentalType = vwap_source, Symbol = "SPY");
def CurClose = close;

def time = GetTime();
def yyyyMmDd = GetYYYYMMDD();
def rth = !isNaN(spCl) and !isNaN(spVol) and !isNaN(spSrc) and !isNaN(CurClose) and
            (spCl>0) and (spVol>0) and (spSrc>0) and (CurClose>0);

def SPYClose;def vol; def src; def diff; #CurClose;
if rth {
    SPYClose = spCl;
    vol = spVol;
    src = spSrc;
    Diff = CurClose / SPYClose;
    } else {
    SPYClose = SPYClose[1];
    vol = vol[1];
    src = src[1];
    Diff = Diff[1];
}

def isPeriodRolled = compoundValue(1, yyyyMmDd!=yyyyMmDd[1], yes);

def volumeSum;
def volumeVwapSum;
if !rth {
    volumeSum = volumeSum[1];
    volumeVwapSum = volumeVwapSum[1];
 } else if (isPeriodRolled) {
    volumeSum = vol;
    volumeVwapSum = vol * src;
} else {
    volumeSum = compoundValue(1, volumeSum[1] + vol, vol);
    volumeVwapSum = compoundValue(1, volumeVwapSum[1] + vol * src, vol * src);
}
def price = volumeVwapSum / volumeSum;
def VWAP1 = price * Diff;
def avgVWAP1 = Average(VWAP1, vwap_smoothing);
def VWAP =  if vwap_smoothing > 0 then avgVWAP1 else VWAP1;

plot avgVwap = if last then na else VWAP;
avgVwap.setDefaultColor(getColor(0));

#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
399 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top