Floating error  [SOLVED]

Questions about MultiCharts and user contributed studies.
stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Floating error

Postby stefanols » 31 May 2017

Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Thanks in advance.

Best regards
Stefan

Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);

User avatar
TJ
Posts: 7150
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2040 times

Re: Floating error

Postby TJ » 31 May 2017

stefanols wrote:Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Thanks in advance.

Best regards
Stefan

Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);



Please show us what/how you tried to correct the problem.

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

Postby stefanols » 31 May 2017

Something like this:
value1=(C+2*StdDev(C,length)-average(C,length))*1.0000001;
Value2=(4*(StdDev(C,length)))*1.0000001;
Value3= ((value1)/(value2)*1.000001) *100;

User avatar
TJ
Posts: 7150
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 987 times
Been thanked: 2040 times

Re: Floating error

Postby TJ » 31 May 2017

What is zero times 1.0000001 ?
These users thanked the author TJ for the post:
stefanols

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

Postby stefanols » 31 May 2017

you are right. How can i come around that then?

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error  [SOLVED]

Postby stefanols » 31 May 2017

I should add 0.000001 then?

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

Postby stefanols » 31 May 2017

Thanks!

User avatar
ABC
Posts: 625
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 354 times
Contact:

Re: Floating error

Postby ABC » 31 May 2017

stefanols wrote:I should add 0.000001 then?


stefanols,

what if Value2 = -0.000001?

I would suggest to check if the denominator of a division is different than 0 (for every division that you perform within a code). If it is, do the division otherwise you can do something else (optional).

For example:

Code: Select all

if denominator <> 0 then
      result = numerator / denominator
else
   result = 0 ;    


Regards,

ABC
These users thanked the author ABC for the post:
stefanols


Return to “MultiCharts”