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

Re: [amibroker] Help with an indicator...



PureBytes Links

Trading Reference Links

Hi,

Sometimes things look more complicated than they should :-)

Your formula:

AMA = ref(AMA,-1)+sc*(close-ref(AMA,-1)); 

Is the same as:

AMA = sc * close + ( 1 - sc ) * Previous( AMA );

This one is in fact the formula for exponential moving average
sc is simply smoothing constant = 2 / (periods + 1)

So periods = -1 + 2/sc

So you final AFL code for your AMA is:

AMA = ema( close, -1 + 2/sc ); 

It is not only faster to execute but also does not have any self-references.

In AFL you can reference the same variable in the assignment statement 
(you must initialize it however):

testvar = 0;
testvar = testvar + close;

But... AFL is a vector (or array) based language performing operations on array
in one run (that's why it is so fast) - so you can not iterate thru elements
of the array. Statements like variable = ref( variable, -1 ) + something 
will not work correctly.
To overcome this problem functions like cum(), sum(), ema() should be used.

Best regards,
Tomasz Janeczko


----- Original Message ----- 
From: <jmjames@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday, March 13, 2001 05:34
Subject: [amibroker] Help with an indicator...


> Hi!
> 
> I have had trouble getting an indicator to work. More specific, I 
> have had trouble with the following line:
> 
> AMA = ref(AMA,-1)+sc*(close-ref(AMA,-1)); 
> 
> It comes back with an error of:
> 
> AMA = ref(AMA,
> ^
> 
> Unknown identifier
> 
> Am I doing something wrong, or will AmiBroker not handel a ref to 
> itself?
> 
> Thank for your time and effort on my questions!!
> 
> Regards,
> 
> Jared James
> jjames@xxxx
> 
> 
> 
> 
> 
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
>