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

OnOrderUpdate

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

    OnOrderUpdate

    My strategy uses multiple entries for an added array of four instruments. How can I differentiate the myEntryOrders for each individual case. Basically if my limit entry order is rejected then convert to market order for conceivably all four instruments if all the myEntryOrder1-4 limit orders are rejected. I use an IB connection. Help appreciated as the market moves often result in an order rejection. Thx



    {
    myEntryOrder = EnterShortLimit(0,true,SizeES-voladjustES,CurrentDayOHL(Opens[0]).CurrentOpen[0],"ES SHORT");
    SetStopLoss("ES SHORT", CalculationMode.Price, CurrentDayOHL(Opens[0]).CurrentOpen[0]), false);
    SetProfitTarget("ES SHORT", CalculationMode.Price, PriorDayOHLC(Closes[0]).PriorClose[0]+3);
    }


    {
    if (order.Name == "myEntryOrder" && orderState == OrderState.Filled)
    myEntryOrder = order;



    // Convert to market order if second limit order rejected
    if (myEntryOrder != null && myEntryOrder == order)
    {
    // Rejection handling
    if (order.OrderState == OrderState.Rejected)
    {
    myEntryOrder = EnterShort(0,SizeES-voladjustES,"ES SHORT MARKET");
    SetStopLoss("ES SHORT MARKET", CalculationMode.Price, 3000 + CurrentDayOHL(Opens[0]).CurrentOpen[0]), false);
    SetProfitTarget("ESSHORT MARKET", CalculationMode.Price, PriorDayOHLC(Closes[0]).PriorClose[0]+5);
    }
    }
    }





    #2
    Hello elliot5,

    Thanks for your post.

    Note that Set methods should be called when the strategy is flat, before the next entry. This ensures that the target and stop are not submitted with a previous level when the entry order comes back as filled.

    I would suggest using dictionaries to manage your entry, target and stop orders so you can differentiate them between each instrument. For example, a Dictionary<Instrument, Order> could be created to manage your entries and additional dictionaries can be created for targets and stops. Alternatively, you could create additional Order objects to manage each entry/target/stop.

    You can then follow the SampleOnOrderUpdate strategy, but you would null the Order object and then remove it from the dictionary if the order comes back as filled (in OnExecutionUpdate,) cancelled (in OnOrderUpdate,) or rejected (in OnOrderUpdate.)

    If the order gets rejected the order would be set to null, removed from the dictionary, and then a new entry order would be submitted for the new entry.

    I would also recommend following the SampleOnOrderUpdate approach to use Exit methods for your target and stop so you can direct

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      thank you for your prompt reply. so myEntryOrder is absolute and cannot be individually named myEntryOrder1 or myEntryOrder2? Regards

      Comment


        #4
        Hello elliot5,

        myEntryOrder is the name of an Order object created in the script. You can create additional Order objects to manage additional entries, or you could use a dictionary to manage the Orders. I.E. you can have myEntryOrder1 manage one instrument and create a myEntryOrder2 that manages another instrument. You could also name these to myEntryOrderES/myEntryOrderCL if you wish.

        Please let me know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        41 views
        0 likes
        Last Post futtrader  
        Started by Option Whisperer, Today, 09:55 AM
        1 response
        11 views
        0 likes
        Last Post bltdavid  
        Started by port119, Today, 02:43 PM
        0 responses
        7 views
        0 likes
        Last Post port119
        by port119
         
        Started by Philippe56140, Today, 02:35 PM
        0 responses
        7 views
        0 likes
        Last Post Philippe56140  
        Started by 00nevest, Today, 02:27 PM
        0 responses
        7 views
        0 likes
        Last Post 00nevest  
        Working...
        X