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

Re : Message pops up say can't divide by zero



PureBytes Links

Trading Reference Links

Dans un courrier daté du 28/08/98 02:09:58  , vous avez écrit :

<< 
 Input: Price(C),Length(18),SDev(2),upper(100),Lower(-100);

 Plot1(((100*(Price-$Lowerband(Price,Length,SDev))/($Upperband(Price,Length,SD
ev)-$Lowerband(Price,Length,SDev)))-50)*2,"Place");
 
 Plot2(upper,"Upper");
 Plot3(lower,"Lower");
 IF CheckAlert Then Begin
   IF Plot1 Crosses Above Plot2 or Plot1 Crosses Below Plot2
   or Plot1 Crosses Above Plot3 or Plot1 Crosses Below Plot3
   or Plot2 Crosses Above Plot3 or Plot2 Crosses Below Plot3
   Then Alert = TRUE;
 End;
 
 Can't figure what its needs without messing up what the original author was
 attempting to do here.
 Anybody see the problem it will verify.
 
 Thanks in Advance
 
 Robert
 
 >>

As a general rule , avoid calculation in plot statements.
Do this in temporary variables, and check that you do not divide by something
that could be equal to 0.

This is the case for :
($Upperband(Price,Length,SDev)-$Lowerband(Price,Length,SDev)))
that may have a zero value, even if you do not think so

So  do :
======
value1=Price-$Lowerband(Price,Length,SDev);
value2=$Upperband(Price,Length,SDev)-$Lowerband(Price,Length,SDev);

if value2<>0 the value3= ((value1/value2)-50)*2;
plot1(value3,"Place");

Better is to write:

value0=Lowerband(Price,Length,SDev);
value1=$Upperband(Price,Length,SDev);
value3=value2-value1;
if value3<>0 then value4= (100*(price-value0)/value3-50)*2;



[Code has not been verified for parenthesis level, but you got the idea].

The other advantage is that the code is more understandable with  this
writing.

Now if you dig  more into the upperband -lowerband code difference, you should
see that its the same than calculating 2*Stdev (price, length)  in the above
expression (not verified but I'm quite sure . Just edit the user functions and
see what's in it. Most of somplifications can be done by rewriting user
functions).

In fact , it seems to me that the above code is what is known as %B. (same
calculation than %R with  the up  low Bollinger bands in lieu of highest(h,
length) and lowest(l, length) ).

Please edit the %R code and verify that I'm right (I should be).
The only diference is the rescaling added  due to the -50)*2 operation. That
will center the B% oscillator around 0.

Any TS user shoul try to understand any user function before using it.
I guarantee any kind of  progress with this method.

Sincerely,

Pierre Orphelin
www.sirtrade.com