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

NT8 GetRealtimeOrder()

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

    NT8 GetRealtimeOrder()

    Hello.

    GetRealtimeOrder() returns null for Market order with state Filled in transition from historical to market replay data.
    I use unmanaged method to handle orders.

    PHP Code:
                else if (State == State.Realtime)
                {
                    
    positionA.Sync();
                    
    positionB.Sync();
                }

    ...

    // position class

            
    public void Sync()
            {
                
    SyncOrders(entry);
                
    SyncOrders(stoploss);
                
    SyncOrders(takeprofit);
            }

            private 
    void SyncOrders(Order[] orders)
            {
                for (
    int i 0orders.Count(); i++)
                    if (
    orders[i] != null)
                    {
                        
    orders[i] = Strategy.GetRealtimeOrder(orders[i]);
                    }
            } 

    #2
    Hello ren37,

    Thank you for your post.

    As Strategy.GetRealtimeOrder() is undocumented there is no expected behavior. I will follow up with development to see if they have details on this.

    Can you provide your full code? You can send the code over to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H - 1580147' in the subject line.

    Comment


      #3
      Here is help on GetReal...()

      https://ninjatrader.com/support/help...t_strategy.htm

      Comment


        #4
        You would only need to call GetRealtimeOrder order if you intended to cancel or change the price of an order. The market order in your scenario is considered terminal since it was filled. Since terminal orders cannot be managed, the GetRealtimeOrder() method will return null if the order doesn't exist. I updated the documentation to better reflect behavior.

        Returns a real-time order reference associated with the historical order object. If no associated order exists (i.e. OrderState is Filled, Canceled, Rejected, Unknown), a null value returns

        MatthewNinjaTrader Product Management

        Comment


          #5
          Hello Patrick

          Yes, you are right. Think I should cancel filled historical orders in transition to real data. Ty.

          Comment


            #6
            Can't get how to close historical order.
            CancelOrder() does nothing.
            Position.Close() gen error message: no market data to drive simulation engine. affected order: Sell 5 Market.

            So after transition from historical data I have some position and this affects on strategy logic.
            Last edited by ren37; 09-29-2016, 03:07 AM.

            Comment


              #7
              Hi all,

              It's what i'm used on NT7, but it's surly work too on NT8:

              On my OnUpdate methode, i have this code:

              // Test if historical is processed
              if (Historical)
              {
              if (CurrentBar == LeadIndicator.Bars.Count - 1)
              {
              Console.Beep(1200, 100);
              (this as IOrdersRequest).ClosePosition(null);
              (this as IOrdersRequest).CancelOrder(null);
              }
              }

              So when i'm process the ultimate bar on historical, i'm cancel and close all orders of my strategy, so i'm can start real-time process with flat position.

              I'm not knwon if NT8 have a LeadIndicator on strategy, but you surely have a way to known how many bars historical have.
              Last edited by Twanaar; 09-29-2016, 06:50 AM.

              Comment


                #8
                Twanaar

                After some invastigations I think "Exit on session close" option checked does the same thing.
                Historical data ends on session end. Or may be in some situations this is not correct?

                And I corrected code thanks to Matthew quote to handle transition to Market replay data to debug strategy logic on replay.

                PHP Code:
                        private void SyncOrders(Order[] orders)
                        {
                            for (
                int i 0orders.Count(); i++)
                                if (
                orders[i] != null)
                                {
                                    if (
                orders[i].OrderType != OrderType.Market && orders[i].OrderState != OrderState.Filled)
                                        
                orders[i] = Strategy.GetRealtimeOrder(orders[i]);
                                }
                        } 
                Last edited by ren37; 09-29-2016, 11:52 AM.

                Comment


                  #9
                  >After some invastigations I think "Exit on session close" option checked does the same thing.
                  >Historical data ends on session end. Or may be in some situations this is not correct?

                  It's correct, but if you want run historical test then continue en reel time, and you don't want your real time strategy close it's order en session close, you need to do it in code for historical.

                  Comment


                    #10
                    Hi NT support!

                    I need close all orders for my strategy on State == State.Realtime.
                    I use SubmitOrderUnmanaged() to open orders.
                    Also I use CancelOrder() for all orders on State == State.Realtime. But it does not make Position.MarketPosition == MarketPosition.Flat so strategy logic goes wrong on live data. Also I see Position quantity > 0 in Startegies tab. But it cancels working orders. How can I cancel filled orders?

                    I tried to use Position.Close() but it hides all markers from chart. Position becomes flat but I see filled historical order in chart trader and get my strategy disabled.

                    I need flatten strategy position on State == State.Realtime.
                    Last edited by ren37; 10-06-2016, 09:04 AM.

                    Comment


                      #11
                      Originally posted by ren37 View Post
                      Hi NT support!

                      I need close all orders for my strategy on State == State.Realtime.
                      I use SubmitOrderUnmanaged() to open orders.
                      Also I use CancelOrder() for all orders on State == State.Realtime. But it does not make Position.MarketPosition == MarketPosition.Flat so strategy logic goes wrong on live data. Also I see Position quantity > 0 in Startegies tab. But it cancels working orders. How can I cancel filled orders?

                      I tried to use Position.Close() but it hides all markers from chart. Position becomes flat but I see filled historical order in chart trader and get my strategy disabled.

                      I need flatten all on State == State.Realtime.
                      Position.Close() will not work on a historical position, using this method is not encouraged or documented.

                      You also cannot "Cancel" and order that is already filled. You can only cancel an order that is active/working

                      If you have an open position, you need to submit a reconciliatory market order in the oppose direction to the position.
                      MatthewNinjaTrader Product Management

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      22 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      45 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      21 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      181 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X