Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Unmanaged order executing when order object = null

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

    Unmanaged order executing when order object = null

    Hello,

    I'm encountering an odd situation with my unmanaged orders, using the same sequence of code that worked flawlessly with NT7.

    The code segments, a screenshot of the Output Window, as well as the .txt of the Output window is appended.

    Brief summary of events.

    1. Entered an unmanaged SellShort order, using iOrder entryShort.

    2. First execution of order. However, entryShort is still showing as null (entryShort == null returns as true, blue box in Output Window). The UNKNOWN entries are from OnOrderUpdate.

    3. entryShort == null turns false after the first execution (which is a PartFill) - red border

    4. Execution proceeds as normal until order is filled, or canceled.


    My question is why, or how, is #2 occuring? And how is it possible for an execution of the "entryShort" iOrder to happen, when entryShort == null?

    It's causing a lot of issues because I'm using (execution.order == entryShort) to determine the quantity of the stop order, which due to entryShort == null on the first execution, is no longer accurate. I didnt encounter this situation in NT7, so its a bit of headscratcher when transitioning my code to NT8.

    Any assistance is much appreciated.

    Code:
    protected override void OnBarUpdate()
    {[INDENT](bunch of code)
    
    if (entryShort==null)[/INDENT][INDENT]{[/INDENT][INDENT=2]CandleOutlineBrushes[0] = Brushes.DeepSkyBlue;
    Print(Time[0] + " Entered Entry Short Order");
    entryShort = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Limit, (int) entryShortQuantity, entryShortPriceWithOffset, 0, "", "Sell");[/INDENT][INDENT]
    }[/INDENT]
     
    }
    
    
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
    {[INDENT]if (order == entryShort)[/INDENT][INDENT=2]Print(Time[0] + " EntryShort: " + order);[/INDENT][INDENT]else if (order == entryLong)[/INDENT][INDENT=2]Print(Time[0] + " entryLong: " + order);[/INDENT][INDENT]else if (order == stopShort)[/INDENT][INDENT=2]Print(Time[0] + " stopShort: " + order);[/INDENT][INDENT]else if (order == stopLong)[/INDENT][INDENT=2]Print(Time[0] + " stopLong: " + order);[/INDENT][INDENT]else if (order == closeLong)[/INDENT][INDENT=2]Print(Time[0] + " closeLong: " + order);[/INDENT][INDENT]else if (order == closeShort)[/INDENT][INDENT=2]Print(Time[0] + " closeShort: " + order);[/INDENT][INDENT]else if (order == exitShort)[/INDENT][INDENT=2]Print(Time[0] + " exitShort: " + order);[/INDENT][INDENT]else if (order == exitLong)[/INDENT][INDENT=2]Print(Time[0] + " exitLong: " + order);[/INDENT][INDENT]else if (order == null)[/INDENT][INDENT=2]Print(Time[0] + " null: " + order);[/INDENT][INDENT]else[/INDENT][INDENT=2]Print(Time[0] + " UNKNOWN: " + order);[/INDENT]
     }
    
    protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
    {[INDENT]Print(Time[0] + " Execution: Is entryshort null: "+ (entryShort==null) + ", and : ");
    Print(Time[0] + " Execution ID: " + execution.Order);
    
    if (entryShort != null)[/INDENT][INDENT=2]Print(Time[0] + " entryShort IS NO LONGER NULL!!!!!!");[/INDENT][INDENT]
    
    if (execution.Order==entryShort)
    {[/INDENT][INDENT=2]stopShortQuantity += execution.Quantity;
    
    Print(Time[0] + " entryShort q: " + stopShortQuantity);[/INDENT][INDENT]}[/INDENT]
     }
    Attached Files

    #2
    Probably similar to problems mentioned here.

    Comment


      #3
      Hello nicbizz,

      Thank you for your reply.

      bltdavid is correct, you appear to be running into the same situation that the post he's linked is hitting - you're assigning the order in OnBarUpdate instead of OnOrderUpdate. I'd take a look at this example specifically:



      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        bltdavid and NinjaTrader_Kate

        i wasn't aware that particular area has changed. Thanks for the suggestion. Will look it up.

        -Nick

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        21 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        4 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X