• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 superkolleech, Today, 12:46 AM
        1 response
        11 views
        0 likes
        Last Post MojoJojo  
        Started by davidwade, Today, 02:51 AM
        0 responses
        3 views
        0 likes
        Last Post davidwade  
        Started by aviat72, 04-26-2020, 09:41 PM
        10 responses
        92 views
        0 likes
        Last Post kissandfly  
        Started by healthooa, Today, 01:28 AM
        0 responses
        7 views
        0 likes
        Last Post healthooa  
        Started by harjinderjit, Yesterday, 08:24 PM
        0 responses
        20 views
        0 likes
        Last Post harjinderjit  
        Working...
        X