[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Possible problem with the REF() function?



PureBytes Links

Trading Reference Links

Hi,

I am trying to calculate EMA that is initialised from the 1st value 
in an array instead of the simple MA used in the built-in EMA 
function from the Amibroker. I tried two ways, one using a custom 
function, EMA0(), and another via the built-in REF() function. The 
custom function works (see example below), but the REF() didn't. 
Because I see no reason(s) why the REF() could not be used to 
accomplish the same calculation, I was wondering if either I mis-
understood how the REF() function works, or is there a problem with 
the REF() function? Does anyone know what is going on? Thanks.

Here is the code:

	function EMA0(a, p){
		r[0] = a[0];
		for(i = 1; i < BarCount; i++){
			r[i] = r[i-1] + (a[i] - r[i-1])/p;
		}
		return r;
	}
	
	ref_ema[0]=C[0];	
	ref_ema=Ref(ref_ema,-1)+(C-Ref(ref_ema,-1))/15;
	ref_ema[0]=C[0];
	
	func_ema=EMA0(C,15);
	
	Filter =1;

	AddColumn (C,"close",1.3);
	AddColumn (ref_ema,"ref_ema",1.3);
	AddColumn (func_ema,"func_ema",1.3);
	AddColumn (BarIndex(),"i");	

And here are the resluts (you can see that the EMA0 function 
produced correct EMA values, but the REF() didn't (only the first 2 
array elements have the correct values):

Ticker	Date/Time	close	ref_ema	func_ema	i	
AA	5/29/2003	23.780	23.780	23.780	0.00	
AA	5/30/2003	24.360	23.819	23.819	1.00	
AA	6/2/2003	25.040	1.669	23.900	2.00	
AA	6/3/2003	24.810	1.654	23.961	3.00	
AA	6/4/2003	25.710	1.714	24.077	4.00	
AA	6/5/2003	25.580	1.705	24.178	5.00	
AA	6/6/2003	25.660	1.711	24.276	6.00	
AA	6/9/2003	25.240	1.683	24.341	7.00	
AA	6/10/2003	25.680	1.712	24.430	8.00	
AA	6/11/2003	25.810	1.721	24.522	9.00	
AA	6/12/2003	25.870	1.725	24.612	10.00	
AA	6/13/2003	25.320	1.688	24.659	11.00	
AA	6/16/2003	26.010	1.734	24.749	12.00	
AA	6/17/2003	26.330	1.755	24.854	13.00	
AA	6/18/2003	26.330	1.755	24.953	14.00	
AA	6/19/2003	26.080	1.739	25.028	15.00	
AA	6/20/2003	25.970	1.731	25.091	16.00	
AA	6/23/2003	24.810	1.654	25.072	17.00	
AA	6/24/2003	24.700	1.647	25.047	18.00	
AA	6/25/2003	24.260	1.617	24.995	19.00	
AA	6/26/2003	24.980	1.665	24.994	20.00	
AA	6/27/2003	24.830	1.655	24.983	21.00	
AA	6/30/2003	25.240	1.683	25.000	22.00	
AA	7/1/2003	25.240	1.683	25.016	23.00	
AA	7/2/2003	25.270	1.685	25.033	24.00	
AA	7/3/2003	25.040	1.669	25.033	25.00	
AA	7/7/2003	25.450	1.697	25.061	26.00	
AA	7/8/2003	25.550	1.703	25.094	27.00	
AA	7/9/2003	25.210	1.681	25.102	28.00	
AA	7/10/2003	24.690	1.646	25.074	29.00	
AA	7/11/2003	25.010	1.667	25.070	30.00	
AA	7/14/2003	24.850	1.657	25.055	31.00	
AA	7/15/2003	24.500	1.633	25.018	32.00	
AA	7/16/2003	24.350	1.623	24.974	33.00	
AA	7/17/2003	24.060	1.604	24.913	34.00	
AA	7/18/2003	24.450	1.630	24.882	35.00	
AA	7/21/2003	23.940	1.596	24.819	36.00	
AA	7/22/2003	24.620	1.641	24.806	37.00	
AA	7/23/2003	25.390	1.693	24.845	38.00	
AA	7/24/2003	25.580	1.705	24.894	39.00	
AA	7/25/2003	26.440	1.763	24.997	40.00	
AA	7/28/2003	26.650	1.777	25.107	41.00	
AA	7/29/2003	26.660	1.777	25.211	42.00	
AA	7/30/2003	26.670	1.778	25.308	43.00	








------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/