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

Re: Simple and Series Functions ?



PureBytes Links

Trading Reference Links

At 2:25 PM +0200 9/6/99, Philippe Lhermie wrote:

>I read Jurik's article about Simple and Series Functions in Omega
>Research Magazine.
>
>1. I understand that a Series function is always calculated first
>even if it's embedded in a IF Then statment and whether this
>condition is true or false ? Am I right?

It is pulled out as if it were a separate program and executed on 
each bar. Thus, the inputs can only be constants or values related to 
a price that are known on each bar without referring to the other 
code in your program. They cannot be variables since the values of 
those variable might depend upon the context in your other code. Even 
if the variables do not depend upon the context in your code, Omega 
does not allow you to use variables as inputs to a series function, a 
major pain in the a--.

>
>2. In which case is it preferable to use a Simple Function ? may be
>it's only when it performs a calculation not referring to some past
>values of bars ago and because it consumes less RAM ?

If the inputs to the function contain a variable, it has to be a 
simple function. If you designate it as a series function it will not 
verify. If it is a simple function, it cannot refer to a past value 
of a price or a variable with the "Close[4]" type of notation. You 
can write code to remember past values as in the following example;

Val3 = Val2;
Val2 = Val1;
Val1 = Close;

X = Close - Val3;

Simple functions only get evaluated when they are called so if you 
call a simple function on every fourth bar, for example, the values 
will only be evaluated on every fourth bar, so in the above code 
example, you would be remembering only every fourth closing value. So 
if you are trying to remember every closing value, you have to be 
sure that the simple function is called on every bar:

Incorrect:
     if <condition> then Value2 = SimpleFunction(A, B);

Correct:
     Value1 = SimpleFunction(A, B);
     if <condition> then Value2 = Value1;

In the first case, the function "SimpleFunction" is called only if 
<condition> is true so will not be called on every bar.

In the second case, the function is called on every bar and equated 
to Value1. Then Value2 is set to Value1 only if <condition> is true.

The situation can be tricky to determine as in the following example:

     if Close > 25 and SimpleFunction(A, B) > 4 then begin

It looks as if "SimpleFunction" is called on every bar but this may 
not be the case. If "Close is less than 25" then the second part of 
the "if" statement may not be evaluated so the function may not be 
called on that bar. When in doubt, always equate the simple function 
to a variable and then use that variable in any complex expression as 
below:

     Value1 = SimpleFunction(A, B);
     if Close > 25 and Value1 > 4 then begin


>
>3. In a series function, when we use the brackets [x], how far in the
>past can we go ? Up to the BarNumber 1( in order to take into account
>the MaxBarsBack setting)?


You can refer back as far as the MaxBarsBack setting. If you write an 
indicator and designate MaxBarsBack as AutoDetect, it will try to 
find a value that works. In complex situations, where the number of 
bars back is a variable dynamically determined at run-time, it can 
take it several attempts to find a value that works. This shows up 
slow operation as it tries various values. You can see this if you 
use a "Print" statement such that you print data on each trial.

Many common functions (such as "Average") are provided in both series 
and simple versions and the system selects the proper one 
automatically. In most simple programs the distinction is invisible 
to the user and works pretty well. It is only when you start doing 
more complex operations that you have to be concerned with the 
distinction.

Bob Fulks