VWAP Based on Lookback Period for ThinkorSwim


Active member
i didnt know what to call this so i gave it this name, basically the point of this indicator is to tell you when the stock is trading based on the vwap of the last 50 bars, you can choose 21, 9, or whatever bars you want to look back, the cool thing about this indicator is that as time goes on its constantly moving with the current last 50 bars. the thing to keep in mind is that since price is moving and so is the wvap looking back will not help you to much i believe, the accurate thing that this will show you is the current price with the set current vwap with a lookback period. give it a try, or comment on what could be fixed about this indicator. i think the best ideas is when people share ideas.


# TD Ameritrade IP Company, Inc. (c) 2007-2020

declare lower;

input slowLength = 4;
input MACDLength = 9;
input BarsBack = 50;  
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;


def currentBar = if isnan(close[-1]) and !isnan(close)   

then barnumber()   

else currentBar[1];  

def barCount = if barnumber()== 1   

then highestall(currentBar)   

else if barCount[1] > 1   

then barCount[1] - 1   

else 0;  

plot count = if barCount == BarsBack then barCount else double.nan;  


plot Number1 = if barCount == barsBack then low - (3* TickSize()) else double.nan;  




def LocH = (hl2) * volume;
def LocL = (hl2) * volume;
rec PH;
rec VH;

if count {
    PH = LocH;
    VH = volume;
} else {
    PH = compoundValue(1, LocH + PH[1], Double.NaN);
    VH = compoundValue(1, volume + VH[1], Double.NaN);

DEF Vw =  PH / VH;

plot Value = MovingAverage(averageType, close, slowLength)-vw;
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff =50* (Value - Avg);
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;


Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
200 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.