Australian (ASX) Stock Market Forum

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

Joined
10 February 2015
Posts
5
Reactions
0
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);
 
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 ) );
}
 
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?












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

Code:
// variable period EMA
function cEMA2( 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 ) );
}
 
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).
 
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!



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 ) );
}
 
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).

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.

8ICTGVe.png
 

Attachments

  • 8ICTGVe.png
    8ICTGVe.png
    29.6 KB · Views: 0
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!

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!

So there you would read about things like quickafl, setbarsrequired etc.

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.
 
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.

bOP50fm.png

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.
 

Attachments

  • cs-movavg.xls
    28.5 KB · Views: 15
  • bOP50fm.png
    bOP50fm.png
    13.3 KB · Views: 0
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.


 
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.
 
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.

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?
 
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.

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

Downloading ASX Stock Quotes from Yahoo Finance and Charting them in MT4 using Perl
https://www.aussiestockforums.com/forums/showthread.php?t=28615

Converting Metastock EOD data to MT4 history files for MT4 charting
https://www.aussiestockforums.com/forums/showthread.php?t=28692

and

World's First Metatrader 4 ASX EOD Stock Market Scanner/Screener/Filter
https://www.aussiestockforums.com/forums/showthread.php?t=28721

Cheers,

Andrew.
 
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:

Downloading ASX Stock Quotes from Yahoo Finance and Charting them in MT4 using Perl
https://www.aussiestockforums.com/forums/showthread.php?t=28615

Converting Metastock EOD data to MT4 history files for MT4 charting
https://www.aussiestockforums.com/forums/showthread.php?t=28692

and

World's First Metatrader 4 ASX EOD Stock Market Scanner/Screener/Filter
https://www.aussiestockforums.com/forums/showthread.php?t=28721

Cheers,

Andrew.

What's that gotta do with EMA topic?

And what's that gotta do with "not too complicated"?
Those threads are the opposite of "not too complicated".
 
Top