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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    46 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X