floating point exception error

Questions about MultiCharts and user contributed studies.
rhodan
Posts: 3
Joined: 30 Dec 2009
Been thanked: 1 time

floating point exception error

Postby rhodan » 27 Dec 2011

I have an indicator called Efficient Ratio.
In a lower time frame like 30 minutes bar, it is doing fine.
but it generate an floating point exception error in 10 minutes bar..



Code: Select all

// Indicator, Name : Kaufman Efficiency Ratio

input: Erperiod(10);

vars: change(0),noise(0),efratio(0);

{CALCULATE EFFICIENCY RATIO}
noise = 0;
if currentbar > ERperiod then begin

   change = absvalue(c[0] - c[ERperiod]);
   for Value1 = 0 to Erperiod - 1 begin
      noise = noise + AbsValue(close[Value1] - close[Value1+1]);
   end;
   efratio = change/noise;

end;

plot1(efratio,"efratio");

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: floating point exception error

Postby TJ » 27 Dec 2011

rhodan wrote:I have an indicator called Efficient Ratio.
In a lower time frame like 30 minutes bar, it is doing fine.
but it generate an floating point exception error in 10 minutes bar..



// Indicator, Name : Kaufman Efficiency Ratio

input: Erperiod(10);

vars: change(0),noise(0),efratio(0);

{CALCULATE EFFICIENCY RATIO}
noise = 0;
if currentbar > ERperiod then begin

change = absvalue(c[0] - c[ERperiod]);
for Value1 = 0 to Erperiod - 1 begin
noise = noise + AbsValue(close[Value1] - close[Value1+1]);
end;
efratio = change/noise;

end;

plot1(efratio,"efratio");


how much data do you have on the chart?
what is the instrument?


ps. I have tried your code, it works fine in all resolutions and Erperiods.


pps. please use code tag when posting codes. It makes reading easier.
I have tagged the code for you this time.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: floating point exception error

Postby JoshM » 28 Dec 2011

A wise man once said..

TJ wrote:usually caused by division by zero.

viewtopic.php?f=1&t=8354#p38881
:)

Looking at your code..

Code: Select all

(..)
efratio = change/noise;
(..)


It's probably worth to try something like..

Code: Select all

if (noise = 0) then     noise = noise[1];
efratio = change / noise;
These users thanked the author JoshM for the post:
TJ

rhodan
Posts: 3
Joined: 30 Dec 2009
Been thanked: 1 time

Re: floating point exception error

Postby rhodan » 28 Dec 2011

Solved..

Thanks you all, I wished you alll have happy new year !!!!!!!!!!!!!!!!!!!!
These users thanked the author rhodan for the post:
JoshM


Return to “MultiCharts”