Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Debugging with Try & Catch

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Debugging with Try & Catch

    I have done a debug with Try & Catch (Thanks Matthew!!) and have narrowed down an error (probably one of so many!)

    The following is the code that has the error.

    Code:
    			if (LongEntryA != null 
    				&& LongEntryB != null
    				&& Close[0] < SMA(sMAPeriod)[0]
    				|| Close[0] < Ichimoku(9,26,52).KijunSen[0])
    			{
    				CancelOrder(LongEntryA);
    				CancelOrder(LongEntryB);
    			}
    Here is the error that I am getting in the Output Window
    8/4/2011 11:00:00 PM System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Object.GetType()
    at NinjaTrader.Strategy.StrategyBase.CancelOrder(IOrd er iOrder)
    at NinjaTrader.Strategy.TrendPilot.OnBarUpdate()
    (which, btw, I can't seem to get it to draw on the chart using DrawText()...is that normal?)

    Can someone help me with what is probably wrong with this? I am not sure if you have enough information to be able to determine it. The goal of this logic is to cancel any open orders if the candle closes below the KijunSen line and/or the SMA.

    Thanks for your help.

    #2
    Hello,

    Problem is here:

    {
    if (LongEntryA != null
    && LongEntryB != null
    && Close[0] < SMA(sMAPeriod)[0]
    }
    OR
    {
    || Close[0] < Ichimoku(9,26,52).KijunSen[0])
    }

    Basically that OR side of the statement can become true and if its true then the LongEntryA/B will try to cancel. But the != null check isn't on that side so it tries to cancel an order that is actually null.
    BrettNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    67 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    36 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    59 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X