PureBytes Links
Trading Reference Links
|
If I do this manually using REF(), then it works. Like this:
ref_ema[0]=C[0]; ref_ema[1]=ref_ema[0]+(C[1]-ref_ema[0])/15; ref_ema[2]=ref_ema[1]+(C[2]-ref_ema[1])/15;
ref_ema[3]=ref_ema[2]+(C[3]-ref_ema[2])/15;
etc, etc....
The EMA can be built this way and the values will be correct. So it seems that using the formula:
ref_ema=Ref(ref_ema,-1)+(C-Ref(ref_ema,-1))/15;
then one should be able to calculate the EMA also. But that's not the case. Why? What's also strange is that the formula calculated ref_ema[1] correctly, but get it wrong from there. Pretty strange don't you think?
On 2/12/06, Graham <kavemanperth@xxxxxxxxx> wrote:
AB goes through the AFL oneline at a time calculating every array value for each line EMA relies on the previous bar value for its current value and as such
normal line AFL cannot be used. The array of values is calculated within that array and so the value is not available within itself as it must have been calculated in a previous line. Unfortunately even the previous calculation line requires a previous value, so this
becomes a dog chasing its tail, you never get a starting value as it always requires an earleir value to calculate it. This is the reason loops are used for functions like EMA
In your example of using ref
ref_ema[0]=C[0]; ref_ema=Ref(ref_ema,-1)+(C-Ref(ref_ema,-1))/15; ref_ema[0]=C[0]; you are only determining the first value of an array (barindex()==0 is [0]) The other problem is that because the first array value is being
calculated you cannot use ref( , -1) because there simply is no earlier value to reference. [0] is the first array value, there is no [-1] position so you started saying the first value of ref_ema is the first value of
Close, you then re-defined the same array value as Ref(ref_ema,-1)+(C-Ref(ref_ema,-1))/15;, now although this is an impossible calculation it would provide a value even if only null, But then you re-define the exact same array value as C[0] again. Each new
definition overwrites any previous defined value of the same variable. so for future reference ref_ema[0] = C[0]
The other problem is that to truely calculate EMA it must start at the position in the array where it has a full range of bars to satisfy the
period setting in the EMA. so EMA(C,15) needs to start at barindex()==15 or [15] as this has 15 bars prior to it in the array of Close values
Make sense or clear as mud? :)
-- Cheers
Graham AB-Write >< Professional AFL Writing Service Yes, I write AFL code to your requirements
http://e-wire.net.au/~eb_kavan/ab_write.htm
On 2/13/06, tom soyer <tom.soyer@xxxxxxxxx> wrote:
> I am trying to understand the built-in REF() function. If it does what the manual says it does, then one should be able to use it to calculate EMA that is initilized using the 1st element of an array (e.g., Close[0]). But if you do that, it doesn't work. So either my understanding of the function is wrong, or there is something wrong with the construction of the function. I wish someone knows which one is which.
> > > > On 2/12/06, cstrader <cstrader232@xxxxxxxxxxxx> wrote: > >
> > Maybe I don't get what you're trying to do, but it sounds like you could use > > something like: > > > > MyMA = MA(C, BarsSince(BarIndex() == 0 )); > > > > > > ----- Original Message -----
> > From: "tomsoyer_php" < tom.soyer@xxxxxxxxx> > > To: <
amibroker@xxxxxxxxxxxxxxx> > > Sent: Sunday, February 12, 2006 9:27 PM > > Subject: [amibroker] Possible problem with the REF() function? > > > > > > > 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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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 > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > 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 > > > > > > > >
> > > > > > SPONSORED LINKS > > Investment management software Real estate investment software Investment property software > > Software support Real estate investment analysis software Investment software
> > > > ________________________________ YAHOO! GROUPS LINKS > > > > > > Visit your group "amibroker" on the web. > > > > To unsubscribe from this group, send an email to:
> > amibroker-unsubscribe@xxxxxxxxxxxxxxx > > > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> > To unsubscribe from this group, send an email to: > > amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. > > > > ________________________________
> > > > 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
> > > > > > > SPONSORED LINKS > Investment management software Real estate investment software Investment property software > Software support Real estate investment analysis software Investment software
> > ________________________________ YAHOO! GROUPS LINKS > > > Visit your group "amibroker" on the web. > > To unsubscribe from this group, send an email to: >
amibroker-unsubscribe@xxxxxxxxxxxxxxx > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> To unsubscribe from this group, send an email to: > amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. > > ________________________________
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
SPONSORED LINKS
YAHOO! GROUPS LINKS
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
SPONSORED LINKS
YAHOO! GROUPS LINKS
|