Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Average Fill is miles away from CLOSE[0]

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

    Average Fill is miles away from CLOSE[0]

    Hi All,

    I have been getting some fills using SubmitOrder that are far away from the Market Price.

    Is there a way in NinjaScript to keep the fills within certain limits?


    C

    #2
    Hello cocopod,

    What type of order are you submitting? (Market, Limit, Stop Market, Stop Limit)

    Are these real-time or historical trades?

    If real time, what bar type are you using?

    If historical, what bar type are you using and what Fill Type is select?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea... Sorry for the delay in responding to your prompt reply.

      longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, 1, tickPrice +5 * TickSize, tickPrice +5 * TickSize, String.Format("Gold" + qty), "long limit entry");

      Currently it is Historical data and the Approach is Unmanaged.with CalculateOnBarClose = false;

      Comment


        #4
        Hi cocopod,

        What Fill Type are you using in the strategy parameters?


        Likely the Fill Type is set to Default and the limit in the stop limit orders are being filled at the limit price they are submitted at.

        Use the Liberal fill type if you want the order to fill at the high or low of the bar instead of at the limit price.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi chelsea,

          Didn't know about that Liberal fill parameter

          One slight problem however is that this occurred when the marked spiked. Even on a 1 second chart the bar is 50 ticks long.

          Is there some way to address this?

          C

          Comment


            #6
            Hi cocopod,

            You can modify your historical data in the Historical Data Manager if you want to historically remove the spike.
            • Tools -> Historical Data Manager... -> Edit
            • Expand the Instrument -> data type -> interval type -> date
            • On the right in the grid, double click the value you want to edit -> type a new value
            • Click the Save button
            • Restart NinjaTrader so the chart can take the change
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              That will defeat the object as I wish to focus on the spike. Would it be possible to have the bars in Milliseconds? Or have something like CLOSE[0} + 3?

              C

              Comment


                #8
                Hello cocopod,

                You can print the millisecond of the time of the bar with:

                Print(Time[0].ToString("MM-dd-yy h:mm:ss:ffff"));


                I'm not clear on what you are trying to do.

                When you say "Is there some way to address this?" are you not asking how to remove the spike?

                If not, what are you trying to do to address this?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Consider the scenario - I have a bracket trade around a consolidation. The market spikes through one side of my bracket. Instead however of giving me a fill at the bracket position of 10, I get filled at 26 and I'm not particularly happy with that.

                  C

                  Comment


                    #10
                    Hi cocopod,

                    If you are using a limit order or stop limit order the order will fill at the limit price or better in real-time.

                    If you are backtesting, the order will fill at the limit price.

                    If you want the fill to be within the bar, use the Liberal fill type, or place the limit at the price you want it to fill at.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Limit orders are not guaranteed by NinjaTrader!!!!!!!!!!!!!!!!

                      This is conclusive proof that the system is in error.
                      Limit orders are not guaranteed by NinjaTrader!!!!!!!!!!!!!!!!
                      Using replay data we are guaranteed fills at the LIMIT price

                      I shorted the marked using an Unmanaged Stragegy. I then created a StopLoss in the OnExecution event that effectively occurs on the same tick

                      The first line below shows that the limit price is 1156.3 ( nothing to do with average fill )
                      the 2nd line shows that we are filled at 1156.4

                      "OnExecutiion" is then called on the same tick - which should be 1156.3 but is now listed at 1159. Basically I get filled at 1156.3 even though the market is 1159. This should not happen!!!!!!!


                      *************** Pendng order ****************

                      19/11/2014 21:49:23|1|32|Order='872642d764c3484f9fc9a53691097 65a/Replay101' Name='Short limit entry' New state=Working Instrument='GC 12-14' Action=SellShort Limit price=1156.3 Stop price=1156.3 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''


                      ***************** Fill of short entry ******************

                      19/11/2014 21:49:23|1|32|Order='872642d764c3484f9fc9a53691097 65a/Replay101' Name='Short limit entry' New state=Filled Instrument='GC 12-14' Action=SellShort Limit price=1156.3 Stop price=1156.3 Quantity=1 Type=StopLimit Filled=1 Fill price=1156.4 Error=NoError Native error=''


                      ********* This sis abracket trade so OCO cancells other side of Bracket ************

                      19/11/2014 21:49:23|1|32|Order='4c56d15d3d1a4af9b43cd10297bc8 54e/Replay101' Name='long limit entry' New state=PendingCancel Instrument='GC 12-14' Action=Buy Limit price=1160.9 Stop price=1160.9 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
                      19/11/2014 21:49:23|1|32|Order='4c56d15d3d1a4af9b43cd10297bc8 54e/Replay101' Name='long limit entry' New state=Cancelled Instrument='GC 12-14' Action=Buy Limit price=1160.9 Stop price=1160.9 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
                      19/11/2014 21:49:23|1|16|Execution='4d7d214508694eae8f878f95b 65d6ba1' Instrument='GC 12-14' Account='Replay101' Exchange=Default Price=1156.4 Quantity=1 Market position=Short Operation=Insert Order='872642d764c3484f9fc9a5369109765a' Time='07/11/2014 13:30:02'
                      19/11/2014 21:49:23|1|64|Instrument='GC 12-14' Account='Replay101' Avg price=1156.4 Quantity=1 Market position=Short Operation=Insert Currency=Unknown

                      *********** Stop is issued at a HIGHER price than fill ****************
                      19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=PendingSubmit Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
                      19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=Accepted Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''



                      ***************** The next tick the Stop loss is filled at CONSIDERABLE loss *******

                      19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=Working Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
                      19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=Filled Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=1 Fill price=1159 Error=NoError Native error=''

                      19/11/2014 21:49:23|1|16|Execution='ea930cfe067041e28c2c1dff7 41fec61' Instrument='GC 12-14' Account='Replay101' Exchange=Default Price=1159 Quantity=1 Market position=Long Operation=Insert Order='4430313a89b4404da86fbda7d2e919b7' Time='07/11/2014 13:30:02'
                      19/11/2014 21:49:23|1|64|Instrument='GC 12-14' Account='Replay101' Avg price=1159 Quantity=0 Market position=Short Operation=Remove Currency=Unknown

                      Comment


                        #12
                        Hi cocopod,

                        I am having difficulty following this.

                        Are you saying that everything works fine in replay but is not working the same historically?

                        There is no intra-bar data historically, either the order will fill at the limit price or will fill at the high or low of the bar its on depending on the fill type you have selected.

                        What fill type have you selected?


                        Also, your output is for the Market Replay, where is the output from your historical backtest in the Strategy Analyzer?


                        Also, I am seeing what you are intending to prove with your output even with the Market Replay.

                        Stop loss has a limit price of 1159
                        19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=Accepted Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''

                        Stop fills at 1159
                        19/11/2014 21:49:23|1|16|Execution='ea930cfe067041e28c2c1dff7 41fec61' Instrument='GC 12-14' Account='Replay101' Exchange=Default Price=1159 Quantity=1 Market position=Long Operation=Insert Order='4430313a89b4404da86fbda7d2e919b7' Time='07/11/2014 13:30:02'

                        What is wrong with that?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Ahhh Chelsea_B!! Knew you would come to my aid...

                          Firstly Strategy Analyzer?... Never heard of it. I am using Relay and then running on live data in SIM.

                          Whats wrong with that?? Well the fact that Iv shorted at 1156.3 and the market is at 1159 on the same means that Iv lost considerably.
                          ****************** I go short here *************
                          19/11/2014 21:49:23|1|32|Order='872642d764c3484f9fc9a53691097 65a/Replay101' Name='Short limit entry' New state=Filled Instrument='GC 12-14' Action=SellShort Limit price=1156.3 Stop price=1156.3 Quantity=1 Type=StopLimit Filled=1 Fill price=1156.4 Error=NoError Native error=''


                          Then on the same tick
                          I have a pending Stop loss which amazingly has a higher price!!! (1159 )

                          *********** Stop is issued at a HIGHER price than fill ****************
                          19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=PendingSubmit Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''
                          19/11/2014 21:49:23|1|32|Order='4430313a89b4404da86fbda7d2e91 9b7/Replay101' Name='Stop loss to protect short' New state=Accepted Instrument='GC 12-14' Action=BuyToCover Limit price=1159 Stop price=1159 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=NoError Native error=''

                          Comment


                            #14
                            Hi cocopod,

                            In post #2 I have asked if these were historical trades or real time trades. You mentioned in #3 these are historical trades.

                            That would mean that these trades are not made on the market replay, so I made the assumption you were doing a backtest in the Strategy Analyzer. (File -> New -> Strategy Analyzer)

                            From what it looks like, these are real-time trades made with the Market Analyzer.

                            There is a major difference on how orders fill depending on if they are historical trades or real-time trades.

                            Below I am adding a link to the help guide on Historical to help you understand what historical data is.
                            http://www.ninjatrader.com/support/h...historical.htm


                            The first order is Sell Stop Limit order with the limit and stop at 1156.3. Meaning that if the price is moving up as 1156.3 is touched, the limit also placed at 1156.3 will fill at that price or better. 1156.4 is a better price than 1156.3. If the price hit 1156.4, then with this type of order, the order is going to fill at 1156.4. Thats true no matter who your broker is or what platform you are using. A limit order will always fill at the limit price or better. For a sell limit order, 1156.4 is a better price than 115.3.

                            The second order is a Buy Stop Limit Order.
                            The order is placed with the stop at 1159 and the limit at 1159 and the order fills at 1159. I still am not understanding the issue here.

                            Is the order not suppose to fill at the limit price it has been submitted to?

                            I still need clarity on why this behavior is undesired. What are you expecting to happen?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              I think I see where the confusion is...

                              Yes I did create an order which was filled at 1156.4. But how does one create a Stop loss to protect this short?? With a "ButToCover" order. See below. the point is that when this was submitted via the OnExecution event it placed the pending order at 1159. The market appeared to Gap up on the same tick or was very generous in the filling of my original order.

                              stopOrder = SubmitOrder(0, OrderAction.BuyToCover, OrderType.StopLimit, 1, pTickPrice +1 * TickSize, pTickPrice +1 * TickSize, String.Format("GoldStop" + qty), "Average Fill..Stop loss to protect short");

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              646 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              367 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X