VWAP Trend Skew For ThinkOrSwim

ysanchezmd

New member
VIP
Hi Mashume, can you help me to thinkscript the computation of the third central moment in the skewed distribution I am not educated in statistics, so I needed to read a few articles in Wikipedia. plus Jerry Perl article Trading with Market Statistics on Traders Laboratory. I had tried the formula (skew = vwap - vpoc /sd) but this may be better.


CM3 = sum(PROBi * (Pi - VWAP)^3),

where

i is going through all prices in range (i.e. all rows in Volume Distribution Function)

CM3 ... the 3rd Central Moment

PROBi = Vi / V ... ith price probability (Volume per ith price / Total Volume)

Pi ... ith price in the Vol. Dist. function



Then the Skew would be calculated as

Skew = CM3 / SD^3

I point of view is if we know the prediction of the price for the next hour and the skew, that will be a better edge trading the instrument. If the prediction is up and the skew is above vwap ( positive) then we has a bullish bias ....

Sorry my English is not very good looking ..........

As per Jerry Perl the distribution function itself tells you the trend bias and strength based on the strength of the skewThe VWAP/VPOC relationship determines the type of distribution (skewed/symmetric). Ignoring for the moment that as price moves around and volume trades that the VWAP and VPOC change and the distribution will probably change. Let's just say we were pretty sure that the type of distribution was not going to change for the next hour( Algorithmic Prediction). I think the distribution function itself tells you the trend bias and strength based on the strength of the skew, if Algorithmic Prediction is Up and the distribution had positive skew, you would go long every time the price action dropped below the VPOC and vice versa for negative skew. Similarly for no skew distribution, always trade toward the VWAP. This is the classical reversion to the mean theory.
 
Last edited by a moderator:

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

@ysanchezmd
After reading your bit, I really like the idea of determining probability at a given price by the volume at that price vs total volume... very nice idea!!!

So I've come up with this bit of code:
Code:
declare lower;

input length = 20;

def V = sum(VOLUME, length);
def VWAP = VWap();

def CM3 = fold i = 0 to length with s do s + ((getValue(VOLUME, i) / V) * Power((GetValue(CLOSE, i) - VWAP), 3));

def SD = StandardDeviation(length = length);
plot skew = - CM3 / Power(SD, 3);
plot zero = 0;

The only thing I'm not sure about is whether to subtract VWAPi or VWAP in the definition of CM3. I think the indicator looks more useful subtracting VWAP, but I think it's mathematically more correct to subtract VWAPi. If you want to see that in action, use this line instead:
Code:
def CM3 = fold i = 0 to length with s do s + ((getValue(VOLUME, i) / V) * Power((GetValue(CLOSE, i) - GetValue(VWAP, i)), 3));
But, as I said, I think the one in the first code is more useful looking.

NOTE: I inverted the skew plot as it makes more sense with a financial instrument.

Please do look over my implementation of the maths. I'm not really a statistician (more in the realm of physics) and so I defer to those who know better than I.

Thanks for the interesting idea,
mashume
 
Last edited by a moderator:
Hi mashume,

Thank you for your help, I had changed the code a little, if you can check and give me your opinion I will appreciate, I am not a coder neither a mathematician, just a physician trying to learn trading.

Have great day!

declare lower;

input length = 20;

input nFE = 8;#hint nFE: length for Fractal Energy calculation.
input AlertOn = no;
input Glength = 13;
input betaDev = 8;
input data = close;
def w = (2 * Double.Pi / Glength);
def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
def Go = Power(alpha, 4) * open +
4 * (1 – alpha) * Go[1] – 6 * Power( 1 - alpha, 2 ) * Go[2] +
4 * Power( 1 - alpha, 3 ) * Go[3] - Power( 1 - alpha, 4 ) * Go[4];
def Gh = Power(alpha, 4) * high +
4 * (1 – alpha) * Gh[1] – 6 * Power( 1 - alpha, 2 ) * Gh[2] +
4 * Power( 1 - alpha, 3 ) * Gh[3] - Power( 1 - alpha, 4 ) * Gh[4];
def Gl = Power(alpha, 4) * low +
4 * (1 – alpha) * Gl[1] – 6 * Power( 1 - alpha, 2 ) * Gl[2] +
4 * Power( 1 - alpha, 3 ) * Gl[3] - Power( 1 - alpha, 4 ) * Gl[4];
def Gc = Power(alpha, 4) * data +
4 * (1 – alpha) * Gc[1] – 6 * Power( 1 - alpha, 2 ) * Gc[2] +
4 * Power( 1 - alpha, 3 ) * Gc[3] - Power( 1 - alpha, 4 ) * Gc[4];
# Variables:
def o;
def h;
def l;
def c;


# Calculations
o = (Go + Gc[1]) / 2;
h = Max(Gh, Gc[1]);
l = Min(Gl, Gc[1]);
c = (o + h + l + Gc) / 4;


def V = sum(VOLUME, length);
def VWAP = VWap();

def CM3 = fold i = 0 to length with s do s + ((getValue(VOLUME, i) / V) * ((GetValue(C, i) - VWAP)/ 3));
#def CM3 = fold i = 0 to length with s do s + ((getValue(VOLUME, i) / V) * Power((GetValue(CLOSE, i) - GetValue(VWAP, i)), 3));

#def SD = StandardDeviation(length = length);
def sd = StDev(vwap, length);

plot skew = (- CM3 / (SD/ 3));
Skew.AssignValueColor(if skew > 0 then Color.CYAN else if skew < 0 then Color.MAGENTA else Color.YELLOW);

plot zero = 0;
 
This is a very interesting take on the VWAP.

I just went through all my personal trades for this year (winners and losers), and it seems this can help tightening up my entries and exit.

Quick question/ request: is it possible to add an arrow (up/down) whenever the line changes from one color to another (and vice versa). And also maybe a down whenever it crosses the 0 value.

Thanks in advance.

Additional indicator used in this image: MA Crosseover

Screen Shot 2023-12-19 at 8.54.48 AM.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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