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

OnExecutionUpdate/OnOrderUpdate for Market unmanaged orders

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

    OnExecutionUpdate/OnOrderUpdate for Market unmanaged orders

    OnExecutionUpdate/OnOrderUpdate doesn't trigger for Market orders in unmanaged approach.

    Trace orders messages, no errors in the log.

    20.12.2017 13:12:38 Strategy 'VPBS2/125647077': Entered internal SubmitOrderUnmanaged() method at 20.12.2017 13:12:38: BarsInProgress=0 Action=Buy OrderType=Market Quantity=2 LimitPrice=6493,75 StopPrice=6493,75 SignalName='VPBS #33 1 of 2'
    20.12.2017 13:12:38 Strategy 'VPBS2/125647077': Entered internal SubmitOrderUnmanaged() method at 20.12.2017 13:12:38: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=6493,75 StopPrice=6493,75 SignalName='VPBS #33 2 of 2'

    Any suggestions?

    #2
    Hello ren37,

    Thanks for your question.

    When I test unmanaged orders, I see prints for OnExecutionUpdate() and OnOrderUpdate().

    Could you try placing a print for the whole execution and the whole order in OnExecutionUpdate() and OnOrderUpdate() to troubleshoot further?

    Print("ORDER: " + order.ToString());
    Print("EXECUTION: " + execution.ToString());

    I tested with the attached script on my end. Each order is set to OrderType.Market. When you run the test script on your end, do you see the same issues?

    NOTE: The provided code is a modification of an existing sample to show prints from OnExecutionUpdate() and OnOrderUpdate() firing in the output window. It is not intended to be a working example strategy and is expected to be non-functional. This is a test-script only.

    I look forward to being of further assistance.
    Attached Files
    Last edited by NinjaTrader_Jim; 12-27-2017, 03:20 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello

      Your script failed.
      But I found a bug in my code.
      Seems OnExecutionUpdate invoked from different thread and triggered before constructor of my custom position class returns instance to handle.

      ORDER: orderId='43b8beb97d6648ab8dfc1826fb75c201' account='Playback101' name='Short limit entry' orderState=Submitted instrument='NQ 03-18' orderAction=SellShort orderType='Market' limitPrice=6530.75 stopPrice=0 quantity=1 tif=Gtc oco='7aeb2b4a84c74c43b22b05085aa0790dentry' filled=0 averageFillPrice=0 onBehalfOf='' id=408 time='2017-12-18 04:01:02' gtd='2099-12-01' statementDate='2017-12-18'
      ORDER: orderId='43b8beb97d6648ab8dfc1826fb75c201' account='Playback101' name='Short limit entry' orderState=Accepted instrument='NQ 03-18' orderAction=SellShort orderType='Market' limitPrice=6530.75 stopPrice=0 quantity=1 tif=Gtc oco='7aeb2b4a84c74c43b22b05085aa0790dentry' filled=0 averageFillPrice=0 onBehalfOf='' id=408 time='2017-12-18 04:01:02' gtd='2099-12-01' statementDate='2017-12-18'
      ORDER: orderId='43b8beb97d6648ab8dfc1826fb75c201' account='Playback101' name='Short limit entry' orderState=Working instrument='NQ 03-18' orderAction=SellShort orderType='Market' limitPrice=6530.75 stopPrice=0 quantity=1 tif=Gtc oco='7aeb2b4a84c74c43b22b05085aa0790dentry' filled=0 averageFillPrice=0 onBehalfOf='' id=408 time='2017-12-18 04:01:02' gtd='2099-12-01' statementDate='2017-12-18'
      ORDER: orderId='43b8beb97d6648ab8dfc1826fb75c201' account='Playback101' name='Short limit entry' orderState=Filled instrument='NQ 03-18' orderAction=SellShort orderType='Market' limitPrice=6530.75 stopPrice=0 quantity=1 tif=Gtc oco='7aeb2b4a84c74c43b22b05085aa0790dentry' filled=1 averageFillPrice=6529.5 onBehalfOf='' id=408 time='2017-12-18 04:01:02' gtd='2099-12-01' statementDate='2017-12-18'
      EXECUTION: execution='7e970665c6894a1dbba17aab90e119de' instrument='NQ 03-18' account='Playback101' exchange=Default price=6529.5 quantity=1 marketPosition=Short orderId='43b8beb97d6648ab8dfc1826fb75c201' time='2017-12-18 04:01:02' sod=False statementDate='2017-12-18'
      Strategy 'UnmanagedTemplate_PrintTest NT8/125647078' submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

      Comment


        #4
        Hello ren37,

        The modified script was provided only as a tool to test prints in OnExecutionUpdate() and OnOrderUpdate() to help narrow down the issue or identify an issue with the platform. I would not expect it to be a usable strategy.

        Thanks for sharing your input that the issue was caused by threading.

        If there is another matter with the platform you would like to troubleshoot, please don't hesitate to write back.
        JimNinjaTrader Customer Service

        Comment


          #5
          Ok.
          Nevetherless you are providing non working scripts.
          Hmmm...

          Btw your code is not correct.
          In some cases because of multi-threading order property will be not assigned when OnExecutionUpdate triggers. Right?
          Last edited by ren37; 12-27-2017, 09:06 AM.

          Comment


            #6
            Hello ren37,

            The multithreading consideration for OnOrderUpdate() OnExecutionUpdate() and OnPositionUpdate() has to do with the sequence of events in which the method is called and the actual state of the objects.

            A scenario for OnExecutionUpdate() would be if there are several quick partial fills. The Order object of the Execution object that iterates in OnExecutionUpdate() would reflect an older state than in sequence, when a direct reference to that Order object (outside of Execution.order) would show the current state.

            These considerations can be found here: https://ninjatrader.com/support/help...-threading.htm

            I've updated my post to be clearer on the intention of the example code.

            Was there anything else involving your original inquiry that you wanted to address?
            Last edited by NinjaTrader_Jim; 12-27-2017, 10:26 AM.
            JimNinjaTrader Customer Service

            Comment


              #7
              I know well what you are talking about.
              But my question was
              In your script "in some cases because of multi-threading order property will be not assigned when OnExecutionUpdate triggers. Right?" SubmitOrderUnmanage() is not a blocking method. And assignment might be done AFTER OnExecutionUpdate triggers. So your shortEntry/longEntry will be null in OnExecutionUpdate and no SL/TP orders will be set.
              I don't see answer from you.

              As I remember Help guide advises to store order object by getting it from input parameter of OnExecutionUpdate/OnOrderUpdate but not getting it from result of SubmitOrderUnmanage().
              What you think?

              Comment


                #8
                It was not clear to me that you were referring to the entry orders. Yes, you are right that assigning Order objects in OnOrderUpdate() is more reliable than OnBarUpdate().

                I'll update the original script so this is reflected.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Entry order is Market type. But it was about multi-threading
                  The only wish is to have more reliable samples...
                  Ty

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jclose, Today, 09:37 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,414 views
                  0 likes
                  Last Post Traderontheroad  
                  Started by firefoxforum12, Today, 08:53 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post firefoxforum12  
                  Started by stafe, Today, 08:34 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post stafe
                  by stafe
                   
                  Started by sastrades, 01-31-2024, 10:19 PM
                  11 responses
                  169 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X