Thanks again, MG.
I tested this:
VNor:=(V-MVolHis)/Max(SVolHis,1);
and, as expected, works perfectly. I like this
workaround.
Regards.
Manuel
----- Original Message -----
Sent: Tuesday, April 05, 2005 8:39
PM
Subject: [EquisMetaStock Group] Re:
Division by 0
Thanks, you're welcome! Just a note, if you
really want a test to pick up the divide by zeros, you have to catch it
before the division!
What I mean is this, you have to test for a zero
before you divide and based on the test either do or skip/modify the
divide. Now, I haven't tested this in MS, just off the cuff stuff,
but I think if you modify your original code to the following it will do
the trick:
VNor:=(V-MVolHis)/if(test,SVolHis,1);
Original
is
VNor:=If(Test,(V-MVolHis)/SVolHis,PREV);
The difference is that, in the
original, based on the value of test, we are switching between the series
or the fall back PREV. But the series is already calculated,
regardless of test, and we just use test to switch between the two.
In the new version, we test before we divide. We still have to get a
fallback value though, which is PREV I gather from your code. So we
now add the switch code again
VNor:=if(test,(V-MVolHis)/if(test,SVolHis,1),prev);
which does what we
want, but now we are testing twice - once to ensure we can divide and once
to decide if we should use use the calculated or fallback value.
Anyhow, this is waaaay to complex for what we want to do, so let us
simplify a bit. We can use max, since we want to ensure we use a
positive number when we divide, so we can change it
to
VNor:=if(test,(V-MVolHis)/max(SVolHis,1));
or, to come full circle!
just add a very small amount and you have a working
fix!
VNor:=(V-MVolHis)/(SVolHis+1);
Regards MG Ferreira TsaTsa EOD
Programmer and trading model builder http://www.ferra4models.com http://fun.ferra4models.com
--- In equismetastock@xxxxxxxxxxxxxxx, "Manuel
Cabedo" <manelcabedo@xxxx> wrote: > Good idea, MG! It works
fine. Thank you. > Regards. > > Manuel >
> ----- Original Message ----- > From:
MG Ferreira > To: equismetastock@xxxxxxxxxxxxxxx
> Sent: Tuesday, April 05, 2005 6:52 PM >
Subject: [EquisMetaStock Group] Re: Division by 0 > > >
> The problem with ignoring division by zero stuff, is that
(in the MS I > use) it results in zeroes in the series,
which you often do not want. > One way to solve this, is to
add a tiny amount, so in your case, >
> SVolHis = Stdev(V,200) +
1; > > or add >
> +0.001 >
> just to make sure it is not zero. >
> Regards > MG
Ferreira > TsaTsa EOD Programmer and trading model
builder > http://www.ferra4models.com >
http://fun.ferra4models.com >
> > --- In equismetastock@xxxxxxxxxxxxxxx,
"manelcabedo" > <manelcabedo@xxxx>
wrote: > > > > >
> Hi friends, > > > > Is there
any way of avoiding the boring division by zero messages in
> > custom indicators? > >
> > I've designed this beautiful Normalized Volume
Indicator but > > (incomplete series, I suppose) gives
me a lot of division by zero > > errors. Yet I think I
prevent them with the Test variable, but it is > >
not actually the case, it does not work. Any idea or
comment? > > > >
MVolHis:=Mov(V,200,S); > >
SVolHis:=Stdev(V,200); > >
Test:=SVolHis>0; > >
VNor:=If(Test,(V-MVolHis)/SVolHis,PREV); > >
VUp:=If(VNor>0,VNor,0); {blue color} > >
VDn:=If(VNor<0,VNor,0); {red color} > >
VUp;VDn;+1;-1 > > > >
Regards. > > > > Manuel >
> > > >
> ------------------------------------------------------------------------------ >
Yahoo! Groups Links > > a.. To visit your
group on the web, go to: > http://groups.yahoo.com/group/equismetastock/ >
> b.. To unsubscribe from this group, send an
email to: >
equismetastock-unsubscribe@xxxxxxxxxxxxxxx >
> c.. Your use of Yahoo! Groups is subject to
the Yahoo! Terms of Service.
Yahoo! Groups Links
|