OPEN-SOURCE SCRIPT

Machine Learning: VWAP [YinYangAlgorithms]

Updated
Machine Learning: VWAP aims to use Machine Learning to Identify the best location to Anchor the VWAP at. Rather than using a traditional fixed length or simply adjusting based on a Date / Time; by applying Machine Learning we may hope to identify crucial areas which make sense to reset the VWAP and start anew. VWAP’s may act similar to a Bollinger Band in the sense that they help to identify both Overbought and Oversold Price locations based on previous movements and help to identify how far the price may move within the current Trend. However, unlike Bollinger Bands, VWAPs have the ability to parabolically get quite spaced out and also reset. For this reason, the price may never actually go from the Lower to the Upper and vice versa (when very spaced out; when the Upper and Lower zones are narrow, it may bounce between the two). The reason for this is due to how the anchor location is calculated and in this specific Indicator, how it changes anchors based on price movement calculated within Machine Learning.

This Indicator changes the anchor if the Low < Lowest Low of a length of X and likewise if the High > Highest High of a length of X. This logic is applied within a Machine Learning standpoint that likewise amplifies this Lookback Length by adding a Machine Learning Length to it and increasing the lookback length even further.

Due to how the anchor for this VWAP changes, you may notice that the Basis Line (Orange) may act as a Trend Identifier. When the Price is above the basis line, it may represent a bullish trend; and likewise it may represent a bearish trend when below it. You may also notice what may happen is when the trend occurs, it may push all the way to the Upper or Lower levels of this VWAP. It may then proceed to move horizontally until the VWAP expands more and it may gain more movement; or it may correct back to the Basis Line. If it corrects back to the basis line, what may happen is it either uses the Basis Line as a Support and continues in its current direction, or it will change the VWAP anchor and start anew.

Tutorial:

snapshot

If we zoom in on the most recent VWAP we can see how it expands. Expansion may be caused by time but generally it may be caused by price movement and volume. Exponential Price movement causes the VWAP to expand, even if there are corrections to it. However, please note Volume adds a large weighted factor to the calculation; hence Volume Weighted Average Price (VWAP).

snapshot

If you refer to the white circle in the example above; you’ll be able to see that the VWAP expanded even while the price was correcting to the Basis line. This happens due to exponential movement which holds high volume. If you look at the volume below the white circle, you’ll notice it was very large; however even though there was exponential price movement after the white circle, since the volume was low, the VWAP didn’t expand much more than it already had.

snapshot

There may be times where both Volume and Price movement isn’t significant enough to cause much of an expansion. During this time it may be considered to be in a state of consolidation. While looking at this example, you may also notice the color switch from red to green to red. The color of the VWAP is related to the movement of the Basis line (Orange middle line). When the current basis is > the basis of the previous bar the color of the VWAP is green, and when the current basis is < the basis of the previous bar, the color of the VWAP is red. The color may help you gauge the current directional movement the price is facing within the VWAP.

snapshot

You may have noticed there are signals within this Indicator. These signals are composed of Green and Red Triangles which represent potential Bullish and Bearish momentum changes. The Momentum changes happen when the Signal Type:
  • The High/Low or Close (You pick in settings)

Crosses one of the locations within the VWAP.
Bullish Momentum change signals occur when :
  • Signal Type crosses OVER the Basis
  • Signal Type crosses OVER the lower level

Bearish Momentum change signals occur when:
  • Signal Type crosses UNDER the Basis
  • Signal Type Crosses UNDER the upper level


These signals may represent locations where momentum may occur in the direction of these signals. For these reasons there are also alerts available to be set up for them.

snapshot

If you refer to the two circles within the example above, you may see that when the close goes above the basis line, how it mat represents bullish momentum. Likewise if it corrects back to the basis and the basis acts as a support, it may continue its bullish momentum back to the upper levels again. However, if you refer to the red circle, you’ll see if the basis fails to act as a support, it may then start to correct all the way to the lower levels, or depending on how expanded the VWAP is, it may just reset its anchor due to such drastic movement.

snapshot

You also have the ability to disable Machine Learning by setting ‘Machine Learning Type’ to ‘None’. If this is done, it will go off whether you have it set to:
  • Bullish
  • Bearish
  • Neutral

For the type of VWAP you want to see. In this example above we have it set to ‘Bullish’. Non Machine Learning VWAP are still calculated using the same logic of if low < lowest low over length of X and if high > highest high over length of X.

Non Machine Learning VWAP’s change much quicker but may also allow the price to correct from one side to the other without changing VWAP Anchor. They may be useful for breaking up a trend into smaller pieces after momentum may have changed.

snapshot

Above is an example of how the Non Machine Learning VWAP looks like when in Bearish. As you can see based on if it is Bullish or Bearish is how it favors the trend to be and may likewise dictate when it changes the Anchor.

snapshot

When set to neutral however, the Anchor may change quite quickly. This results in a still useful VWAP to help dictate possible zones that the price may move within, but they’re also much tighter zones that may not expand the same way.

We will conclude this Tutorial here, hopefully this gives you some insight as to why and how Machine Learning VWAPs may be useful; as well as how to use them.

Settings:

VWAP:
  • VWAP Type: Type of VWAP. You can favor specific direction changes or let it be Neutral where there is even weight to both. Please note, these do not apply to the Machine Learning VWAP.
  • Source: VWAP Source. By default VWAP usually uses HLC3; however OHLC4 may help by providing more data.
  • Lookback Length: The Length of this VWAP when it comes to seeing if the current High > Highest of this length; or if the current Low is < Lowest of this length.
  • Standard VWAP Multiplier: This multiplier is applied only to the Standard VWMA. This is when 'Machine Learning Type' is set to 'None'.


Machine Learning:
  • Use Rational Quadratics: Rationalizing our source may be beneficial for usage within ML calculations.
  • Signal Type: Bullish and Bearish Signals are when the price crosses over/under the basis, as well as the Upper and Lower levels. These may act as indicators to where price movement may occur.
  • Machine Learning Type: Are we using a Simple ML Average, KNN Mean Average, KNN Exponential Average or None?
  • KNN Distance Type: We need to check if distance is within the KNN Min/Max distance, which distance checks are we using.
  • Machine Learning Length: How far back is our Machine Learning going to keep data for.
  • k-Nearest Neighbour (KNN) Length: How many k-Nearest Neighbours will we account for?
  • Fast ML Data Length: What is our Fast ML Length? This is used with our Slow Length to create our KNN Distance.
  • Slow ML Data Length: What is our Slow ML Length? This is used with our Fast Length to create our KNN Distance.


If you have any questions, comments, ideas or concerns please don't hesitate to contact us.

HAPPY TRADING!
Release Notes
- Added the ability to use an Optimal Length as a Source within the Settings instead of a Static Length. This may help the accuracy of the VWAP's expansion, as well as when it changes anchor.

- Added the ability to change the color of the VWAP:
  • Basis Line Color
  • Bullish Color
  • Bearish Color
Release Notes
- Fixed an issue with using Fast and Slow 'Machine Learning: Optimal Lengths'.

1.
snapshot
2.
snapshot

1. Is an example of how the default settings for Machine Learning: VWAP perform.

2. Is an example of how the Machine Learning: VWAP changes when the 'Machine Learning: Optimal Length - Neutral' is applied to it.
AIforecastingFractal Adaptive Moving Average (FRAMA)knnlorentzianclassificationmachine-learningmachine_learningmachinelearningmoving_averagetrendpatternvolumeweightedVolume Weighted Average Price (VWAP)

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Follow us for Free Indicators and Strategies released weekly!

Visit our website to purchase our Premium Indicators and Strategies. Try for 7 days risk free!
YinYangAlgorithms.com

Join our Discord Community: discord.gg/ccEHem37FB
Also on:

Disclaimer