Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to change order with no native error

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

    Unable to change order with no native error

    Hi,

    I am in the middle of developing an indicator which can place orders.

    I am using following code which places an order with an ATM.

    Code:
    account.CreateOrder(this.Instrument, OrderAction.Buy, OrderType.Market, TimeInForce.Day, 1, 0, 0, string.Empty, "Entry", null);
     NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy("ATM1", order);​
    It works fine, order is placed and Stop and target orders are also placed based on the ATM.

    OnBarUpdate function I check some conditions and want to change the limit price of the target order.
    Code:
    foreach (var o in account.Orders.Where(p => p.IsLimit
                                && p.Name == "Target1"
                                && (p.OrderState == OrderState.Working))){
    
     o.LimitPrice = newPrice;
    account.Change(new[] { o });​​
    }
    I use the above code to find the working limit order for the target1 and apply the price change.

    This works fine on the Sim but not when I run the indicator on the live account using NT brokerage.

    Code:
    2025-01-17 14:12:30:136|1|32|Order='1067315690/XXX' Name='Target1' New state='Accepted' Instrument='MNQ MAR25' Action='Sell' Limit price=21624.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='95296df0af154c43b527a7c593685357' Filled=0 Fill price=0 Error='No error' Native error=''
    2025-01-17 14:12:30:136|1|32|Order='1067315690/XXX' Name='Target1' New state='Working' Instrument='MNQ MAR25' Action='Sell' Limit price=21624.25 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='95296df0af154c43b527a7c593685357' Filled=0 Fill price=0 Error='Unable to change order' Native error=''
    2025-01-17 14:12:30:136|0|32|XXX,  affected Order: Sell 1 Limit @ 21624.25​
    It just says "Unable to change order" and there is no native error

    Any help on this please?


    #2
    Hello azh_ali,

    ATM's are ultimately in control of the order. To do what you are asking you would need ot make a strategy and use the strategy atm method AtmStrategyChangeStopTarget

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    JesseNinjaTrader Customer Service

    Comment


      #3
      What does it work on the sim account then? Indicator is quite complex and porting the code would be difficult, is it possible for indicator to place the order and ATM or find the ATM object and manage it via that?

      Comment


        #4
        Hello azh_ali,

        All I can suggest is trying with the strategy approach which has specific atm methods. That should allow you to control the atm.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the pointer. I stored the object return by StartAtm method and use that to set the ProfitTarget and it worked!!

          AtmStrategy atm = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(ATMName, order);
          atm.SetProfitTarget(CalculationMode.Price, newPrice);


          Comment


            #6
            I take it back this method doesn't work.

            AtmStrategy atm = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(ATMName, order);
            atm.SetProfitTarget(CalculationMode.Price, newPrice);​


            if you do call
            atm.SetProfitTarget(CalculationMode.Ticks, 25);
            or
            atm.SetProfitTarget(CalculationMode.Price, newPrice);

            this method throws an exception of Error on calling 'OnBarUpdate' method on bar 24146: Index was outside the bounds of the array.

            Any idea?

            Comment


              #7
              Hello azh_ali,

              The code you are trying to use is not valid, ATM's can only be controlled by using the strategy ATM methods. To change a target you need to use the method AtmStrategyChangeStopTarget

              A strategy will need to submit the ATM so it has access to it and then you use the ID which you generated to access the ATM. This cannot be used to control ATM's that were not started by the strategy.

              https://developer.ninjatrader.com/do...angestoptarget
              JesseNinjaTrader Customer Service

              Comment


                #8
                Is it possible to call this method AtmStrategyChangeStopTarget​ in a indicator if you have the AtmStategy object?

                Comment


                  #9
                  Hello azh_ali,

                  No and indicator can only submit atms, there are no methods to control an atm in the same way as the strategy approach. Because the ATM is in control of the orders any changes to the orders made by a non atm method will result in the atm not knowing about the change which you could see the order be snapped back to its original value depending on the atm settings. The strategy approach is designed to inform the ATM of the change so it uses the new values and does not apply logic to the changed orders. A strategy is required to use that part of the framework.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi,

                    I am still not having luck with this.

                    I moved all my logic to atm and opening the order like this


                    isAtmStrategyCreated = false; // reset atm strategy created check to false
                    atmStrategyId = GetAtmStrategyUniqueId();
                    orderId = GetAtmStrategyUniqueId();
                    AtmStrategyCreate(action, OrderType.Market, limitp, 0, TimeInForce.Day, orderId, "MergeBig", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
                    //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
                    isAtmStrategyCreated = true;
                    });​

                    Opening of the order works.
                    AtmStrategyChangeStopTarget(0, newPrice, "Target1",atmStrategyId);

                    Now this doesn't error and I can see the order moving on the chart up and down but on the broker side, order is not changing the price. Price goes through the order limit price. Its like its not updating properly.

                    Comment


                      #11
                      this is on live NT brokerage account. it works fine on Sim account

                      Comment


                        #12
                        Hello azh_ali,

                        I would not be sure why the order would not change on the broker end, you may need to contact the brokerage and make sure they are seeing the order update events.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          I can't see the order update events in the NT log either but the Chart shows the Target order moving as price changes

                          Comment


                            #14
                            Hi,
                            Please help with this. I have been trying to solve this for weeks now.

                            I am using the same ATM and modified it to test it.

                            1 - I want to open an entry using ATM template, in this sample its called MergeBig it has 50 SL and 50 TP.
                            2 - I want to track the Target order based on the BB band lower or upper band price depending upon if its a BUY or SELL.
                            3 - In this sample, it tracks for the STOP1 order but doesn't do the same for TARGET1 order.

                            Any reason for that?

                            Please help
                            Attached Files

                            Comment


                              #15
                              Hello azh_ali,

                              In the attached file you have a target being placed to the lower band price when long, is the lower band price greater than the market price? A target would need to be placed above market price, if the order is less than the market price it will be ignored.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mbcito, Today, 03:31 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post mbcito
                              by mbcito
                               
                              Started by GerardCP, Yesterday, 02:45 PM
                              3 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by fincabayano, 02-08-2025, 05:58 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by shunsinger22, Yesterday, 11:47 AM
                              4 responses
                              24 views
                              0 likes
                              Last Post shunsinger22  
                              Started by moneymaster, Today, 03:19 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post moneymaster  
                              Working...
                              X