• 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 , 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 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 ratio buckets to be reached.
• Volume Incr - Size of ratio buckets.
• VAMA Source - Price used for weighted calculations.
• VAMA Strict - Must meet desired requirements, even if N bars has to exceed VAMA Length to do it.
• Show Avg Vol Label - Displays label on chart of total chart .
Notes: VAMA was created by Richard Arms. It utilizes a period length that is based on 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 first be calculated for the entire chart duration, then that average 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 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 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 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 data to calculate the average 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!
Changed Subset mode's Average Volume calculation from using native
Renamed some variables to better describe their roles. Edited some comments to better describe logic behavior. Colorized troubleshooting values for Data Window.
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.
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:
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.