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

How to know a Pending Fill

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

    How to know a Pending Fill

    My Strategy acts like a server to receive trade signals from one or more indicators....so...it needs to know if there is already an order that is submitted but has not been filled.

    There is no Pending Fill OrderState...from the documentation what I have is this

    OrderState.Initialized
    OrderState.Submitted
    OrderState.Accepted
    OrderState.TriggerPending
    OrderState.Working
    OrderState.ChangePending
    OrderState.ChangeSubmitted
    OrderState.CancelPending
    OrderState.CancelSubmitted
    OrderState.Cancelled
    OrderState.Rejected
    OrderState.PartFilled
    OrderState.Filled
    OrderState.Unknown

    so here is what I test to give me a pending order
    if (ThisOrder_1.OrderState == OrderState.Initialized ||
    ThisOrder_1.OrderState == OrderState.Submitted ||
    ThisOrder_1.OrderState == OrderState.Accepted ||
    ThisOrder_1.OrderState == OrderState.TriggerPending ||
    ThisOrder_1.OrderState == OrderState.Working ||
    ThisOrder_1.OrderState == OrderState.Unknown)

    would this be correct to derive a "pending fill" status?

    or, is there a better way to do this??

    Thanks

    #2
    Hello vantojo,

    If the order is pending a fill, this means that it is OrderState.Working or OrderState.Accepted. Once the order fills, the brokerage will send back OrderState.Filled.

    To know the order is closed it will have an an OrderState of OrderState.Filled, OrderState.Cancelled, or OrderState.Rejected.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      the other ones in my list aren't relevant?

      Comment


        #4
        Hello vantojo,

        The other states in the list would not be relevant to an order that is working and waiting for fill. This would be OrderState.Working and OrderState.Accepted.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ok, thanks

          Comment


            #6
            Hi Chelsea,

            I'm trying to build a strategy to auto-manage exiting manually placed orders.

            What I'd like to achieve is moving the Exit order (a Limit Order using the SubmitOrderUnmanaged() method) on those conditions:
            if the Limit Order (Exit Order) is not yet filled/can still be changed, and the Market improves in profit,
            then move the Limit order (Exit Order) according to specified value (10 ticks in below example, from 1110 to 1120)






            How can I check that the Limit Order can still be changed?


            For example:
            At Time1:
            Position.AveragePrice = 1110
            Limit Order/Exit Order = 1100
            At Time2:

            If
            Market Price = 1140
            New Limit Order/Exit Order = 1120

            Then
            ChangeOrder(myNewlimitOrder, myNewlimitOrder.Quantity, 0, (Position.AveragePrice + (10 * TickSize)));






            What do I substitute the '???' with in below code?

            myNewlimitOrder.OrderState == OrderState.???

            Which one of the following is the best one for my case?

            OrderState.Initialized
            OrderState.Submitted
            OrderState.Accepted
            OrderState.TriggerPending
            OrderState.Working
            OrderState.ChangePending
            OrderState.ChangeSubmitted
            OrderState.CancelPending
            OrderState.CancelSubmitted
            OrderState.Cancelled
            OrderState.Rejected
            OrderState.PartFilled
            OrderState.Filled
            OrderState.Unknown
            Last edited by Cormick; 07-18-2021, 09:52 AM.

            Comment


              #7
              Hello Cormick,

              If the <order>.OrderState is OrderState.Working, .Accepted, .Submitted, the order can be changed with a change request.

              Below is a link to ProfitChaseStopTrailUnmanagedExample_NT8, an example of moving stops in an unmanaged script.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello Cormick,

                If the <order>.OrderState is OrderState.Working, .Accepted, .Submitted, the order can be changed with a change request.

                Below is a link to ProfitChaseStopTrailUnmanagedExample_NT8, an example of moving stops in an unmanaged script.
                https://ninjatrader.com/support/foru...269#post802269
                Hi Chelsea,

                Thanks a lot for the great sample.
                I'm learning a lot from it!

                I noticed a probable copy-paste typo line 215:

                Should it not be StopLossDistance instead of ProfitTargetDistance?

                They are the same value (10) in State.SetDefaults, but if we want different ones do we need to change it?

                Click image for larger version  Name:	vmplayer_3ZbbTYc8qV.png Views:	0 Size:	650.4 KB ID:	1166183
                Attached Files

                Comment


                  #9
                  Chelsea,

                  Also, why do you need the AddDataSeries(BarsPeriodType.Tick, 1); line 68 ?

                  Click image for larger version

Name:	vmplayer_CNNWuXkObO.png
Views:	190
Size:	347.7 KB
ID:	1166194
                  Attached Files

                  Comment


                    #10
                    Another question about the StopLoss back movement prevention.

                    I've tested your sample as is:

                    Demo Video:

                    Timestamps:
                    1:12
                    11:12


                    How do you achieve in the code getting the StopLoss to not move back after it triggers and progresses with the Profits?

                    I mean, how do you 'lock' the StopLoss and prevent it from getting back from its progresses move?


                    For example, a 20 ticks stop:


                    At Time0
                    Long Entry = 1.00
                    Stop loss = 0.80
                    At Time1
                    Price = 1.10
                    Stop loss = 0.90

                    At Time2
                    Price = 1.05
                    Stop loss = 0.90 (not 0.85)

                    How to achieve the prevention of the stop moving back to 0.85, and it staying at 0.90?

                    How to do it the simplest way?

                    At Time3
                    Price = 1.09
                    Stop loss = 0.90 (not 0.89)


                    At Time4
                    Price = 1.13
                    Stop loss = 0.93
                    (etc.)



                    From your code lines 210-217:

                    // trigger the trail action when the current price is further than the set distance to the stop loss
                    if (TrailStopLoss &&
                    stopLoss != null && (stopLoss.OrderState == OrderState.Accepted || stopLoss.OrderState == OrderState.Working) &&
                    Close[0] > currentSlPrice + StopLossDistance * tickSizeSecondary)
                    {
                    currentSlPrice = Close[0] - StopLossDistance * tickSizeSecondary;
                    ChangeOrder(stopLoss, entryOrder.Filled, 0, currentSlPrice);
                    }

                    Full Code:


                    I can understand the Stop code is 'allowed to' move back.

                    But it seems it is locked somehow when testing it (Demo Video above).

                    How is that so?



                    Thanks a lot!
                    Last edited by Cormick; 08-03-2021, 05:37 AM.

                    Comment


                      #11
                      Hello Cormick,

                      215 was indeed a mistake, thanks for pointing this out. I've updated the original post.

                      AddDataSeries() is used to add a 1 tick series for historical order accuracy and intra-bar events, such as preventing new orders after the exit on session close seconds triggers until the end of the session.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chelsea,

                        Thanks for the update and the details about the AddDataSeries().

                        Have you had the opportunity to check your code for the locking feature mentionned in post # 10 (https://ninjatrader.com/support/foru...07#post1166207)?

                        Any pointers or other sample/documentation reference you used?

                        I still can't understand how you manage to get it set?

                        Thanks for your next illustrations.
                        Last edited by Cormick; 08-03-2021, 11:48 AM.

                        Comment


                          #13
                          Hello Cormick,

                          You can decide not to set a new trigger price once the order is moved once, if you do not want to continue trailing and just want a single breakeven movement.
                          You could also decide to use a bool. Once the movement occurs, set the bool to true. In the condition that triggers the movement require the bool to be false.
                          You could use an integer as a counter if you want a specific number of movements. Increment the counter on each movement, and in the condition that triggers the movement require the counter int to be less than, a number for how many movements you want.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chelsea,

                            Thanks for the steps. I'd try your recommendation.
                            However, I'm not sure it's getting what I'm looking to achieve.

                            I just need the stop to not return backwards.

                            You can decide not to set a new trigger price once the order is moved once, if you do not want to continue trailing and just want a single breakeven movement.
                            No, I need the stop to trail (unlimited numbers same as you code), not just a breakeven (on move only).

                            You could also decide to use a bool. Once the movement occurs, set the bool to true. In the condition that triggers the movement require the bool to be false.
                            The use is to get the stop to trail each forward (profit increase) move, and adjust accordingly, while not dis-adjusting (decrease on profit decrease) on move backward.

                            You could use an integer as a counter if you want a specific number of movements. Increment the counter on each movement, and in the condition that triggers the movement require the counter int to be less than, a number for how many movements you want.
                            No need of counter. The stop simply needs to follow the Close[0] move as with your code, with no preset number of moves.
                            The only difference from your code is that when 'Close[0] > currentSlPrice + StopLossDistance * tickSizeSecondary' regresses (after the stop has made a 1st move forward)
                            (c.f. from Time1 (Price = 1.10) to Time2 (Price = 1.05) in post #10 above
                            (https://ninjatrader.com/support/foru...07#post1166207))
                            the Stop must not regress— it must stay locked at the last price movement forward (at Time2 from post #10 above: Stop loss = 0.90 (not 0.85)).
                            Then only forward movement can be allowed (at Time3 Stop loss = 0.90 (not 0.89) and Time4 Stop loss = 0.93 from post #10 above).

                            Does you code already achieve that same result? It seems to do so, but I can't see how/why from your code.
                            Lines 210-217 from your code seem to be the only lines that manage the stop movement.
                            And those lines seem not to include 'strict locking forward' stop movement.

                            If there is already the needed 'strict locking forward' stop movement logic elsewhere in your code, could you refer me to it please?
                            If not, and the code achieves the same result in another way, could you tell me please how it does so?
                            If the code does not achieve that aim at all as is, can you please refer me to another sample that does or related documentation?


                            If my examples or stated aim are not clear enough please let me know and I'll do a better job explaining with your confusion pointers.
                            Also, you can illustrate Time0 1 2 3 4 with actual time references if that makes it clearer.

                            For example:
                            Time0 = 9:00 AM
                            Time1 = 9:09 AM
                            Time2 = 9:18 AM
                            Time3 = 9:27 AM
                            Time4 = 9:36 AM


                            Thanks for your next illustrations!

                            Comment


                              #15
                              Hello Cormick,

                              I'm not certain I am understanding, the example I provided never moves the stop down and never moves the limit up. These only move toward the current price, never away.

                              The currentSlPrice is only ever set to Close[0] - StopLossDistance * tickSizeSecondary when the close is greater than currentSlPrice + StopLossDistance * tickSizeSecondary. This wouldn't allow for a smaller value.

                              There is no locks or locking. Only logic that chooses a new stop price.

                              Can you clarify the behavior in the example script that moves backwards?
                              Last edited by NinjaTrader_ChelseaB; 08-03-2021, 02:20 PM.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by briansaul, Today, 05:31 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post briansaul  
                              Started by fwendolynlpxz, Today, 05:19 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post fwendolynlpxz  
                              Started by traderqz, Yesterday, 12:06 AM
                              11 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by PaulMohn, Today, 03:49 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post PaulMohn  
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Working...
                              X