allanster

VAMA Volume Adjusted Moving Average

Richard Arms' Volume Adjusted Moving Average

Settings:

Inp Avg Vol: Input - Purist method but not intended for live analysis, to retroactively alter MA curve enter Avg Vol from value shown on label into Use Avg Vol field.

Inp Avg Vol: Current - Live method using current volume , to retroactively alter past MA curve toggle any setting back and forth to force recalculation.

Inp Avg Vol: Subset - Similar to Current, but uses a subset rather than all bars for avg vol.

Use Avg Vol - Used for Inp Avg Vol: Input mode. Enter volume from Avg Vol label here after each new bar closes, label will turn green, else red.

Subset Data - Lookback length used for Inp Avg Vol: Subset mode.

VAMA Length - Specified number of volume ratio buckets to be reached.

Volume Incr - Size of volume ratio buckets.

VAMA Source - Price used for volume weighted calculations.

VAMA Strict - Must meet desired volume requirements, even if N bars has to exceed VAMA Length to do it.

Show Avg Vol Label - Displays label on chart of total chart volume .

Notes: VAMA was created by Richard Arms. It utilizes a period length that is based on volume increments rather than time. It is an unusual indicator in that it cannot be used in some platforms in realtime mode as Arms had originally intended. VAMA requires that the average volume first be calculated for the entire chart duration, then that average volume is used to derive the variable adaptive length of the moving average. The consequence of this is that with each new bar, the new average volume alters the moving average period for the entire history. Since Pine scripts evaluate all historical bars only once upon initial script execution, there is no way to automatically shift the previous moving average values retroactively once a new bar has formed. Thus the historical plot of the moving average cannot be updated in realtime, but instead can only plot through previous bar that existed upon load or reinitialization through changing some setting.

Setting Use Avg Vol to Input mode the average volume through previous bar shown in label can be entered (input) into the Inp Avg Vol setting after each new bar closes. Entering this total chart volume forces the script to reevaluate historical bars which in turn allows the historical moving average to update the plot. When using Input mode the color of the label is green when Inp Avg Vol value matches current label value, the label color red signifies Inp Avg Vol value has not been entered or is stale.

Setting Use Avg Vol to Current mode allows the script to correctly calculate and plot the correct moving average upon initial load and the realtime moving average moving forward, but can not retroactively alter the plot of the past moving average unless some change is made in the script settings, such as toggling the Use Avg Vol from Current to some other choice and then back to Current.

Setting Use Avg Vol to Subset mode uses a rolling window of volume data to calculate the average volume and can be used in realtime, but should be noted it is a deviation from Richard Arms' original specification.

VAMA info: "Trading Without Fear" by Richard W Arms, Jr, https://www.fidelity.com/learning-center...


NOTICE: This is an example script and not meant to be used as an actual strategy. By using this script or any portion thereof, you acknowledge that you have read and understood that this is for research purposes only and I am not responsible for any financial losses you may incur by using this script!
Release Notes: Revision 1

Changed Subset mode's Average Volume calculation from using native
sum()
function to custom
sumFrom()
function.

Renamed some variables to better describe their roles. Edited some comments to better describe logic behavior. Colorized troubleshooting values for Data Window.
Release Notes: Revision 2

Added basic error protection, but some instruments and/or combinations of settings may still error due to the computational expense of using multiple for loops. Changed limit for maximum loops to VAMA Length * 5. Situations where a large number of bars is required to meet volume requirements can result in calculations exceeding 20000ms. These situations may arise when VAMA Length and/or Volume Incr settings are too high, and/or the instrument's liquidity is too low. The typical use range of settings has been tested successfully without error against AAPL, BTCUSD, DOGEUSDT, and EURUSD. These were chosen to cover wide range of price and volume possibilities.
Release Notes: Revision 3

Added tool tip for label. Disabled all Troubleshooting plots except for ‎VAMA Length and number of ‎volume bars used to satisfy chosen method.

There is a newer and much more efficient version of this indicator for live analysis utilizing a single function with a single for loop here:

Remove from Favorite Scripts Add to Favorite Scripts
Telegram: https://t.me/allanster • Gunbot Tuners: http://www.allanster.com

If you would like to buy me a refreshing beverage :)...

LTC (preferred): LTDaAe7nPzbpBhZVT9o5f9f8M3aZSPa46Y

BTC: 13LhkeXBYrRomVAqbXcoLXHuqMk6Mf7G6N

Comments

Am I understanding it correctly that according to the original idea the indicator should repaint but this version does not repaint on tradingview because of restrictions by TV?
+1 Reply
allanster Canundo
@Canundo, yes, with a normal time based moving average once a satisfactory length has been set that length is expected to remain static. Since that period length is static there is never a need to historically redraw the time based moving average plot with the formation of each new bar. But this moving average utilizes an adaptive length based off of total chart volume. With each new bar that has formed, the total chart volume changes, which in turn changes the period length of the moving average.

When a SMA period is changed from 50 to 200 this forces a Pine script indicator to reinitialize and evaluate each historical bar same as if the script had just been loaded onto the chart. No issue arises when changing time based indicators, each time their settings are changed the historical plot(s) are redrawn. This same concept is being utilized here when using Input mode. Each time a new bar has formed and total chart volume has changed, the new total average volume is calculated and updated in the label and that value is then manually entered into the indicator''s settings, forcing the reinitialization and redrawing of the plot.

Setting the mode to Current or Subset calculates initial plot correctly for those modes, and each new subsequent bar thereafter, without the need to manually enter the total chart volume average, but those modes also do not redraw the historical plot as each new bar has formed unless some setting is changed briefly in the script and then changed back. Then the historical plot would recalculate and redraw same as it would do when using Input mode and a new value has been entered into settings. When using Input mode if a user does not update the indicator's setting for total chart average volume, the label turns red but the behavior will be similar to Current mode with the distinction that Input mode calculates total chart volume average up through previous bar, whereas Current and Subset modes calculate total chart volume average up through current bar.

Some 3rd parties describe use cases for Input mode as being post analysis, and Current or Subset mode as being live analysis. But by loading the indicator twice, setting one to Input mode and the other to Current mode, the two modes can be compared and the delta is small between the two. Regarding the platform limitation it is not unique to TradingView, there are other modern platforms that behave similar. It only becomes apparent when not utilizing time based indicators and needing to do post analysis of historical values, regardless of this limitation the current values calculate and plot correctly without intervention.

Hopefully this script will serve multiple purposes in that it will provide members of the community with the ability to use VAMA, while also helping users understand that when utilizing Pine script indicators all historical bars are evaluated only once upon initial loading of the script OR when a setting in the script has been changed.
Reply
Canundo allanster
@allanster, Thanks a lot for your answer and your good work. :thumbsup:
+1 Reply
Nice idea
+1 Reply
allanster MinaCordier
@MinaCordier, thanks for taking the time to comment!
Reply
Very good
+1 Reply
allanster DawnButlers
@DawnButlers, thanks for your comment!
Reply
very nice work
+1 Reply
allanster SteveBryantp
@SteveBryantp, much appreciated!
Reply
Great work
+1 Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out