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

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");`

TJ
Posts: 6870
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 984 times
Been thanked: 1976 times

Re: floating point exception error

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.

JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1494 times
Contact:

Re: floating point exception error

A wise man once said..

TJ wrote:usually caused by division by zero.

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

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

Solved..

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