Variable Moving Average Calculation  [SOLVED]

Questions about MultiCharts and user contributed studies.
earmarques
Posts: 13
Joined: 07 Dec 2013
Has thanked: 1 time
Been thanked: 1 time

Variable Moving Average Calculation

Postby earmarques » 23 Feb 2014

Hi, I've tried to create a indicator for the VMA but without success, using the below formula:

Code: Select all

VMA = (0.78*(volatility index) * close) + (1-0.078 * volatility index)*yesterday’s VMA
For the volatility index I've choosed the CMO of length 9, function below:

Code: Select all

Input: LENGTH(Numeric);

CMO =100*((C-C[LENGTH])/ (SUMMATION(ABSVALUE((C-C[1])),LENGTH)));
Then the complete formula for my VMA is:

Code: Select all

VMA = (0.78*CMO(9) * close) + (1-0.078 * CMO(9))*VMA[1]
This looks wrong? I put this formula and Multicharts64 return big numbers, far from a moving average. I put this formula in excel with the values of CMO(9) and don't return big numbers. Can anyone help me please?

And sorry by the bad english!

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Variable Moving Average Calculation

Postby TJ » 23 Feb 2014

::
And sorry by the bad english!
No apology needed for bad english; we are from all over the world.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Variable Moving Average Calculation

Postby TJ » 23 Feb 2014

you can debug by breaking down all the variables and
printing out each value:

eg.

VMA1 = (0.78*(volatility index) * close)
VMA2 = (1-0.078 * volatility index)*yesterday’s VMA

plot CMO
plot VMA1
plot VMA2

plot VMA1+VMA2

earmarques
Posts: 13
Joined: 07 Dec 2013
Has thanked: 1 time
Been thanked: 1 time

Re: Variable Moving Average Calculation

Postby earmarques » 23 Feb 2014

Yes, but the problem arrives when I reference the VMA[1]. When I change this to Close the number isn't so bigger. And I can't do this test without sum the two formulas:

Code: Select all

VMA1 = (0.78*(volatility index) * close)
VMA2 = (1-0.078 * volatility index)*VMA[1]<-------this part must be calculated

plot CMO
plot VMA1
plot VMA2

plot VMA1+VMA2
This is why this debug is so dificult. When I replace VMA[1] by Close is ok, but this variable must be calculated.

earmarques
Posts: 13
Joined: 07 Dec 2013
Has thanked: 1 time
Been thanked: 1 time

Re: Variable Moving Average Calculation  [SOLVED]

Postby earmarques » 23 Feb 2014

T, thanks for the help. I made a search for this indy and found this:

Code: Select all

Inputs: Price(c), Period(9), CMOPeriod(9);
Variables: VI(0), factor(0), VMA(0);
factor = 2/(Period+1);
VI = AbsValue(CMO(Price, CMOPeriod)/100);
if CurrentBar <= 1 then
begin
VMA = Price;
end
else
begin
VMA = (factor*VI*Price) + ((1-factor*VI)*VMA[1]);
end;

plot1(vma);
It's perfect!
Thanks.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Variable Moving Average Calculation

Postby TJ » 23 Feb 2014

Good. Thanks for letting us know.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Variable Moving Average Calculation

Postby TJ » 23 Feb 2014

An easier way would be to initialize the VMA to Close.

VMA will start with the value of "Close",
after the first bar, VMA will be determined by your code.
This method works if you are only referencing one bar back;

Code: Select all

Inputs: Price(c), Period(9), CMOPeriod(9);
Variables: VI(0), factor(0), VMA( CLOSE );

factor = 2/(Period+1);
VI = AbsValue(CMO(Price, CMOPeriod)/100);

VMA = (factor*VI*Price) + ((1-factor*VI)*VMA[1]);

plot1(vma);

filippo.milano
Posts: 44
Joined: 02 Jan 2015
Has thanked: 1 time

Re: Variable Moving Average Calculation

Postby filippo.milano » 07 Nov 2018

Sorry, but it's not working tis code...
Could you please post the correct code for VMA and also for CMO function code?

Many thanks in advance

Filippo


Return to “MultiCharts”