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

Addon Account.Change and Order objects

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

    Addon Account.Change and Order objects

    The documentation for https://ninjatrader.com/support/help...-us/change.htm indicates that to change an order, the code should modify the xxxxChanged property for the change needed. Using Visual Studio to look at the definition for the Order class this reveals the following options to be changed.
    • LimitPriceChanged
    • StopPriceChanged
    • QuantityChanged
    Changing the original Quantity, LimitPrice or StopPrice and then calling Account.Change seems to have no affect on the order. The naming of these properties is confusing as it uses a past tense changed to indicate something that is to be changed.

    Debugging further reveals that the fields are never reset back to default states after the change is accepted. Once the OrderState goes to OrderState.Accepted it was expected that these fields would reset back to 0's.

    Are these fields supposed to reset back after a change is accepted?
    Are these the correct fields to push changes through?

    #2
    Hello ntbone,

    Yes, the LimitPriceChanged, StopPriceChanged, and QuantityChanged are the correct properties to set for a change.

    It is expected these will not be reset to 0. Whatever they are set to at the time Change() is called will be what is used for the order.

    Below is a link to an example that modified orders through the addon approach.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I was running into strange behavior when changing my orders but I suspect now that was due to them being part of an OCO. Internals of NinjaTrader were changing them and I was also trying to change them resulting some odd results. I am going to stop using OCO and just implement it myself using the logic I want, which is different from the default behavior.

      Comment


        #4
        Hello ntbone,

        The example I have provided uses OCO.

        Are you finding this is not sufficient as a working example?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The example definitely helps clarify things, and would be worth adding to the list of samples in the documentation. It helps confirm that I am using the API's correctly.

          The issues I am running into are trying to change the quantity behavior of OCO orders. I am working with the simulation accounts. When two orders are part of an OCO and one them is partially filled, the other one has its quantity adjusted by scaling it back. I want to change this behavior so I have been changing the quantity of the orders as they are partially filled. This is having strange side effects though since the internal code is also changing the quantity of the orders.

          I am going to drop using OCO and implement that myself since I want different quantity adjustment behavior then is provided, and since brokers may also not implement the adjustment to quantity the way I want.

          Comment


            #6
            Hello ntbone,

            Few considerations with changing order quantities with part fills.

            If the part fills are happening quickly you might just allow them to happen.

            You may need to be sure if the particular brokerage cancels the part filled portion of orders with the same OCOID string on the server side.

            Other wise as you call the change order you may need to select a new price for the working order that is a valid price as if the order is filling, then its probably on that side of the market now.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              How would I go about determining if the part fill is happening quickly?

              I have not had a chance to work with an actual broker yet so all of my work is currently happening with just the simulation account and a live data feed/market replay data.

              I am still confused why stop orders have this condition and pop up this error message when the price has moved. I have requested an explanation for this error message but have yet to get a sufficient answer.

              Sell stop and stop limit orders must have the stop price below the market price.
              Buy stop and stop limit orders must have the stop price above the market price.

              If I create a sell stop order/stop limit order above the market price, why can't it just execute right away and become a market order/limit order?
              If I create a buy stop order/stop limit order below the market price, why can't it just execute right away and become a market order/limit order?

              Other trading software I have used lets you set the stop order at any price and executes it right away if the price has already moved past it. I see no advantage to this error message and denying the user the ability to create the order. This situation also needlessly complicates the code I am working on to take orders.

              Comment


                #8
                Hello ntbone,

                You are getting an error message?

                What is the error message?


                A stop order on the wrong side of the market will be rejected.

                You would need to talk to a broker about why brokerages have these rules.

                Some brokerages allow limit orders to be placed on the wrong side of the market (typically not for forex).

                This is not a software limitation, this is a brokerage rule limitation. You will not be able to do this on the phone either.

                However, if you want to code in the software to choose a better price for a modification, that is possible to code.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ah. I haven't gotten any error messages yet. You mentioned "If the part fills are happening quickly you might just allow them to happen." so I was curious how I would go about determining "too quickly".

                  Thanks for clarification on the error messages/rejection of stop orders on the wrong side of the market. The other software I had used was directly with its own broker so they must have just gone with different rules. Thanks for the clarification. It's good to know that this is a broker rule and thus something I will have to work around.

                  Comment


                    #10
                    Hello ntbone,

                    What I mean by "If the part fills are happening quickly you might just allow them to happen" I just mean you might wait until the order is fully filled before taking action. But as part fills are happening this can cause a rapid set of change orders depending on how the code is written. When talking to the brokerage everything has transmission times which mean as something is part filling, trying to modify or cancel it can result in an overfill.

                    But the script is able to adequately handle rejections and overfills, to re-submit orders this may do the job.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I am not sure what you mean by "But the script is able to adequately handle rejections and overfills, to re-submit orders this may do the job."

                      If I wait for a full fill I won't be able to handle situations where a full fill never completes. Consider the following
                      1. A market order buy order is filled for 200 units
                      2. A sell limit order is set for 100 units, a sell stop order is set for 200 units. They price difference is 0.2.
                      3. The limit order fills for 50 units, say at 10 units at a time.
                      4. The instrument changes direction and hits the stop.
                      5. The stop fills for the full 200 units leaving now 50 units outstanding.
                      If the stop is updated as the partial fills happen then it should be for only 150 units thus closing out the position.

                      It is unclear to men how I can tell when the limit order is no longer being partially filled thus making it safe to update the stop order.

                      The code I am writing never tries to modify an order while it is being part filled. The way I have coded this up, as the limit order is part filled, the stop order is updated to reflect the new amount. I am no longer using the OCO functionality since it results in a fight for changing the quantity.

                      Comment


                        #12
                        Hello ntbone,

                        As things are part filling things are happening quickly and there is the chance of in-flight-executions.

                        If the price changes causing the order to fill, and then you want to change that order, you will need to also change the price to a valid price that can be accepted.

                        However, I would imagine that the OCO should be handling this.

                        Are you finding the OCO does not adjust the quantity of the other orders in the pairing?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          The OCO doesn't adjust it right. Please reread the situation I have presented in my previous post. Please let me know if its not clear what I am trying to do.

                          If I make an OCO for the situation I referred to, it will scale the stop order as the limit order fills. Referring to my example before if I used OCO what would happen is
                          1. A market buy order is filled for 200 units
                          2. A sell limit order is set for 100 and a sell stop order for 200
                          3. The limit order fills for 50 units only, and as a result the stop order is now adjusted to 100 units. Since the limit order has filled half, the stop order is now adjusted to be half of what it was.
                          4. The instrument changes direction and hits the stop without filling the rest of the limit order.
                          5. The stop fills for the full 200 units leaving now 100 units outstanding.
                          What I want is the stop order to close the position in the event that it is hit, regardless of how partially filled the limit order is. This requires me to manually update the stop order as the limit order is partially filled setting the stop order to close out the remaining position. I have abandoned using OCO because it won't give me the behavior I want and am instead attempting to figure out how to manually update the stop order.

                          Comment


                            #14
                            Hello ntbone,

                            In what you previously posted, I would expect the OCO to be adjusting the quantities.

                            From this post #13 it looks like you are using OCO with orders that have different quantities.
                            Your stop and target should have the same quantity. Use separate order pairs if you are wanting to scale out specific quantities at a time.

                            As an example for this type of logic see the reference sample.


                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by gemify, 11-11-2022, 11:52 AM
                            6 responses
                            803 views
                            2 likes
                            Last Post ultls
                            by ultls
                             
                            Started by ScottWalsh, Today, 04:52 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post ScottWalsh  
                            Started by ScottWalsh, Today, 04:29 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post ScottWalsh  
                            Started by rtwave, 04-12-2024, 09:30 AM
                            2 responses
                            22 views
                            0 likes
                            Last Post rtwave
                            by rtwave
                             
                            Started by tsantospinto, 04-12-2024, 07:04 PM
                            5 responses
                            70 views
                            0 likes
                            Last Post tsantospinto  
                            Working...
                            X