Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange Error with Strat Limit Orders

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

    Strange Error with Strat Limit Orders

    I have the following lines of code (print statements were use to help debug):

    Code:
    [COLOR=#add8e6]if[/COLOR] ([COLOR=#f0f0f0]jelDirection[/COLOR] == -[COLOR=#22cdff]1[/COLOR])
    {
    [COLOR=#f0f0f0]Print[/COLOR]([COLOR=#0076ec]"Enter Place Short"[/COLOR]);
    [COLOR=#f0f0f0]Print[/COLOR]([COLOR=#0076ec]"Ask: "[/COLOR] + [COLOR=#f0f0f0]GetCurrentAsk[/COLOR]());
    [COLOR=#f0f0f0]Print[/COLOR]([COLOR=#0076ec]"QTY: "[/COLOR] + [COLOR=#f0f0f0]_TradeQTY[/COLOR]);
    [COLOR=#f0f0f0]EnterShortLimit[/COLOR]([COLOR=#f0f0f0]_TradeQTY[/COLOR], [COLOR=#f0f0f0]GetCurrentAsk[/COLOR](), [COLOR=#0076ec]"jelOrder"[/COLOR]);
    [COLOR=#f0f0f0]Print[/COLOR]([COLOR=#0076ec]"OrderPlaced"[/COLOR]);
    [COLOR=#f0f0f0]barNumberofOrder[/COLOR] = [COLOR=#f0f0f0]CurrentBar[/COLOR];
    [COLOR=#f0f0f0]Print[/COLOR]([COLOR=#0076ec]"*** ENTER SHORT*** Bar#"[/COLOR] + [COLOR=#f0f0f0]barNumberofOrder[/COLOR] + [COLOR=#0076ec]" jelDir: "[/COLOR] + [COLOR=#f0f0f0]jelDirection[/COLOR] + [COLOR=#0076ec]" dirSC: "[/COLOR] + [COLOR=#f0f0f0]dirSC[/COLOR][[COLOR=#22cdff]0[/COLOR]] + [COLOR=#0076ec]" scDirCount: "[/COLOR] + [COLOR=#f0f0f0]_scDirectionCount[/COLOR] + [COLOR=#0076ec]" dirTH: "[/COLOR] + [COLOR=#f0f0f0]dirTH[/COLOR][[COLOR=#22cdff]0[/COLOR]] + [COLOR=#0076ec]" dirIndex: "[/COLOR] + [COLOR=#f0f0f0]dirIndex[/COLOR][[COLOR=#22cdff]0[/COLOR]]);
    }
    that produces the following in the output window:

    Code:
    Enter Place Short
    Ask: 2087.25
    QTY: 1
    Strategy 'jelMM2/-1': Error on calling 'OnOrderUpdate' method on bar 158: Object reference not set to an instance of an object.
    OrderPlaced
    I think the error is coming form EnterShortLimit - but I am not sure.

    The execution never makes it out of the function before the error because the very next step is to exit this function and enter a function called form OnBarUpdate to manage the trade. It never makes it to that print statement.

    Is there a way to do a line-by-line step through the code? using print statements is making it hard for me to debug.

    #2
    Hello jeliner,

    Something about this is not making sense.

    An error that occurs when there is a null value should cause your script to be disabled.
    The print 'OrderPlaced' is unexpected if the script hit a null reference error.

    If you add the time to the prints, are all of the prints appearing at the same time?
    Code:
    Print(string.Format("{0} | Ask: {1}", Time[0], GetCurrentAsk()));
    Print(string.Format("{0} | OrderPlaced", Time[0]));
    Can you add the time to your prints and include the output once more?

    You can comment out the other prints if this is making things confusing.
    You can add logic to only print this once and return to make things easier when you are testing.

    Also, would you be able to copy this code into a new script to isolate it and allow us to test this as well?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Here is the complete place order function with the time elements added...
      Notice after adding the time elements its not hitting the Print(Placed Order") statement
      Code:
      [COLOR=black]private void jelPlaceOrder( int jelDirection)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black]   if (jelDirection == 0) return;[/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black]   if (entryOrder!=null)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]CancelOrder(entryOrder);[/COLOR]
      [COLOR=black]barNumberofOrder= 0;[/COLOR]
      [COLOR=black]entryOrder = null;[/COLOR]
      [COLOR=black]Print("Forced Cancel in order placement - Should not Happen");[/COLOR]
      [COLOR=black]}[/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black]barNumberofOrder = CurrentBar;[/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black]if (jelDirection == 1)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]EnterLongLimit(_TradeQTY, GetCurrentBid(), "jelOrder");[/COLOR]
      [COLOR=black]barNumberofOrder = CurrentBar;[/COLOR]
      [COLOR=black]Print("*** ENTER LONG*** Bar#" + barNumberofOrder + " jelDir: " + jelDirection + " dirSC: " + dirSC[0] + " scDirCount: " + _scDirectionCount + " dirTH: " + dirTH[0] + " dirIndex: " + dirIndex[0]);[/COLOR]
      [COLOR=black]}[/COLOR]
      [COLOR=black][/COLOR]
      [COLOR=black]if (jelDirection == -1)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]Print("Enter Place Short TIME: " + Time[0]);[/COLOR]
      [COLOR=black]Print("Ask: " + GetCurrentAsk() + " TIME: " + Time[0]);[/COLOR]
      [COLOR=black]Print("QTY: " + _TradeQTY + " Time: " + Time[0]);[/COLOR]
      [COLOR=black]EnterShortLimit(_TradeQTY, GetCurrentAsk(), "jelOrder");[/COLOR]
      [COLOR=black]Print("OrderPlaced" + " Time: " + Time[0]);[/COLOR]
      [COLOR=black]barNumberofOrder = CurrentBar;[/COLOR]
      [COLOR=black]Print("*** ENTER SHORT*** Bar#" + barNumberofOrder + " jelDir: " + jelDirection + " dirSC: " + dirSC[0] + " scDirCount: " + _scDirectionCount + " dirTH: " + dirTH[0] + " dirIndex: " + dirIndex[0]);[/COLOR]
      [COLOR=black]} [/COLOR]
      [COLOR=black]}[/COLOR]
      [COLOR=black][/COLOR]
      Here is the Output window...

      Code:
      Enter Place Short TIME: 6/10/2016 4:28:35 AM
      Ask: 2087.25 TIME: 6/10/2016 4:28:35 AM
      QTY: 1 Time: 6/10/2016 4:28:35 AM
      Strategy 'jelMM2/-1': Error on calling 'OnOrderUpdate' method on bar 158: Object reference not set to an instance of an object.

      Comment


        #4
        Hello jeliner,

        Just to confirm once more after this error is hit, the script is remaining enabled and is not becoming disabled?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The strategy analyzer stops when the script hits this error

          Comment


            #6
            I am in the middle of final exams for doctorate program in anesthesia. Once done, Ill install Visual Studio and see if I can step through it.

            Its my understanding that ninjatrader is creating (or trying to) an order object from the Cbi.Order class to manage the open order? I am using some code in the OnOrderUpdate event to capture this object and assign it to the entryOrder variable of type order.

            I am hoping if I run this through visual studio I will be able to step through it and maybe see how close if at all it gets to creating this order object? just a hunch on where the error might be?

            Could this be related to data that is historical in nature in the analyzer and that an actual ECN order can not in reality be placed because this is on past data? You would think the code would know its being run through the analyzer? is there a toggle switch I might need to activate?

            Comment


              #7
              Hello jeliner,

              The script should stop when hitting this error.
              This is the expected behavior. From your output in your first post, it appeared that the 'OrderPlaced' text was printed after the script hit the error which should not be possible.

              The error indicates one of the variables that is being checked in OnOrderUpdate() has a value of null.
              'Object reference not set to an instance of an object.'

              I would recommend you add prints to your script in the OnOrderUpdate() method to quickly find which variable has a null value. (After the order is submitted, this triggers OnOrderUpdate() when the order changes states. This is when the error is being triggered.)

              This code you have posted is a custom method. I am not able to see which NinjaTrader method this is triggered from. However, my guess is that this is not triggered from OnOrderUpdate().
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              54 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              130 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              72 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              44 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              49 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X