View Full Version : Any Other Way to Debug
darckeen
03-15-2009, 11:57 PM
I've got a infinite loop bug in my code that I suspect is due to floating point error and was trying to debug it through Print() to the output window since I only have the express version of Visual C#. Problem is that the code locks up NT and I have to shut its process down to get it back up. Is there any way i can see the output text after bringing NT back, or can i use Alerts or something in a way like Msgbox() in VB, or is it possible to do something like CTRL-C to stop an indicator when its locked so i can see the output text and not have to shut down NT?
TIA
NinjaTrader_Bertrand
03-16-2009, 02:54 AM
Hi, did you already check this tip - especially the double epsilon part? http://www.ninjatrader-support2.com/vb/showthread.php?t=3929
You can also look into this one - http://www.ninjatrader-support2.com/vb/showthread.php?t=9825
darckeen
03-16-2009, 12:50 PM
Great, those links have some useful stuff. Compare() looks like it would be really helpful in this perticular situation. When using Log(), if the script locks up NT can i still see what messages were generated prior to killing the NT process? Also out of curriosity, does the debugging feature work with the standard version of Visual Studio 2008 or would I need to get the pro version?
Thanks
NinjaTrader_Josh
03-16-2009, 12:55 PM
darckeen,
If NT locks up, you will get whatever happened before the lock up. Remember the Output Window is part of NinjaTrader so a lock up in NT may even lock you from viewing the Output Window.
You can use either version of Visual Studio, just not the Express version.
darckeen
03-18-2009, 12:13 PM
I've been encountering a related problem with rounding, basically i'm trying to round the price to the next highest digit. The problem arises when you have a price where the last digit is a 5. Sometimes it will round down, other times it will round down. I think I came up with a way to get around the problem but I was wondering if there is a better way to handle this.
int decimals = (int)Math.Abs(Math.Log10(TickSize));
double round = Math.Round(Close[0],decimals-1);
int remain = (int)Math.Round((Close[0] - round) * 1 / TickSize);
if (remain == 5 || remain == -5) {
Print("Close:" + Close[0] + " Rounded#1:" + Math.Round(Close[0],decimals-1) + " Remain:" + remain);
Print("Close:" + Close[0] + " Rounded#2:" + Math.Round(Math.Round(Close[0],decimals),decimals-1) + " Remain:" + remain);
Print("Close:" + Close[0] + " Rounded#3:" + Math.Round(Close[0]-TickSize/2,decimals-1) + " Remain:" + remain);
}
Method #3 seems to work I guess but I was wondering if there were a better way.
NinjaTrader_Josh
03-18-2009, 12:30 PM
darckeen,
Unfortunately I do not know. You could try searching google for more rounding routines. There are a lot of resources floating around.
roonius
03-18-2009, 10:41 PM
I've been encountering a related problem with rounding, basically i'm trying to round the price to the next highest digit. The problem arises when you have a price where the last digit is a 5. Sometimes it will round down, other times it will round down. I think I came up with a way to get around the problem but I was wondering if there is a better way to handle this.
int decimals = (int)Math.Abs(Math.Log10(TickSize));
double round = Math.Round(Close[0],decimals-1);
int remain = (int)Math.Round((Close[0] - round) * 1 / TickSize);
if (remain == 5 || remain == -5) {
Print("Close:" + Close[0] + " Rounded#1:" + Math.Round(Close[0],decimals-1) + " Remain:" + remain);
Print("Close:" + Close[0] + " Rounded#2:" + Math.Round(Math.Round(Close[0],decimals),decimals-1) + " Remain:" + remain);
Print("Close:" + Close[0] + " Rounded#3:" + Math.Round(Close[0]-TickSize/2,decimals-1) + " Remain:" + remain);
}
Method #3 seems to work I guess but I was wondering if there were a better way.
How about built-in method Round2TickSize(double) ?
darckeen
03-24-2009, 01:28 AM
Thanks, Round2TickSize seems to be what i was looking for. To be honest though, for now imo the simplest way to handle floating point errors is just convert the price to a decimal. Slight performance hit is worth the lack of headaches.