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

Re: dividing by zero



PureBytes Links

Trading Reference Links

At 6:24 PM -0500 7/17/99, preston morrow wrote:

>i am attempting to create an occilator consisting of a moving 
>average of dmi+ / dmi-. i have attempted several ways to account for 
>a divisor of zero, including the exact verbiage of the TS 4.0 error 
>message.

>following is my current version, but it occasionally still gives me 
>the dreaded error message that says i cannot divide by zero! (which 
>i know, but my programming skillss are too elementary. thanx, preston

>Input: length(13),XAVlen(3),zero(0);
>Plot1(IFF(DMIMinus(LENGTH) <> 0, (XAverage(DMIPlus(LENGTH) /
>DMIMinus(LENGTH),XAVlen)),1),"Plot1");
>Plot2(zero,"Plot2");
>IF CheckAlert Then Begin
>  IF Plot1 Crosses Above Plot2 or Plot1 Crosses Below Plot2
>  Then Alert = TRUE;
>End;



This looks correct but assumes that TradeStation handles such complex 
expressions correctly, which has not been my experience. Try using 
variables for the complex functions. In addition you will need to use 
my XAverage.V function in place of XAverage since you need to use a 
variable as input and Omega has defined the XAverage function as a 
series function (for some unknown reason) so that you can not use 
variables as inputs. This has not been verified but should be close 
to correct.

Bob Fulks

----

Input: Length(13), XAVlen(3);
Vars:  DMIM(0), DMIP(0), Ratio(0), Ave(0), Zero(0);

DMIM = DMIMinus(LENGTH);
DMIP = DMIPlus(LENGTH);


if DMIM <> 0 then Ratio = DMIP / DMIM;

Ave = XAverage.V(Ratio, XAVlen);

Plot1(Ave,"Plot1");
Plot2(Zero,"Plot2");

if CheckAlert then begin
   iF Plot1 crosses above Plot2 or Plot1 crosses below Plot2
   Then Alert = TRUE;
end;

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

         Function        : 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;