How can I calculate the VWAP of the last bar?

Forums ProRealTime English forum ProScreener support How can I calculate the VWAP of the last bar?

Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • #81916

    Hello forum,

    I want to code a very simple screener but obviously it’s not so easy as I thought. I want to screen for stocks where the last two bars where above their VWAP.

    I tried it this way but it doesn’t work:

    I am sure that VWAP[1] is not the correct way to get the VWAP of the last bar but I don’t know how to get this value.

    Thank you for any help!

    #81935

    VWAP[1] is actually the correct way to get the previous bar VWAP value. But, are you looking for an intraday VWAP? On what timeframe do you launch this screener? (the “default” one).

    #81940

    Yes, I am working with 15 minutes intraday charts.

    #81955

    By the way, is it possible to check all bars/VWAP-values of the day within a loop in the screener? For example I want to find all stocks at 19:00 where all 15 minutes bars were below their VWAP.

    Good example today was GOOGL.

     

    #81974

    The below screener will return all shares that has met this condition:

    _ last 19:00 bar Close was below the VWAP

     

    1 user thanked author for this post.
    #81982

    I am not sure if you can really use SUMMATION in this case. In the programming manual I read that SUMMATION calculates from the right to the left but to calculate the intraday VWAP I must start at the first bar of the day. So I made this version and it seems to work pretty fine. But I will test it today when the US markets open.

    What do you think?

    #81996

    You can use SUMMATION, but it needs a period of at least 1, or it fails to make the calculation, and that’s what happened in your first version. Look at how I calculate period at first line of my code, it prevents the period to be less than 1. SUMMATION is also less intensive for the platform engine than FOR/NEXT loop.

    #82041

    I don’t want to disagree but SUMMATION doesn’t seem to work correctly in this case. It is necessary that the calculation of the VWAP is made from the left to the right and SUMMATION doesn’t work this way. This small example shows that the calculation begins at the very current bar:

    The result is the cumulative volume of the last three bars. That means the VWAP calculation with SUMMATION would be started at the very last bar and end with the first bar of the day.

     

     

    #82045

    Sorry if I don’t understand clearly what you mean but, making addition of values starting from the first one or by the last one should give the same result?

    (copy/paste from other web sources):

    There are five steps in calculating VWAP:

    1. Calculate the Typical Price for the period. [(High + Low + Close)/3)]
    2. Multiply the Typical Price by the period Volume (Typical Price x Volume)
    3. Create a Cumulative Total of Typical Price. Cumulative(Typical Price x Volume)
    4. Create a Cumulative Total of Volume. Cumulative(Volume)
    5. Divide the Cumulative Totals.

    VWAP = Cumulative(Typical Price x Volume) / Cumulative(Volume)

    vwap

    #82055

    We can take IBM as an example. The indicator shows a VWAP for the very last 15-minute-bar of  151.40545.

    If you start the calculation from the right side it’s the typical price (151.26666) muliplied with the period’s volume divided with the total traded shares. So the calculation would be:

    (151.26666*613719)/613719 = 151.26666

    You see that the result is different from the correct VWAP of 151.40545. Therefore it’s necessary to start the calculation with the very first bar of the day.

    Would you agree?

    #82056

    I just noticed where the logic problem is with SUMMATION is!

    You divide by the total volume BUT of course only by the total volume at that time. Only the very last period is divided by the total volume of that day. Therefore it is so important to start with the very first bar of the day. The cumulative volume becomes larger and this is the reason why the VWAP is more sensitive at the beginning and flattens out at the end of the day.

     

    #82063

    Only the very last period is divided by the total volume of that day.

    Nope. All periods are divided by the total volume of the day at their points. The summation periods is automatically increased with the “intradaybarindex”, so each bar make the same calculation but with a different period.

    The reason why the VWAP is more and more flattened is because the calculation period is increasing along the day, so the price is more and more weighted by the exchanged Volumes and therefore the real market mean is formed.

    Look at the attached picture, the embedded platform VWAP (black line) is the same as the one I gave the formula above (orange/blue color depending of its slope).

    #82072

    I am sure that you are way better than me in programming but I still don’t get this in my mind… 🙂

    Just made some test-screening and most of the results are wrong. I don’t know if it’s the formula or if it’s a syntax problem.

    Could you please have a last look at this code? I promise not to bother you with that topic anymore… 🙂

    A lot of these results do not fit to the chart I see. Please have a look yourself. Thanks!!

     

    PS. This code works perfect:

     

Viewing 13 posts - 1 through 13 (of 13 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login