• Australian (ASX) Stock Market Forum

# Amibroker code for EMA? (or convert formula from Metastock to Amibroker?)

Discussion in 'Software and Data' started by richardwilson, Feb 10, 2015.

1. ### richardwilson

Posts:
5
0
Joined:
Feb 10, 2015
Does anyone know the full AFL code to create a custom EMA?

Alternatively, if somone could help me convert the following Metastock formula, it would be most appreciated!

Pds:= 200;

Rate:=2 / (Pds+1);

M:=If(Cum(1)=1, C, PREV*(1-Rate) + C*Rate );

ValueWhen(1,Cum(1)>=Pds,M);

2. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

What's wrong with the built-in EMA function?

Code:
```// variable period EMA
function cEMA( array, period )
{ // by T.Janeczko, http://www.amibroker.com/guide/h_understandafl.html
// initialize first value
vaexp[ 0 ] = array[ 0 ];
for( i = 1; i < BarCount; i++ ) {
// calculate the value of smoothing factor
factor = 2/(period[ i ] + 1 );
// calculate the value of i-th element of array
// using this bar close ( close[ i ] ) and previous average value ( vaexp[ i - 1 ] )
vaexp[ i ] = factor * array[ i ] + ( 1 - factor ) * vaexp[ i - 1 ];
}
return vaexp;
}```

Code:
```// variable period EMA
function varperEMA( array, period )
{// by T.Janeczko
return AMA( array, 2 / ( period + 1 ) );
}```

3. ### richardwilson

Posts:
5
0
Joined:
Feb 10, 2015
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

I'm experiencing the same problem as is mentioned here: http://forum.metastock.com/Discussi...ge--EMA--9-periods---Initial-Value#post150586

When I calculate EMA using Amibroker's default EMA, it gives me a different value to what is calculated in both Excel and Metastock (which match each other) and the difference is VERY wide. I'm trying to figure out why this might be... and from what I can figure out so far, I suspect it might something to do with the initial EMA value. I'm not even entirely sure which is correct... Metastock/Excel OR Amibroker...

Many thanks for the code.. I'm not familar with functions in AB though... how do I get it to plot?

4. ### richardwilson

Posts:
5
0
Joined:
Feb 10, 2015
I've worked out how to plot it, so please disregard my last question - thanks.

The resulting plot from the code you gave is now only a little bit different from the Excel/Metastock values (but is still very different from the default Amibroker EMA).

5. ### richardwilson

Posts:
5
0
Joined:
Feb 10, 2015
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

Also, I note that the EMA using that code changes completely as I zoom in and out of the chart... very strange!

6. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
I'm sorry to say but you do not have much of a clue whatsoever. The built-in function outputs the same result as other ones and same one as Excel calculation. It just starts period later. That's why at start only it differs a bit.

File size:
29.6 KB
Views:
0
7. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

There is nothing strange.
Once again you just prove one thing that is having no clue of the software you are using. How can you gain more knowledge resulting in having more clue? Reading the documentation!

Anyway in case you have a short attention span the posts of this thread may help a little bit already https://groups.yahoo.com/neo/groups/amibroker/conversations/topics/177938
But to be honest I doubt it since ignorance is the king of Internet.

8. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
Here is another proof that the calculation is in-line with Excel for example using same start method contrary to your claims it wouldn't be the case.

attached is the Excel file from Stockcharts.com. Import the close prices into AB and apply built-in EMA 10 as of the Excel file. Results will be in-line.

File size:
28.5 KB
Views:
15
File size:
13.3 KB
Views:
0
9. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

read "Important notes" section here http://www.amibroker.com/kb/2008/07/03/quickafl/

10. ### richardwilson

Posts:
5
0
Joined:
Feb 10, 2015
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

You are right.. I dont have a clue whatsoever.. have never used Amibroker before until today... so if this is the general attitude towards helping community members.. then I think I will give this software a miss. Thanks for replying anyway.

11. ### trash

Posts:
412
17
Joined:
Mar 31, 2012
And I find it rather rude annoying other people with implications like "this is wrong and that is strange" instead of first reading documentation of a software if someone has no clue at all.

You being a helping community member? Have I missed something?
What have you helped so far? That's quite funny. AFAICS I'm the only one who has helped you so far. I am the one who has provided the input to you but not you to yourself. You have just gotten your lazy butt creamed with free info that you could have easily found out yourself.

BTW, I don't care if you use this or that software as I'm not the developer of any commercial software. I really couldn't care less.
And as I see it, you will remember my "rant" much better instead of some butt licking posts and I'm sure you will rather avoid further redundant posts but instead you got encouraged to better study reasons before implying something and making a fool out of yourself. So actually everything has a good side not just a bad one.

12. ### colion

Posts:
116
0
Joined:
Aug 6, 2010
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

Richard don't be turned off. All boards have people who "live" on them (or even more than one under different names) and feel compelled to respond to all questions. If annoyed just ignore and somebody else will answer your questions.

Have you actually switched to AB or are you searching for the right software (or combination of software) that fits your needs?

13. ### ajcode

Posts:
137
19
Joined:
Feb 12, 2014
Re: Amibroker code for Exp. Mov. Avge? (or convert formula from Metastock to Amibroke

Hi Richard, if you're not looking for too complicated stuff, you might want to check out my threads:

Converting Metastock EOD data to MT4 history files for MT4 charting

and

World's First Metatrader 4 ASX EOD Stock Market Scanner/Screener/Filter

Cheers,

Andrew.

Posts:
412