Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Order Causing NT Strategy to Stop Working

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

    Entry Order Causing NT Strategy to Stop Working

    Could somebody help me figure out what my error is?

    I have tried to make this as clear as possible with what is going on. Also written is an explanation of what the strategy is supposed to do so that you are not just blindly trying to figure it out. Please let me know if you have any questions or if I just did not make it clear enough. Any help is really appreciated!

    I have attached the script file in order to save on the number of words posted.

    When lines #109 & #126 are commented out, all of the draw objects draw correctly. When they are not commented out, that is where I start running into issues.

    These two lines are exactly the same except that one is for longs and the other is for shorts

    In the section for TrendDirection.Up (Line #119), when the LongEntry (Line #109) is uncommented, the draw objects will draw correctly until a long trade is placed. As soon as that happens, no more draw objects will be drawn. The Output Window says,

    **NT** Error on calling 'OnExecution' method for strategy 'LondonBreakout/e3356e67a4c7435598c9044ef8e9f00e': Object reference not set to an instance of an object.
    When I look at the OnExecution area to find out what it might be, I don't see what the problem could be. (I expect that it is referring to line #183 - 189 - Blue Section)

    Would somebody be willing to take a look at this and see if this is, in fact, where my problem is and let me know what I could to fix it?

    Maybe you want a bit of an idea of what this code is supposed to do.

    In its current form, it is supposed to find a range (between 2:00 am and 9:00 am). With that range it is supposed to find the highest bar and the lowest bar and take note of the High and Low respectively. When it finds the high, for example, and the TrendDirection is Up, then it is supposed to place a EnterLongStop order x pips above that high and x pips below the low of the range. It is then supposed to place a SellLimit order above the Entry Order. If the Entry Order is not triggered by a particular time (22:00) then it is to be cancelled.

    It is only supposed to take one trade per day, therefore a flag was created (restrictTrade). When the Entry Order is triggered then the flag is to be set to true, thus not allowing any more trading to happen for that day. Then, on the next day, during the range then the flag is changed back to false in order to allow trading. (I have tried various combinations of this flag to see if it is causing the problem, but it does not appear to be the issue).

    If you have any more questions, feel free to ask me. Thank you in advance for any help that anyone is able to give.
    Attached Files

    #2
    jg123, the issue looks to me like connected to the missing for null check in your very first OnExecution statement.

    if (execution.Order != null) ...

    Adding this in as check it should work.

    Comment


      #3
      That fixed the issue with the TrendDirection.Up & the TrendDirection.Down. Thanks!

      There is now a similar issue going on with the TrendDirection.NoTrend

      This one has a slightly different logic associated with placing the stop/limit & cancellation of the orders.

      In OnExecution() - still within the bracket for if(execution.Order != null) - I have this:

      Code:
      				// Setting Stop Loss & Profit Target for OCO orders &&
      				// Cancel Short Entry Order if Long Entry Order is filled & vice versa
      				else if (LongEntryOCO != null
      					&& LongEntryOCO == execution.Order)
      				{
      					LongStopOCO = ExitLongStop((rangeLow - pipBuffer),"LongStopOCO","BreakoutLongOCO");
      					LongTargetOCO = ExitLongLimit(LongEntryOCO.AvgFillPrice + (LongEntryOCO.AvgFillPrice - (rangeLow - pipBuffer)), "LongTargetOCO", "BreakoutLongOCO");
      					CancelOrder(ShortEntryOCO);
      					restrictTrade = true;
      				}
      			
      				if (ShortEntryOCO != null
      					&& ShortEntryOCO == execution.Order)
      				{
      					ShortStopOCO = ExitShortStop((rangeHigh + pipBuffer), "ShortStopOCO", "BreakoutShortOCO");
      					ShortTargetOCO = ExitShortLimit(ShortEntryOCO.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTargetOCO", "BreakoutShortOCO");
      					CancelOrder(LongEntryOCO);
      					restrictTrade = true;
      				}
      When I comment out "CancelOrder(ShortEntryOCO); then, on the surface, it appears that the Long side is working properly. But I do not get the same results when I comment out "CancelOrder(LongEntryOCO)"

      So it appears that it has to do with the cancelling out of orders.

      I did receive a message in the Output Window saying, "Object reference not set to an instance of an object." I have googled that phrase and I can't seem to come up with any definitive meaning of that. Could you 1. help me find out what is going on with the TrendDirection.NoTrend logic & 2. help me understand what is going on when I see that error?

      Thanks!

      Comment


        #4
        I forgot to mention that I also received this in the Output Window:

        **NT** An Enter() method to submit an entry order at '6/10/2014 9:00:00 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
        I have read through those rules but I do not see me violating any of them in my code.

        Comment


          #5
          jg123, great you're aware of the order handling rules, now it would be a matter to debug which exact scenario you have run into on the mentioned bar where an order was ignored. From the time I would think a previous trade is still open and exits working, when you try placing a new entry in potentially opposite direction?

          A general tip on null references could be reviewed here - http://www.ninjatrader.com/support/f...ead.php?t=4226

          This means you need to check through your new code snippet and ensure you're not accessing an object property, where the object itself could be actually null already.

          Comment


            #6
            Great, Thanks!

            As soon as I read the example, I knew exactly what was going on. This is good information and will be bookmarked. Thanks!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            639 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            572 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X