Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Pending Logic

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

    Order Pending Logic

    Guys

    I have been thoroughly testing today. Everything is going reasonable well.

    I have encountered the following problem:

    An order is submitted from inside OnBarUpdate.

    It can take a second to go from accepted->working->filled.

    In that time, a new TICK arrived. OnBarUpdate is retriggered and a new order is submitted. Like I said this happens in the space between accepted and filled.

    I have been looking in the reference for a function/method that gives something along the lines of: OrderState that returns Working/Accepted etc... does this exist somewhere?

    Also: I am seeing a lot of State=PendingChange. What causes this?

    #2
    imported post

    Oli,

    Would you mind eloborating on your initial concern? I can't make out what behaviour you are seeing that you are not expecting.

    There are not methods in the NinjaScript layer that return order status. In concept, this should not be required since the NinjaScript layer takes care of managing order submission, re-submission and cancellation.

    PendingChange is caused when an order is changed. The following code sample would do this if called on the close of each bar.


    EnterLongLimit(Low[0]);

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Hey Ray,

      sorry for the lack of clarity. I'll try again:

      When an order is submiited from inside OnBarUpdate (EnterLongLimit say), what happens next? Is the script somehow halted at that point until the order filled, or does the next line of code execute immediately?

      Comment


        #4
        imported post

        Processing is not halted, the next line of code is executed. The only time code is not executed is when an exception is trapped at which time the strategy stops running and an error is logged in the Control Center log tab.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          OK - good.

          So then When the EnterLongLimit line is execute, an order is sent. This order takes time to go from PendingSubmit->Accepted->Working->Filled, right? This isn't at all instantaneous is it?

          Comment


            #6
            imported post

            Correct, it is not instantaneous. There is always a delay with live account orders and in the Sim101 account.

            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              OK - great.

              So this is where there is a problem.

              EnterLongLimit executes.

              Order is Pending.

              OnBarUpdate method finishes = waiting for next TICK.

              Order is Accepted.

              New TICK arrives.

              Position.MarketPosition == MarketPosition.Flat

              Order is Working.

              EnterLongLimit executes a second time.

              Order is filled just before new order is pending.

              I now have TWO, instead of ONE, orders off the same trade signal.

              I MUST have a logic switch that says something like:

              Position.MarketPosition == MarketPosition.PENDING

              PENDING is not Flat.

              This is the problem...

              Comment


                #8
                imported post

                here is a screen shot of two exact same order executing within a half second of one another:




                Attached Files

                Comment


                  #9
                  imported post

                  When run your strategy,

                  Set your "Entries per direction" to a value of 1 if you only ever want to have one of the orders executed.

                  Ray
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    imported post

                    Ray,

                    thanks for the suggestion but it is not a solution. A good stratgey never simply runs long then short then long then short. In theory my strategies can go LONG an infinite number of time without ever being short.

                    What does that then mean - my Strat only trades once? This is limited and not workable unfortunately.

                    Comment


                      #11
                      imported post

                      Oli,

                      Doyou want to golong multiple times on the same trade signal?

                      If no, then provide a unique signal name for each trade signal in the long direction and set the "Entries per direction" to a value of 1, set "Entry handling" to Unique Entries.

                      If yes, but you only want to enter while an order is NOT pending, then you have to get creative and add some logic to check for pending conditions.

                      Ray
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        imported post

                        Thanks Ray,

                        I'll have a closer look at the handling = unique side of the coin. That soundspromising.I do not want to enter multiple trades off of one signal. But I do want a long to be able to follow a long...

                        "add some logic to check for pending conditions."

                        I have looked for a method that will access the State=[Pending*, Accepted, Working, Filled] but can't see any...and I think you said below that there are none.

                        Comment


                          #13
                          imported post

                          Check for pending means adding your own variables to track when an order is submitted, cancelled, filled by checking the market position etc... That's what I meant by creative.

                          Ray
                          RayNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by f.saeidi, Today, 08:01 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post f.saeidi  
                          Started by Rapine Heihei, Today, 07:51 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Rapine Heihei  
                          Started by frslvr, 04-11-2024, 07:26 AM
                          5 responses
                          96 views
                          1 like
                          Last Post caryc123  
                          Started by algospoke, 04-17-2024, 06:40 PM
                          6 responses
                          49 views
                          0 likes
                          Last Post algospoke  
                          Started by arvidvanstaey, Today, 02:19 PM
                          4 responses
                          11 views
                          0 likes
                          Last Post arvidvanstaey  
                          Working...
                          X