Debugging a floating point invalid operation error

Questions about MultiCharts and user contributed studies.
User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Debugging a floating point invalid operation error

Postby furytrader » 09 Jun 2011

I am programming a very complicated (1600+ line) strategy and while it compiles okay, I sometimes receive a "floating point invalid operation" error when I place it on a chart. I say "sometimes" because the code uses random numbers, among other things.

Here's my question: how do I find out which line number is causing the error?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Debugging a floating point invalid operation error

Postby TJ » 10 Jun 2011

I am programming a very complicated (1600+ line) strategy and while it compiles okay, I sometimes receive a "floating point invalid operation" error when I place it on a chart. I say "sometimes" because the code uses random numbers, among other things.

Here's my question: how do I find out which line number is causing the error?
you can start with a review of any operation that involves a division...

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Debugging a floating point invalid operation error

Postby furytrader » 11 Jun 2011

Tj,

As always, thanks for the suggestion. I will go through each line and verify that any operations involving division are only using variables that are verified to be appropriate for that equation.

Part of me wonders, though, whether it's possible any of the built-in indicators could be causing this. You see, I had seen similar errors in the past, and when I took out certain indicators (for example, the RSI and ADX), the errors went away. I never determined why those particular indicators would cause this floating point error though.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Debugging a floating point invalid operation error

Postby TJ » 11 Jun 2011

Tj,

As always, thanks for the suggestion. I will go through each line and verify that any operations involving division are only using variables that are verified to be appropriate for that equation.

Part of me wonders, though, whether it's possible any of the built-in indicators could be causing this. You see, I had seen similar errors in the past, and when I took out certain indicators (for example, the RSI and ADX), the errors went away. I never determined why those particular indicators would cause this floating point error though.
RSI or ADX Indicators do not cause errors,
it is the improper application of the indicators that can cause errors.


You can always post a snippet if you have any doubts.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Debugging a floating point invalid operation error

Postby furytrader » 11 Jun 2011

... and you would be right. It turns out that the issue had to do with trying to calculate performance-related statistics when there were no trades. I had thought I had programmed a catch for this, but apparently not!

Nick
Posts: 496
Joined: 04 Aug 2006
Has thanked: 4 times
Been thanked: 24 times

Re: Debugging a floating point invalid operation error

Postby Nick » 14 Jun 2011

... and you would be right. It turns out that the issue had to do with trying to calculate performance-related statistics when there were no trades. I had thought I had programmed a catch for this, but apparently not!
Oh for a run time debugger :) Even a rudimentary one! AS TJ helpfully suggested divide by zero is often the problem so looking for things like zero volume, zero range (h=l), zero trades and other similar occurrences will get you there. Can become much more difficult to find as the code gets longer.


Return to “MultiCharts”