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

Difference between execution.Order.Filled and Position.Quantity

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

    Difference between execution.Order.Filled and Position.Quantity

    Hi

    I trade a strategy with 1 future, however, i would like to increase the position.

    At the moment, the quantity on the ExitLongStop on the protected override void OnExecution(IExecution execution) is execution.Order.Filled

    Same on the ExitLongLimit.

    My question is : if the strategy is long and when the target price is traded, i have only few future traded for me (for example only 3 futures on 10 is executed; so i'm still long of 7), what's going on the ExitLongStop quantity ? is it turn from 10 to 7 or is it stay at 10 (the initial stop quantity) ?

    Is is better to use Position.Quantity on the ExitLongStop and the ExitLongLimit ?

    Regards
    Thomas

    #2
    Hello Thomas,

    My recommendation would be to use unique signal names for the entries and have separate orders for the exits with the from entry signals of those entries.


    However, if this is not your plan, you could use the <order>.Filled quantity in OnOrderUpdate / OnExecutionUpdate or the position.Quantity in OnPositionUpdate.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea.

      Thx for your answer but i'm on NT 7 not on NT 8.

      Can you help on NT 7 ?

      Regards.

      Comment


        #4
        Hello Thomas,

        execution.Order.Filled, represents the number of contracts filled so far by the order that is currently executing in OnExecution.

        Position.Quantity represents the total size of the strategy position.

        If the strategy only enters once in each direction, execution.Order.Filled would essentially be the same as Position.Quantity.

        If you are updating your Exit orders in OnExecution following Position.Quantity or, execution.Order.Filled, the exits will account for the quantities of the position as it grows.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thx for the answer,

          i understant that the exits will account for the quantities of the position as it grows.

          However, my question is on the other way. When the quantity of the ExitLongLimit or ExitShortLimit start to be executed (so the quantity position decrease), is the stop quantity is automatically adjusted on the OnExecution(IExecution execution) ?

          Regards.
          Thomas

          Comment


            #6
            Hello Thomas,

            This would be handled by the Managed Approach. As the position size decreases, NinjaTrader will modify exit orders so they do not exceed the strategy's position size.

            OnExecution would trigger the submission of the target and stop Exit orders and change their quantity as the entry fills. Then, when the stop/target fill, the Managed Approach would adjust the quantities of those Exit orders as the position closes.
            JimNinjaTrader Customer Service

            Comment


              #7
              ok understood

              thx for the reply

              Comment


                #8
                Hi Jim,

                I come back to you. Today i inscreased my position to test what you say on the Managed Approach. And i'm sorry but my stop quantity is not updating, see my print screen in really time.

                I was long quantity 2, the target has been hit but i was part filled of 1 quantity and you can see the stop quantity remained at 2 (the Managed Approached do not update the stop quantity).

                Not a good idea if the market reverse and hit my stop, i'll be short of 1.

                Can you help ?

                Thx
                Thomas
                Attached Files

                Comment


                  #9
                  Hello Thomas,

                  We may need to get down to a small example that can show the behavior with Market Replay to comment further.

                  There is a documented limitation that affects NinjaTrader 7 and NinjaTrader 8 involving non-OCO Exit orders in the event of a partial fill. I can't be sure if this is the case without a small example and steps to watch the issue happen.

                  As a workaround NinjaTrader 8, we have suggested to force amending the stop loss in OnExecutionUpdate whenever an exit execution (executuion.Name does not reflect one of the entries) was seen. For example:

                  Code:
                  protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                  {
                      if (execution.Name != "MyEntryShort" && Position.MarketPosition == MarketPosition.Short)
                          stopOrder = ExitShortStopMarket(0, true, Position.Quantity, EMA(50)[0], "MyStop", "MyEntryShort");
                      ...
                  You could try our suggested workaround, but if the issue is not resolved, we need to work on observing the issue first hand to assist further. (Preferably, with a modification of the SampleOnOrderUpdate strategy)

                  This could look like:

                  Code:
                  protected override void OnExecution(IExecution execution)
                  {
                      ...
                  
                      if (execution.Name != "MyEntryShort" && Position.MarketPosition == MarketPosition.Short)
                          stopOrder = ExitShortStop(0, true, Position.Quantity, EMA(50)[0], "MyStop", "MyEntryShort");
                  }
                  If we are still stuck at this point , could you modify the SampleOnOrderUpdate strategy so it can demonstrate the behavior and reach me by email? This way we can work together towards a solution for your specific case.

                  You may reach me at scriptingsupport [at] ninjatrader [dot] com with the text "Attn Jim 3494054" Please also include a link to this thread.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Jim

                    first, thank for you help, is your first sample "OnExecutionUpdate" is available on NT7 or only on NT8 ?

                    Regards
                    Thomas

                    Comment


                      #11
                      Hello Thomas,

                      The first snippet with OnExecutionUpdate would be NinjaTrader 8 NinjaScript.

                      The second snippet with OnExecution would be the same code implemented in NinjaTrader 7.

                      JimNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      17 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,786 views
                      0 likes
                      Last Post Leafcutter  
                      Started by poplagelu, Today, 05:00 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post poplagelu  
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,407 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Working...
                      X