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

Series and Simple Functions



PureBytes Links

Trading Reference Links

At 6:52 PM -0500 3/15/98, Cab Vinton wrote:

>Does anyone have a real live _example_ of code where the series/ simple
>distinction makes a difference? (Maybe of code with a simple function
>that is _not_ evaluated on every bar?)
>
>That would help no end for those of us without extensive programming
>backgrounds.


Here is another example. It is the XAverage function.

The Omega version is shown first. It refers to a previous value of XAverage
as "XAverage[1]". Thus, the system knows this is a series function.
(Functions which refer to a previous value using the brackets force the
function to be series type.)

As Mark Jurik stated, the series function will be evaluated on every bar
automatically to assure that the value "XAverage[1]" is always correct. The
downside is that you cannot use a variable for the "Price" input to the
function. It has to be a data series. This is sometimes inconvenient.

The second version is a rewrite as a simple function. Here, instead of
referring to "XAverage[1]", I saved the last value of XAverage as the
variable "XLast". This eliminated the need to reference the previous value
so I could make this a simple function.

Now, I can use a variable as the "Price" input to the function. The
downside is that the function has to be called on every bar. If it is not,
the value of XLast will not be the value on the last bar, but will be THE
VALUE ON THE LAST BAR ON WHICH THE FUNCTION WAS EVALUATED. This means you
cannot include this function in a conditional expression that might prevent
it from being evaluated on every bar.

In addition, as noted in my post of 3/11/98, you should not include a
simple function in a complex comparison expression such as:

     Condition1 = A > B and XAverage.V(M,50) < N;

since if the first comparison

     A > B

is not true, then the second expression

     XAverage.V(M,50) < N

will not be evaluated on that bar so the function will return the wrong
value on future bars.

Bob Fulks


{ *******************************************************************

  Study        : XAverage

  Last Edit    : 7/7/95

  Provided By  : Omega Research, Inc. (c) Copyright 1995

********************************************************************}
inputs : Price(NumericSeries),Length(NumericSimple);
vars   : Factor(0);

if Length + 1 <> 0
then begin
  if CurrentBar <= 1
  then begin
     Factor = 2 / (Length + 1);
     XAverage = Price;
  end
  else
     XAverage = Factor * Price + (1 - Factor) * XAverage[1];
end;



{ *******************************************************************

  Study        : XAverage.V

  Last Edit    : 11/2/96

  Provided By  : Bob Fulks

  Description  : This is a recoding of the XAverage function as a
      "simple function" rather than as a "series function". For
      correct results it must be evaluated on every bar, as is
      normal for Omega simple functions.

********************************************************************}
inputs : Price(NumericSeries), Length(NumericSimple);
vars   : Factor(0), XLast(0);

if Length + 1 <> 0
then begin
  if CurrentBar <= 1
  then begin
     Factor = 2 / (Length + 1);
     XAverage.V = Price;
     XLast = Price;
  end
  else begin
     Value1 = Factor * Price + (1 - Factor) * XLast;
     XAverage.V = Value1;
     XLast = Value1;
  end;
end;