• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Labelling an entry order changes its execution

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

    Labelling an entry order changes its execution

    Hi guys,

    Take a look at the following 2 charts generated in Strategy Analyzer (I'm just showing a zoomed in section)..

    This chart generates orders using the following syntax (showing long orders only);

    Code:
    EnterLongLimit(1, GetCurrentBid());
    Click image for larger version

Name:	withoutlabel.PNG
Views:	1
Size:	43.5 KB
ID:	1041008

    This chart generates orders using the following syntax i.e. I label the entry with a string.

    Code:
    EnterLongLimit(1, GetCurrentBid(), "+Sc" + CurrentBar);
    Click image for larger version

Name:	withlabel.PNG
Views:	1
Size:	38.4 KB
ID:	1041009

    This is the only difference between the 2 strategies.

    The strategies are totally in sync until trade number 30 (about the middle of the chart) where they begin to diverge. I find this unsettling unless I am missing something. I would have thought that they should be identical.

    (Note: the strategies do have associated target and stop loss orders - but these are vanilla - they are not tied to any entry labels.)

    Please could you let me know your thoughts.

    thanks

    #2
    Hello trader_rick,

    I would not expect changing the signal name to change the logic for when orders are submitted or the logic for how they are filled.
    Below is a link to a video that shows a test of this.
    https://drive.google.com/file/d/1oXf...w?usp=drivesdk

    The first order that looks to be different is a sell order and is not a buy order. (It might be a different line of code than the line you are expecting)

    To find exactly what is different, use prints.

    Print the values of all variables used in the conditions that place orders, and then also print the order object in OnOrderUpdate so we can see when orders are submitted and changing states and what price they are being submitted with and what price they are filling at to give us more information.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    http://ninjatrader.com/support/forum...979#post510979

    Please include the code from the print and the output from the output window and we can further analyze what is different.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea, thanks for your response.

      I've reproduced your video with my strategy and there is a difference in results. Again, the only difference is in adding a label to the entry orders (long and short)

      I know how to print. There is no point in printing the condition values which trigger the orders at this stage since the logic is unchanged between strategies so it looks like the most helpful thing to do would be to print the order information.

      However, I've not done this before and I find the documentation on this unclear.

      How do I use OnOrderUpdate()? Where do I place it in the body of the code? Is it like OnBarUpdate()?

      (On a separate note, I find the documentation on NT8 woeful compared to its predecessor - although you guys do a great job in terms of support. If you got this sorted out, it would probably reduce your workload too.)

      regards

      Comment


        #4
        Hello trader_rick,

        I am not able to reproduce (as shown in the video I have provided).

        For me to know what is causing the differences on your end, I would need that output.
        The logic may not be changing but the values held in variables may be changing or the data may be different. This is why it is necessary to print all values for all variables used in all conditions that lead to orders.
        It might be that you are using the same signal names for both buy and sell orders and some orders are being ignored due to the entry handling.
        Without more information I am not able to direct you to finding the cause of the behavior.

        Or I will need the exact steps from you to reproduce on my end so that I can determine there is a bug and I can report this to our development.

        Below is a public link to the help guide on OnOrderUpdate().
        https://ninjatrader.com/support/help...rderupdate.htm

        Also, I didn't mention before that TraceOrders should also be enabled.
        https://ninjatrader.com/support/help...raceorders.htm


        Can you clarify what is missing from the NinjaTrader 8 help guide that is available in the NinjaTrader 7 help guide. I'll forward the missing pages to our product management.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Lol - you pointed me to the help that I'd already seen and thought unclear - never mind, I think I figured it out. (I've commented elsewhere on missing documentation.)

          The attached text files show the output of conditions triggering entry and the order details as called within OnOrderUpdate().

          Divergence happens fairly early on but you only need to look at the first 20 or so rows to see the discrepancy in orders - for some reason, in the labelled case, a cancellation is submitted but not in the unlabelled case, where the order goes on to be filled.

          I also attach the charts so you can visualize it better.

          Click image for larger version  Name:	labelled.PNG Views:	1 Size:	37.3 KB ID:	1041032Click image for larger version  Name:	unlabelled.PNG Views:	1 Size:	37.4 KB ID:	1041033

          regards

          EDIT:

          Sorry, noticed a typo in the output.

          Text should either read;

          Up value is below threshold so go short.

          or

          Down value is below threshold so go long.

          The actual Up/Down values and thresholds printed are correct.
          Attached Files
          Last edited by trader_rick; 11-27-2018, 01:37 PM.

          Comment


            #6
            Chelsea,

            I just noticed something. In your demo video you did not give each order a unique identifier. I am creating identifiers based on bar number so they are unique to the entry order.

            I think this has something to do with order handling rules.

            Comment


              #7
              Hello trader_rick,

              Unfortunately, the output does not include timestamps so that everything can be lined up as demonstrated in the video in the link I have posted that shows how to use prints to understand behavior.

              This means I can't be sure that things are happening at the same time or at different times. I can see the submission time of the orders are the same with the order object but I can't see when actions are happening in the logic.

              The are no prints for the values used in conditions so we don't have this information as well.

              TraceOrders was not enabled so we can't see if the order is being cancelled due to liveUntilCancelled..

              But looking at the output I am seeing:

              unlabelled.txt
              orderId='NT-00003-860' account='Backtest' name='Buy' orderState=Submitted instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-860' account='Backtest' name='Buy' orderState=Accepted instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-860' account='Backtest' name='Buy' orderState=Working instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              Value is below threshold so go long - Value: 0.1725 Threshold: 0.175
              orderId='NT-00004-860' account='Backtest' name='Stop loss' orderState=Submitted instrument='ES 12-18' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2736.75 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00004-860' account='Backtest' name='Stop loss' orderState=Accepted instrument='ES 12-18' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2736.75 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00004-860' account='Backtest' name='Stop loss' orderState=Working instrument='ES 12-18' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2736.75 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00005-860' account='Backtest' name='Profit target' orderState=Submitted instrument='ES 12-18' orderAction=Sell orderType='Limit' limitPrice=2744.75 stopPrice=0 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00005-860' account='Backtest' name='Profit target' orderState=Accepted instrument='ES 12-18' orderAction=Sell orderType='Limit' limitPrice=2744.75 stopPrice=0 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00005-860' account='Backtest' name='Profit target' orderState=Working instrument='ES 12-18' orderAction=Sell orderType='Limit' limitPrice=2744.75 stopPrice=0 quantity=1 tif=Day oco='NT-00002-860' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:50:00' gtd='2099-12-01' statementDate='2018-11-27'

              orderId='NT-00003-860' account='Backtest' name='Buy' orderState=Filled instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=1 averageFillPrice=2744.25 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'

              labelled.txt

              Value is below threshold so go long - Value: 0.1725 Threshold: 0.175
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=Submitted instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=Accepted instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=Working instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              Value is below threshold so go long - Value: 0.1725 Threshold: 0.175
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=CancelPending instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=CancelSubmitted instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              orderId='NT-00003-851' account='Backtest' name='+Sc18' orderState=Cancelled instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-27'
              This does give us some information. The orders are submitted and have the same datetime. One fills and the other does not.

              The question becomes why was this order not filled? Was the limit price between the high and low of the bar?

              I would like you to add timestamps and enable TraceOrders and print the high and low of the bar in OnOrderUpdate() (to see the high and low on the bar when it is cancelled not when submitted). If the order is cancelled due to isLiveUntilCancelled false, and the order submission price is between the high and low of the bar, the order should have filled.



              In the video I've provided, the crossover script would never attempt to place more than one order in any direction. I've only used different names for the buy or sell orders, not for each bar.

              I've attached the script for you to test. With this script are you able to reproduce the behavior?
              Attached Files
              Last edited by NinjaTrader_ChelseaB; 11-27-2018, 03:15 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,

                Thanks for your help and patience.

                I modified the strategies you sent me and I can't duplicate the behaviour that I have with my own strategy.

                However, I do notice that your signals are mutually exclusive. My strategy is made up of two signals and two different thresholds so it is possible to place orders in the same or even opposite direction, all on the same bar. This is intentional and I might refine the strategy later on to remove some of these conflicts. I just assumed, however, that the internal order handling rules would take care of it and I could sort it out later if necessary. What I don't understand is how labelling an order changes whether it gets executed or not. (I do have targets and stops but these are not tied to the label.).

                It's late here now in the UK so I'll take a fresh look at it tomorrow.

                regards

                Comment


                  #9
                  OK Chelsea, let's try again ;-)

                  Trace on
                  Timestamps added
                  Highs and Lows added

                  It's interesting - in the labeled case we are getting a cancelled expired order at 14:50 but I don't know why the order is expiring in this case.

                  regards

                  P.S. As an aside, can you ask the devs to add the ability to export from the output window? It's a pain to have to manually select, copy and paste.
                  Attached Files
                  Last edited by trader_rick; 11-28-2018, 07:19 AM.

                  Comment


                    #10
                    Hello trader_rick,

                    I am seeing the order is being cancelled due to the liveUntilCancelled handling. If liveUntilCancelled is not used, this is by default false. When false, if an order does not fill on the bar it is submitted on it is cancelled when that bar closes.

                    21/05/2018 14:50:00 Strategy 'ESVolatilityOld/-1': Cancelled expired order: BarsInProgress=0, orderId='NT-00003-1965' account='Backtest' name='+Sc18' orderState=Working instrument='ES 12-18' orderAction=Buy orderType='Limit' limitPrice=2744.25 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-21 14:49:00' gtd='2099-12-01' statementDate='2018-11-28'

                    So the order was cancelled because it did not fill on the bar it was submitted on.

                    Are you using the Default or Liberal fill type?

                    The test script I have provided to you is not able to reproduce this behavior.

                    May I have the strategy you are testing so that I may reproduce the behavior on my end so that I may further investigate?

                    To export a NinjaTrader 8 NinjaScript, so this can be shared and imported by the recipient, do the following:
                    1. Click Tools -> Export -> NinjaScript...
                    2. Click the 'add' link -> check the box(es) for the script(s) you want to include
                    3. Click the 'Export' button
                    4. Enter a unique name for the file in the value for 'File name:'
                    5. Choose a save location -> click Save
                    6. Click OK to clear the export location message

                    By default your exported file will be in the following location:
                    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>

                    Below is a link to the help guide on Exporting NinjaScripts.
                    http://ninjatrader.com/support/helpG...-us/export.htm
                    Last edited by NinjaTrader_ChelseaB; 11-28-2018, 10:53 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I'm using default fill as far as I can tell - I haven't set anything in this regard.

                      Do you have an email address I can send to? Whilst this particular strategy is not earth-shattering in its complexity or even profitable for that matter I don't like posting these in public unless there is something specific that I'd like to share.

                      I'll also need to send you my underlying indicator.

                      regards

                      Comment


                        #12
                        Hello trader_rick,

                        To contact NinjaTrader Platform Support send an email to platformsupport [at] ninjatrader [dot] com. (Replace the [at] with @ and the [dot] with a period).

                        This email address can also be found on the contact page of the www.ninjatrader.com website.
                        https://ninjatrader.com/ContactUs

                        In the email please include a link to this forum thread.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          files have been sent

                          Comment


                            #14
                            Hello trader_rick,

                            There are times when the order will not fill on the bar its submitted on.

                            When no signal names are used, the order is resubmitted on the next bar and is kept alive and later fills on a different bar.

                            However, when using signal names that are unique for each bar, the original order is allowed to be cancelled due to the liveUntilCancelled not being used and defaulting to false and a new order with a new name is submitted because you are changing the signal name instead of resubmitting the order with the same signal name. The new order is ignored because of the Entries Per Direction being set to 1 and not allowing for a second entry.

                            You can choose to resubmit the order using the original signal name to keep the order alive or you can choose to use isLiveUntilCancelled as true.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              OK, thanks Chelsea - I'll use the function signature that sets isLiveUntilCancelled to true.

                              regards

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ralett, Today, 06:20 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post ralett
                              by ralett
                               
                              Started by grizzlytrader, Today, 06:24 AM
                              1 response
                              20 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by andrewtrades, Today, 01:43 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by FuturesRon, Today, 03:09 AM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Ivantr, Today, 05:24 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Ivantr
                              by Ivantr
                               
                              Working...
                              X