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?
Debugging a floating point invalid operation error
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Debugging a floating point invalid operation error
you can start with a review of any operation that involves a division...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?
- 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
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.
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.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Debugging a floating point invalid operation error
RSI or ADX Indicators do not cause errors,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.
it is the improper application of the indicators that can cause errors.
You can always post a snippet if you have any doubts.
- 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
... 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!
Re: Debugging a floating point invalid operation error
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.... 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!