Hi,
Anyone that can help with below code?
Compile ok but get invalid floating point error.
Thanks in advance!
input: Length(21);
Value1= Sum((2*close-high-low)/(high-low)*volume,Length)/Sum(volume,Length);
Plot1( Value1, "IntraDI" ) ;
Plot2(0);
floating point error [SOLVED]
Re: floating point error
In your denominator you have (high - low). That could be 0 thus the floating point zero error. Change the equation so you are not dividing by anything that could be 0.
Re: floating point error
ok thanks for the input:
I changed to
input: Length(21);
Value1= Sum((2*close-high-low)/(high-(low * 0.999999999999999999999999999))*volume,Length)/Sum(volume,Length);
Plot1( Value1, "IntraDI" ) ;
Plot2(0);
Or are there a more elegant way to do it?
I changed to
input: Length(21);
Value1= Sum((2*close-high-low)/(high-(low * 0.999999999999999999999999999))*volume,Length)/Sum(volume,Length);
Plot1( Value1, "IntraDI" ) ;
Plot2(0);
Or are there a more elegant way to do it?
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: floating point error
I would break down the components for easy reading and debugging.
Code: Select all
input: Length(21);
var:
IntraDI(0),
numer1(0),
denom1(0),
numer(0),
denom(0);
numer1 = (2*close-high-low) ;
denom1 = (high-low)*volume ;
if denom1 <> 0 then
numer = sum( numer1 / denom1 , Length );
denom = Sum(volume, Length );
if denom <> 0 then
IntraDI = numer / denom;
Plot1( IntraDI, "IntraDI" ) ;
Plot2(0);
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times