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

Can you help avoid an error i get with 'GetAtmStrategyStopTargetOrderStatus()'

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

    Can you help avoid an error i get with 'GetAtmStrategyStopTargetOrderStatus()'

    Hi everyone,

    Using Ninjatrader version 8.0.27.1 64-bit

    I created a strategy to issue and manage orders using the AtmStrategyCreate() command.

    Once a new entry order is created, i wait for the order to get filled to move the stop order to a certain distance away from the position average price.

    It works fine but once in a while i get an error when using this command before updating the stop loss:
    GetAtmStrategyStopTargetOrderStatus(string orderName, string atmStrategyId)

    The error message i get is this:
    'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid

    I have not been able to catch this error with Ninjascript.
    My script deals with it without affecting the behavior of my strategy but the error is logged into the Log window which i would like to avoid.

    I know this error has been described in other threads and i have implemented the solutions proposed.

    I also know it occurs because the Stop order has not been created or submitted yet but what i find strange is that my script
    make sure the entry order has been Filled and the position average price is greater than 0 which it should be since the entry order
    has been Filled. Finally, i make sure the the position is not Flat before checking the status of the Stop order associated to the entry order.

    Despite all these checks, the error still pops up occasionaly during a trading session.

    Can you see anything wrong with the part of my script which modify the stop loss ?

    Click image for larger version

Name:	GetAtmStrategyStopTargetOrderStatus_error.png
Views:	154
Size:	704.8 KB
ID:	1243233

    Here is what i get in the message window when an error occurs:
    Note that despite the fact the error is raised, the script do its job and wait for the next OnBarUpdate
    which happens a couple of times before the order gets accepted.
    Anyway, i'd like to prevent this error from showing in the Log window.
    ---
    'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
    needs to wait some more. Stop/target has not been created (or submitted) yet
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    needs to wait some more before order gets accepted
    Stop order Accepted
    ---​

    #2
    Hello trendisyourfriend,

    Thanks for your post.

    I see in the post you shared that your script is confirming that the order is not working yet.

    The error may occur when calling this method before the stop (or target) has been created and submitted.

    You should wait for 1 tick to pass after the entry fills before checking the state of the stop loss.

    To prevent this, ensure the Atm position is not flat before calling the GetAtmStrategyStopTargetOrderStatus() method.

    The SampleAtmStrategy strategy included with NinjaTrader provides sample code of checking the Atm position before working with the stops on line 96 - 100.

    Here is a forum thread about this topic which you might find helpful: https://ninjatrader.com/support/foru...052#post815052

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello trendisyourfriend,

      Thanks for your post.

      I see in the post you shared that your script is confirming that the order is not working yet.

      The error may occur when calling this method before the stop (or target) has been created and submitted.

      You should wait for 1 tick to pass after the entry fills before checking the state of the stop loss.
      I have added a 1 tick delay just after the entry has been filled and it works a majortity of the time but when
      the market is fast i still get an error, but my script can deal with it. However, the error is displayed in the Log window
      which i'd like to avoid to not make the user too nerveous

      Originally posted by NinjaTrader_BrandonH View Post
      Hello trendisyourfriend,
      To prevent this, ensure the Atm position is not flat before calling the GetAtmStrategyStopTargetOrderStatus() method.
      My script has already this check in place and the error can still be raised when the market is fast.

      Here is an extreme case i got this morning just after the open (09:30 New York time).
      Just after a new entry order was executed (filled).

      It took 27 OnBarUpdate for this method "GetAtmStrategyStopTargetOrderStatus()"
      to return a valid result which would not produce an error.

      ---
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid
      needs to wait some more. Stop/target has not been created (or submitted) yet
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      needs to wait some more before order gets accepted
      Stop order Accepted
      ---​

      Comment


        #4
        Hello trendisyourfriend,

        Thanks for your note.

        Unfortunately, there are no documented or supported methods or properties that allow you to suppress messages from appearing in the Log tab of the Control Center.

        We are tracking interest for this feature in an internal feature request ticket and I have added your vote to it. This request is being tracked under the number SFT-671.

        As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

        Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

        Please let us know if we may be of further assistance to you.​
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello trendisyourfriend,

          Thanks for your note.

          Unfortunately, there are no documented or supported methods or properties that allow you to suppress messages from appearing in the Log tab of the Control Center.

          We are tracking interest for this feature in an internal feature request ticket and I have added your vote to it. This request is being tracked under the number SFT-671.

          As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

          Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

          Please let us know if we may be of further assistance to you.​
          I have also tried to use this method "AtmStrategyChangeStopTarget()" as it Returns true if the specified order was found; otherwise false.
          That's what the Help file says.

          But the problem is that it also raises an error when the Stop or Target has not been found.


          Comment


            #6
            Hello trendisyourfriend,

            Thanks for your notes.

            If the Stop or Target has not been found then this error would appear. Once the order is created and submitted/accepted/working then the error will no longer appear.

            As previously stated, there are no supported means available for suppressing error messages from appearing and your vote was added to the feature request for this.

            The SampleAtmStrategy script that comes default with NinjaTrader uses the AtmStrategyChangeStopTarget() method within the script and when testing this I am unable to reproduce the behavior you are reporting.

            Please test reproducing the behavior with the SampleAtmStrategy script on the Playback connection. Are you able to reproduce the behavior of AtmStrategyChangeStopTarget() when testing this script?

            If so, send me the exact steps and settings you used to reproduce the behavior so I may look into this further on my end.

            Playback: https://ninjatrader.com/support/help...8/playback.htm

            Let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_BrandonH View Post
              Hello trendisyourfriend,

              ...

              The SampleAtmStrategy script that comes default with NinjaTrader uses the AtmStrategyChangeStopTarget() method within the script and when testing this I am unable to reproduce the behavior you are reporting.

              Please test reproducing the behavior with the SampleAtmStrategy script on the Playback connection. Are you able to reproduce the behavior of AtmStrategyChangeStopTarget() when testing this script?
              ...
              Hi, thanks for your help,

              I was able to reporduce this error using the SampleAtmStrategy this morning before the open at around 9:10 AM (New York time).

              When you add the SampleAtmStrategy, it calculates "On Bar Close" by default. I modified the script so that it calculates "On each tick" .

              Here is an example using this SampleAtmStrategy:
              Just after the entry order was "Filled" the 'AtmStrategyChangeStopTarget' raised the same error i get.
              ---
              status: Submitted
              status: Submitted
              status: Filled
              'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid
              'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid
              The current ATM Strategy market position is: Long
              The current ATM Strategy position quantity is: 1
              The current ATM Strategy average price is: 13112,25
              The current ATM Strategy Unrealized PnL is: -2
              ---

              *note: i have attached the modified script of the SampleAtmStrategy
              Click image for larger version

Name:	SampleAtmStrategy3.png
Views:	129
Size:	539.9 KB
ID:	1243903
              Last edited by trendisyourfriend; 03-31-2023, 07:36 AM.

              Comment


                #8
                Hello trendisyourfriend,

                Thanks for your note.

                I was able to reproduce the behavior when testing the script you shared. I also added a GetAtmStrategyStopTargetOrderStatus() in the script.

                When running the strategy using Calculate.OnEachTick, the Entry order is being filled and before the Stop1 order is in an orderState of Initialized, the GetAtmStrategyStopTargetOrderStatus() and AtmStrategyChangeStopTarget() methods are being called which is resulting in the errors you are reporting.

                Here is what the Log files could look like when this occurs:

                2023-04-03 08:51:30:695|1|32|Order='698bdaab2104440f8723ca1659eeb49b/Sim101' Name='Entry' New state='Filled' Instrument='ES 06-23' Action='Buy' Limit price=4204 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=1 Fill price=4204 Error='No error' Native error=''

                2023-04-03 08:51:30:697|3|4|'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid

                2023-04-03 08:51:30:697|3|4|'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid

                2023-04-03 08:51:30:699|1|32|Order='72d343a5c4294117a94e3ea4e83b236d/Sim101' Name='Stop1' New state='Submitted' Instrument='ES 06-23' Action='Sell' Limit price=0 Stop price=4202.75 Quantity=1 Type='Stop Market' Time in force=GTC Oco='b61ed15ec66b4008b808d7b56c5f1c1b' Filled=0 Fill price=0 Error='No error' Native error=''


                You must wait for at least 1 tick to pass after the entry fills before checking the state of the stop loss or changing the price of the stop loss.

                The simplest way to prevent this behavior from occurring would be to run your strategy using Calculate.OnPriceChange instead of Calculate.OnEachTick.

                Otherwise, you would need to ensure that the 'Stop1'​ order is submitted by waiting for at least 1 tick to pass before calling the GetAtmStrategyStopTargetOrderStatus() method or the AtmStrategyChangeStopTarget() method in your script.

                Please let me know if I may assist further.

                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NRITV, Today, 01:15 PM
                2 responses
                6 views
                0 likes
                Last Post NRITV
                by NRITV
                 
                Started by frankthearm, Today, 09:08 AM
                7 responses
                30 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by maybeimnotrader, Yesterday, 05:46 PM
                5 responses
                25 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by quantismo, Yesterday, 05:13 PM
                2 responses
                18 views
                0 likes
                Last Post quantismo  
                Started by adeelshahzad, Today, 03:54 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X