OPEN-SOURCE SCRIPT

업데이트됨

This here is my take on the popular VWAP indicator with several novel features including:

- Dual EMA smoothing.
- Arithmetic and Harmonic Mean plots.
- Custom Anchor feat. Intraday Session Sizes.
- 2 Pairs of Bands.
- Side Input for Connection to other Indicator.

This can be used 'out of the box' as a replacement VWAP, benefitting from smoother transitions and easy-to-use custom alerts.

By design however, this is intended to be a highly customisable alternative with many adjustable parameters and a pseudo-modular input system to connect with another indicator. Well suited for the tweakers around here and those who like to get a little more creative.

I made this primarily for crypto although it should work for other markets. Default settings are best suited to 15m timeframe - the anchor of 1 week is ideal for crypto which often follows a cyclical nature from Monday through Sunday. In 15m, the default ema length of 21 means that the wap comes to match a standard vwap towards the end of Monday. If using higher chart timeframes, i recommend decreasing the ema length to closely match this principle (suggested: for 1h chart, try length = 8; for 4h chart, length = 2 or 3 should suffice).

Note: the use of harmonic mean calculations will cause problems on any data source incorporating both positive and negative values, it may also return unusable results on extremely low-value charts (eg: low-sat coins in /btc pairs).

The development of this project was one driven more by experimentation than a specific end-goal, however i have tried to fine-tune everything into a coherent usable end-product. With that in mind then, this walkthrough will follow something of a development chronology as i dissect the various functions.

DUAL-EMA SMOOTHING

At its core this is based upon / adapted from the standard vwap indicator provided by TradingView although I have modified and changed most of it. The first mod is the dual ema smoothing. Rather than simply applying an ema to the output of the standard vwap function, instead i have incorporated the ema in a manner analogous to the way smas are used within a standard vwma. Sticking for now with the arithmetic mean, the basic vwap calculation is simply

The example below shows a standard vwap (1week anchor) in blue, a 21-ema applied to the vwap in purple and a dual-21-ema smoothed wap in gold. Notably both ema types come to effectively resemble the standard vwap after around 24 hours into the new anchor session but how they behave in the meantime is very different. The dual-ema transitions quite gradually while the post-vwap ema immediately sets about trying to catch up. Incidentally. a similar and slower variation of the dual-ema can be achieved with dual-rma although i have not included it in this indicator, attempted analogues using sma or wma were far less useful however.

tradingview.com/x/wbLpNl9q.png

STANDARD DEVIATION AND BANDS

With this updated calculation, a corresponding update to the standard deviation is also required. The vwap has its own anchored volume-weighted st.dev but this cannot be used in combination with the ema smoothing so instead it has been recalculated appropriately. There are two pairs of bands with separate multipliers (stepped to 0.1x) and in both cases high and low bands can be activated or deactivated individually. An example usage for this would be to create different upper and lower bands for profit and stoploss targets. Alerts can be set easily for different crossing conditions, more on this later.

Alongside the bands, i have also added the option to shift ('Deviate') the entire indicator up or down according to a multiple of the corrected st.dev value. This has many potential uses, for example if we want to bias our analysis in one direction it may be useful to move the wap in the opposite. Or if the asset is trading within a narrow range and we are waiting on a breakout, we could shift to the desired level and set alerts accordingly. The 'Deviate' parameter applies to the entire indicator including the bands which will remain centred on the main WAP.

CUSTOM (W)ANCHOR

Ever thought about using a vwap with anchor periods smaller than a day? Here you can do just that. I've removed the Earnings/Dividends/Splits options from the basic vwap and added an 'Intraday' option instead. When selected, a custom anchor length can be created as a multiple of minutes (default steps of 60 mins but can input any value from 0 - 1440). While this may not seem at first like a useful feature for anyone except hi-speed scalpers, this actually offers more interesting potential than it appears.

When set to 0 minutes the current timeframe is always used, turning this into the basic volume-weighted ema mentioned earlier. When using other low time frames the anchor can act as a pre-ema filter creating a stepped effect akin to an adaptive MA. Used in combination with the bands, the result is a kind of volume-weighted adaptive exponential bollinger band; if such a thing does not already exist then this is where you create it. Alternatively, by combining two instances you may find potential interesting crosses between an intraday wap and a standard timeframe wap. Below is an example set to intraday with 480 mins, 2x st.dev bands and ema length 21. Included for comparison in purple is a standard 21 ema.

I'm sure there are many potential uses to be found here, so be creative and please share anything you come up with in the comments.

ARITHMETIC AND HARMONIC MEAN CALCULATIONS

The standard vwap uses the arithmetic mean in its calculation. Indeed, most mean calculations tend to be arithmetic: sma being the most widely used example. When volume weighting is involved though this can lead to a slight bias in favour of upward moves over downward. While the effect of this is minor, over longer anchor periods it can become increasingly significant. The harmonic mean, on the other hand, has the opposite effect which results in a value that is always lower than the arithmetic mean. By viewing both arithmetic and harmonic waps together, the extent to which they diverge from each other can be used as a visual reference of how much price has changed during the anchored period.

Furthermore, the harmonic mean may actually be the more appropriate one to use during downtrends or bearish periods, in principle at least. Consider that a short trade is functionally the same as a long trade on the inverse of the pair (eg: selling BTC/USD is the same as buying USD/BTC). With the harmonic mean being an inverse of the arithmetic then, it makes sense to use it instead. To illustrate this below is a snapshot of LUNA/USDT on the left with its inverse 1/(LUNA/USDT) = USDT/LUNA on the right. On both charts is a wap with identical settings, note the resistance on the left and its corresponding support on the right. It should be easy from this to see that the lower harmonic wap on the left corresponds to the upper arithmetic wap on the right. Thus, it would appear that the harmonic mean should be used in a downtrend. In principle, at least...

In reality though, it is not quite so black and white. Rarely are these values exact in their predictions and the sort of range one should allow for inaccuracies will likely be greater than the difference between these two means. Furthermore, the ema smoothing has already introduced some lag and thus additional inaccuracies. Nevertheless, the symmetry warrants its inclusion.

tradingview.com/x/0pdGfIT0.png

SIDE INPUT & ALERTS

Finally we move on to the pseudo-modular component here. While TradingView allows some interoperability between indicators, it is limited to just one connection. Any attempt to use multiple source inputs will remove this functionality completely. The workaround here is to instead use custom 'string' input menus for additional sources, preserving this function in the sole 'source' input. In this case, since the wap itself is dependant only price and volume, i have repurposed the full 'source' into the second 'side' input. This allows for a separate indicator to interact with this one that can be used for triggering alerts. You could even use another instance of this one (there is a hidden wap:mid plot intended for this use which is the midpoint between both means). Note that deleting a connected indicator may result in the deletion of those connected to it.

Preset alertconditions are available for crossings of the side input above and below the main wap, alongside several customisable alerts with corresponding visual markers based upon selectable conditions. Alerts for band crossings apply only to those that are active and only crossings of the type specified within the 'crosses' subsection of the indicator settings. The included options make it easy to create buy alerts specific to certain bands with sell alerts specific to other bands. The chart below shows two instances with differing anchor periods, both are connected with buy and sell alerts enabled for visible bands.

Okay... So that just about covers it here, i think. As mentioned earlier this is the product of various experiments while i have been learning my way around PineScript. Some of those experiments have been branched off from this in order to not over-clutter it with functions. The pseudo-modular design and the 'side' input are the result of an attempt to create a connective framework across various projects. Even on its own though, this should offer plenty of tweaking potential for anyone who likes to venture away from the usual standards, all the while still retaining its core purpose as a traders tool.

Thanks for checking this out. I look forward to any feedback below.

릴리즈 노트

When I first published this I was not aware that the 'indicator on indicator' function required to fully utilise the side input was restricted by Tradingview to Premium and Pro+ accounts only, meaning that many of you have been unable to use this feature as intended. I have noted this limitation in the tooltips and consequently added a bunch of standard MAs to the 'Side' section so now everyone can at least make use of the crossings and alerts.

릴리즈 노트

Multiple improvements have been made:

Now works on charts without volume data. Added a condition which will use a constant value of 1 when volume data is unavailable, resulting in an unweighted 'AP'.

Included additional 'weighted inputs'. These are taken from Weight Gain 4000, for more details refer to that listing. These are best considered experimental. Due to the method of calculation they are probably not well suited to the actual WAP itself, however they may be more useful when used on the updated Side tracker.

The Side tracker functionality has been given a significant overhaul. We now have a global 'Aux' input which can be used to select another indicator when available, this can then be assigned to either the main WAP or the Side from the respective source inputs. Side now has its own custom source menu featuring the weighted inputs. A selection of Pine's onboard filters are available here applied to whichever source is selected (note the VWEMA here is a simple version analogous to a standard VWMA and not the elastic version). The default state is 'close' with no filter making this function as a standard price tracker.

Cosmetic improvements. The colour change conditions for the main WAP are now determined solely by the relative position of the side (for simplicity more than anything). The arithmetic and harmonic WAP lines are now coloured independently, something which will be more noticeable on charts with significant divergence. The fill here is now gradient based becoming more opaque as the price deviates further away and more transparent when price is closest, again this is something which will be more noticeable on volatile charts or those with greater divergence.

Added a third pair of bands.

Updated alerts. These are now solely determined by the side (post-filter if active). The previous buy/sell labels have been replaced with up/down triangles, allowing you to decide for yourself whether these should be regarded as buys or sells. The 'invert condition' function is thus no longer relevant and has been removed. Alert messages have been changed to reflect this ambiguity.

Aside from these, a few changes to the code have been made, mostly renaming and tidying. Overall, the core functionality and design principle remains as before.

Chart demonstration has been updated to better reflect the improvements.

릴리즈 노트

Mostly just minor back-end tweaks:Code is now more consistent with PineScript standards: more camelCase, less snake_case

Data Window has been tidied to show only useful information

Improved logic for fix when volume data in unavailable

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.