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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    621 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    567 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X