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

Question about current Order List

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

    Question about current Order List

    I would like to ask about the handling of order list. I found some related threads, one, two. Strategy should maintain an order list by themselves under the callback function onOrderUpdate().

    Here is my possible situation.
    1. Strategy is running
    2. Send a limit order to broker
    3. NT8 is offline
    4. Order may be filled or may be still working only
    5. NT8 is online
    6. Strategy may need to know the current order list
    Is there a way to get a current order list?

    Thank you very much.

    #2
    Hi Sulfred, thanks for your post.

    See the documentation on connection loss settings here:



    That group of settings handles how the strategy should continue if there is a connection loss.

    If the strategy is disabled and you need to start it back up while your account still has an open position, you can use the Adopt Account Position startup behavior and use the GetRealTimeOrder() method to get a reference to an order that was submitted on the historical data. Your strategy must have IsAdoptAccountPositionAware = true; in State.SetDefaults of the strategy to use this startup behavior.

    Please let me know if I can assist any further.

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      I am sorry, I don't get it. The following implementation is my guess, could you please give me a suggestion?

      The situation:
      1. Strategy is running, and I set Recalculate in the connection loss handling.
      2. Send a limit order to broker
      3. NT8 is offline
      4. Order may be filled or may be still working only
      5. NT8 is online
      6. Strategy may need to know the current order list
      From step 1 - 2
      Code:
      private Dictionary<string, Cbi.Order> myOrderList;
      OnBarUpdate()
      {
          SetProfitTarget("order_001", CalculationMode.Price, tpPrice);
          SetStopLoss("order_001", CalculationMode.Price, slPrice, false);
          EnterLong(1, "order_001");
      }
      
      OnOrderUpdate(Cbi.Order order...)
      {
          myOrderList["order_001"] = order;
      }
      From step 3 - 4. Suppose my order is TP. So the EnterLong order is filled, ProfitTarget order is filled, StopLoss order is cancel.
      After step 5. Suppose I do.
      Code:
      OnStateChange()
      {
          if (state == State.Realtime)
          {
              foreach (KeyValuePair<string, Cbi.Order> kvp in myOrderList)
              {
                 kvp.Value = GetRealtimeOrder(kvp.Value);
              }
          }
      }
      At this moment, is that those orders in myOrderList up to date ? Thank you very much.
      Last edited by Sulfred; 04-12-2020, 02:15 AM.

      Comment


        #4
        Hi Sulfred thanks for your reply.

        If the strategy is stopped, the orders that were made in real-time are now historical so GetRealTimeOrder will need to be used to get a reference to the live active order. Your code can be tested in the Sim101 account by having a strategy running with resting orders>force a disconnect using a tool like TCPView to close the connection. If you close the connection with your strategy running you can test how it behaves when you start it up from being disabled, or recovering from a disconnection.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,607 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        16 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X