Click here to Login

                                                   Volume Adjusted Moving Average


Joshua Laferriere
2019-09-03 08:40:33

I want to write my first formula

How do I access the previous trading day's value?

VAMA is (En1 price x volume) / En1 volume

En1 is the sum of (E) of the past n days including today

So... I would use close, but I'd like a moving average of the past 3 closes and past 3 volumes.

Yes I've been looking in the docs

The problem I have is I don't know what built in accessor functions or variables I have access to.

A wiki with them documented would be nice vs having to jump through these half documented how-to's.

I'm new to this editor. I've only written one function. I like the layout of your site. Please bear with me as I'm getting used to it. I work better with top level wiki's and hyperlinks.

A glossary of all available built in variables and functions would be nice

2019-09-03 14:21:04



The previous bar value can be accessed using the "ref" function or using []
a = ref(close, 1);
a = close[1];

To get the moving average of the volume for the past 3 bars:
a = sma(volume, 3);

The link on how to create a custom trading indicator shows instructions on how to create custom function in c# (not in QS language). This is in case the formula is too complex to be implemented in QS language.

Please also check this QS language introduction:

Joshua Laferriere
2019-09-06 22:35:53


thank you for all that. I've saved them in a reference file I use now for tutorials

So I've created a 3 period volume adjusted moving average

indicator = ((close * volume)+(ref(close, 1)* ref(volume, 1))+(ref(close, 2)* ref(volume, 2)))/(volume+ref(volume, 1)+ref(volume, 2));

edit: for some reason this isn't including volume. It is only a 3 day moving average of price as when mapped against the candlsticks, it's spot on.

I think I have this correct from the formula here:

and saved it as vama.azf and added to indicators and it plotted

yay! I'm making progress. I suppose you don't know how I could turn this into a function that would accept any value of n? I suppose I could answer that question myself. I'd like to recursively iterate through each close/volume up to n so I can call vama like vama(3) and have it do 3 periods vs a static 3 each time. I might even modify it to be exponential.

The reason I'm relying on this so heavily is because machine learning likes equally sampled data points (i.e. at specific tradeable units, which time is not). Such as trades by dollar or volume and vama is a great candidate.


No more messages


No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"


Trading Items
Elastic Volume Weighted Moving Average - eVWMA
Multiple Time Frames Trading System - Price / Moving Average Cros...
Mahesh Moving Average
Moving Average Ratio
Cross Above 200 SMA on Average Volume Strategy

How-to Lessons
How to create a moving average of an indicator
How to change volume bar colors when the price closes down
How to create a volatility-based Stop - Dynamic stop based on the...
How to create volume bar charts
How to calculate the average of a time series using the money man...

Related Forum Threads
Average Volume
delay in moving average
Rising moving average
Displaced moving average
coding a moving average

Blog Posts
Trading System: Moving average crossover and few others buy and s...
Custom Indicator: Moving average spread
Different Types of Trading Indicators: Trend, Momentum, Volatilit...
Using Average True Range to Measure Intraday Volatility
Trend Following and Moving Averages

Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2021
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Follow us on Google+
RSS Trading Items

Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.