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

Is it possible to have finer control over an order submitted via AtmStrategyCreate()?

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

    Is it possible to have finer control over an order submitted via AtmStrategyCreate()?

    I found from the documentation that the level of control over an order submitted via AtmStrategyCreate() is somewhat limited. For instance, to close a non-terminal-state order submitted by AtmStrategyCreate(), AtmStrategyClose() would cancel any open orders on the active instrument/account. This is problematic as unrelated orders would be affected. It seems that there is no way to work with the actual Order object. Is there a way to achieve finer control over the order so that I can, in the fore-mentioned case for instance, be able to close only the submitted order?

    #2
    Hello mbesha,

    Without knowing what logic you were using it would be hard to understand the outcome you described. In general an ATM controlled from NinjaScript requires very specific coding and use of string ID's, if something was mixed up in the logic it certainly could produce unknown results when calling the ATM methods.

    It is currently not possible to have better control over an ATM strategy in general. The point of the ATM is to have limited control because an outside strategy(ATM) controls the target orders instead of you or your NinjaScript strategy. For what you are asking you would be better off using either the Managed or Unamanged approach so you have full control over the orders. ATM's are only intended to be started and then work on their own so if you need to do other actions with the targets an ATM is not a good choice for that use case.


    I look forward to being of further assistance.



    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by mbesha View Post
      I found from the documentation that the level of control over an order submitted via AtmStrategyCreate() is somewhat limited. For instance, to close a non-terminal-state order submitted by AtmStrategyCreate(), AtmStrategyClose() would cancel any open orders on the active instrument/account. This is problematic as unrelated orders would be affected.
      Just to clarify,
      Isn't the behavior affecting "unrelated orders" confined entirely within the Strategy executing the AtmStrategyClose?

      I mean, any manual orders and any orders created by other running Strategies would not be affected by that AtmStrategyClose, correct?

      A careful reading of the documentation implies the answer is "yes" for both questions, since it says,
      "Cancels any working orders and closes any open position of a strategy ..."

      My point is, the OP has said,

      Originally posted by mbesha View Post
      AtmStrategyClose() would cancel any open orders on the active instrument/account.
      I see a disconnect between what the OP is reporting and what the documentation says the behavior should be.

      It seems like what the OP is saying is AtmStrategyClose cancels more open orders than it is supposed to.

      mbesha, for the same instrument/account, is AtmStrategyClose also cancelling your open orders submitted manually?

      Comment


        #4
        Originally posted by bltdavid View Post
        A careful reading of the documentation implies the answer is "yes" for both questions, since it says,
        "Cancels any working orders and closes any open position of a strategy ..."
        The documentation, being annoying sparse on details, does not say "of an ATM strategy", so we are left
        to assume "strategy" is referring to an automated Strategy written in NinjaScript ...

        To me, the documentation says it will only affect the orders of the Strategy calling it ... am I wrong?

        Comment


          #5
          Hello bltdavid,

          I would not want to try and go further into what may be happening without more specific details first. To reiterate the question that was asked:
          It seems that there is no way to work with the actual Order object. Is there a way to achieve finer control over the order so that I can, in the fore-mentioned case for instance, be able to close only the submitted order?
          There is not a more elegant way to control the ATM's orders besides the methods which are documented or the sample that we provide. Given that working with the actual orders was listed very likely one of the other order handling approaches should be used here so that the orders can be manged individually. I would not want to otherwise guess or speculate at the situation, if mbesha would like to explore the ATM script further we can, I would just need more details on what is being done in the script that situation.



          Please let me know if I may be of additional assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Originally posted by bltdavid View Post

            The documentation, being annoying sparse on details, does not say "of an ATM strategy", so we are left
            to assume "strategy" is referring to an automated Strategy written in NinjaScript ...

            To me, the documentation says it will only affect the orders of the Strategy calling it ... am I wrong?
            I thought the same as you did until I read the help documentation for nt8 for the same method (https://ninjatrader.com/support/help...ategyclose.htm). Note the "using default ATM strategy close behavior" link that seems to indicate otherwise. May be for nt7 it really is restricted to the ATMstrategy but is it really so for certain?

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello mbesha,

              Without knowing what logic you were using it would be hard to understand the outcome you described. In general an ATM controlled from NinjaScript requires very specific coding and use of string ID's, if something was mixed up in the logic it certainly could produce unknown results when calling the ATM methods.
              I have read from the documentation that ATMStrategy methods make use of an orderId. Is it possible to use it to find a specific order from Account.Orders and thus make a link from the ATMStrategy to an Order object?

              Comment


                #8
                Hello mbesha,

                Is it possible to use it to find a specific order from Account.Orders and thus make a link from the ATMStrategy to an Order object?
                Not in any supported/suggested ways no, the ATM orders are not designed to be accessed individually like the other order handling approaches. The Managed and Unamanged approaches are created with the purpose of working with the individual orders. If the purpose is to gain finer control over the orders or work individually with orders to do extra logic you would need to move to the managed or unmanaged approach.

                Is there a specific feature you wanted to from the ATM over one of the other approaches? If you can provide more detail on what you want to do with the order overall I can try to provide links to other related resources to help toward that.

                I look forward to being of further assistance.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Is there a specific feature you wanted to from the ATM over one of the other approaches? If you can provide more detail on what you want to do with the order overall I can try to provide links to other related resources to help toward that.
                  As I mentioned previously, I want to be able to cancel an order submitted by ATMStrategyCreate() and it should be able to do so without affecting any other open orders in the account. I did not find this specific feature as ATMStrategyClose() seems to affect others orders in the account as well.


                  Originally posted by NinjaTrader_Jesse View Post
                  Not in any supported/suggested ways no, the ATM orders are not designed to be accessed individually like the other order handling approaches.
                  I think it I might just go with a Managed approach if there is no good workaround. It will require reworking my strategy code substantially but if it the only way to achieve the goal, it can't be helped.

                  Comment


                    #10
                    Originally posted by mbesha View Post
                    As I mentioned previously, I want to be able to cancel an order submitted by ATMStrategyCreate() and it should be able to do so without affecting any other open orders in the account. I did not find this specific feature as ATMStrategyClose() seems to affect others orders in the account as well.
                    The over-reaching AtmStrategyClose behavior where it closes all orders for that instrument/account
                    is a seriously aggravating 'gotcha' when working with the NinjaTrader 7 ATM api's.

                    Why?
                    Because the NT7 documentation for AtmStrategyClose lies to you.

                    Jesse, there is no need to speculate. It is clear to anyone who uses AtmStrategyClose in their
                    code that NT7 AtmStrategyClose documentation does not document the behavior they experience.

                    Btw, I don't think NT8 is much better in this department.

                    mbesha, the problem is -- neither NT7 or NT8 have an API for the Close behavior you want.

                    How so? Let's look at NT8, where the documentation says this,
                    "(the left mouse button will close the current position and cancel any working orders associated
                    with the instrument/account combination and the middle mouse button (scroll wheel) will close the
                    selected active ATM Strategy position only)"

                    Just like NT7, the AtmStrategyClose in NT8 performs left mouse button behavior.

                    The real problem is this:
                    Neither NT7 or NT8 have an API that performs the middle mouse button behavior.

                    A feature request should be submitted to NT8 for the addition of an API to perform the
                    middle mouse button behavior to close the active ATM Strategy position only.

                    Jesse, can you do that?

                    Comment


                      #11
                      Hello mbesha,

                      I have tested the AtmStrategyClose() and I am finding that positions opened from manual orders that are not submitted to an active Atm Strategy are not being cancelled by AtmStrategyClose().

                      Below is a link to a video of the test.
                      https://drive.google.com/file/d/1geY...w?usp=drivesdk


                      bltdavid,

                      I will request that the help guide for NinjaTrader 7 be changed to specifically state: 'Cancels any working orders and closes any open position of an Atm Strategy...' to clarify.


                      With NinjaTrader 7, any usage of the Account is not supported or documented.
                      Below is a link to a forum post that has some undocumented code you may find helpful.
                      http://www.ninjatrader.com/support/f...2&postcount=33

                      With NinjaTrader 8, using the Account is supported and there is a way to find a working Atm Strategy from an Account Order. I do have an example script of this if you would like this.


                      With the middle mouse behavior, this will only close the selected active Atm Strategy.

                      With the AtmStrategyClose() this will only close the Atm Strategy created by the script with that Atm Strategy ID as demonstrated in the video above. It will not close an Atm Strategy that is selected in the Atm Strategy drop-down of any trade window such as Chart Trader or SuperDOM, if that Atm Strategy is not the Atm created by the script.

                      Are you asking for a NinjaScript Atm Strategy method that will look at the focused window and close the Atm Strategy that is manually selected in the trade window?
                      Last edited by NinjaTrader_ChelseaB; 01-29-2020, 12:29 PM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you, I will take a look ...

                        Comment


                          #13
                          Thanks, ChelseaB!

                          Excellent video, it was very helpful, I stand corrected, thank you very much for making that.

                          The key element I had been missing (apparently, for several years ) is where you said this,

                          "if that Atm Strategy is not the Atm created by the script".

                          I shall retreat back to my cave ..

                          Comment


                            #14
                            Originally posted by NinjaTrader_ChelseaB View Post
                            I have tested the AtmStrategyClose() and I am finding that positions opened from manual orders that are not submitted to an active ATM Strategy are not being cancelled by AtmStrategyClose().
                            ...
                            With the AtmStrategyClose() this will only close the Atm Strategy created by the script with that Atm Strategy ID as demonstrated in the video above.
                            ChelseaB - Thanks for testing how the method affects manual orders and I am glad to know there is no effect. I am particularly interested in how the method affects orders created by script using the AtmStrategyCreate() method and using the same ATM Strategy Template. For instance, let's say the same strategy, say SampleAtmStrategy, is enabled for different charts and since it is the same strategy used in different charts, the ATM Strategy Template used in all of them is also the same. In such a case, it seems that despite the strategy being on different charts, the orders created on each chart and not treated independently but are rather lumped together and treated collectively under the Atm Strategy Template. So orders created using AtmStrategyCreate() or closed using AtmStrategyClose() on one chart affect any open orders on the other charts. The way to have independent control over each order on each chart would be to have a different ATM Strategy Template used for each chart. Correct me if I am wrong but if this is indeed true, then I think I will just go with a managed approach as I do not want to have to create as many ATM Strategy Templates as I have charts. Thanks for enlightening me on ATM strategy methods.

                            Comment


                              #15
                              Hello mbesha,

                              The AtmStrategyClose() will close a strategy by ID. This is ID is generated by GetAtmStrategyUniqueId(). This ID will be unique each time its called. For each chart running the script, a different ID is going to be used so the NinjaScript Strategy will only be closing the Atm Strategy created with that ID.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              31 views
                              0 likes
                              Last Post love2code2trade  
                              Started by cls71, Today, 04:45 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post eDanny
                              by eDanny
                               
                              Started by proptrade13, Today, 11:06 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post proptrade13  
                              Started by kulwinder73, Today, 10:31 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X