Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM cancel order and change entryorder

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

    ATM cancel order and change entryorder

    hi,
    im using SampleAtmStrategy to develope my strategy with ATM. the Sample is working fine but i need to set my logic, and cancel or change entryorder price.

    i have tested with the code in ninjatrader help but dont get cancel or change orders.
    Can you help me ? thanks

    AtmStrategyChangeEntryOrder(GetCurrentBid(), 0, "orderIdValue");

    // ATM strategy methods only work during real-time
    if (State != State.Realtime)
    return;

    string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");

    // checks if the entry order exists
    // and the order state is not already cancelled/filled/rejected
    if (entryOrder.Length > 0 && entryOrder[2] == "Working")
    {
    AtmStrategyCancelEntryOrder("orderId");
    }

    #2
    Hello manueldecastro,

    There may be some confusion on the atmStrategyId and the orderId.

    These should be generated IDs. IDs can be generated with GetAtmStrategyUniqueId().

    These IDs are how the specific instance of the Atm that is active is selected to be modified.

    See lines 62 and 63 in the SampleAtmStrategy that is distributed with NinjaTrader for example code of generating IDs.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      I really don't understand very well how the cancel order works and modify the entry price with atm from the example.
      To simplify what I need, in pseudocode, I look for a color change in range candles

      if (close [0]> open [0] && close [1] <open [1])
      {entryprice = open [0] candleX = currentbar} if (currentbar> candleX + 5) {CancelATMorder}

      or option 2 if (currentbar> candleX + 5) {entryprice = low [0]} // the entry order is chasing the price until is crossed.

      These options are normally performed in strategies in which I do not use ATM but I have the problem that if I do not use ATM I cannot move the target and stop orders manually.

      thanks!

      Comment


        #4
        Hello manueldecastro,

        The way AtmStrategyChangeEntryOrder works is by supplying an id to identify the atm instance, then the entry associated with that atm instance will have a change order with the updated price supplied.

        Atm Strategies placed manually cannot use chart bar information like Close[0].

        Exit orders, such as ExitLongStopMarket, can be moved manually when using isLiveUntilCancelled as true and only calling the order method when submitting the order or changing the price (and not on every bar update).

        Below is a link to an example called ProfitChaseStopTrailExitOrdersExample_NT8.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          hi
          what i need is something like this;

          protected override void OnBarUpdate()
          {
          // ATM strategy methods only work during real-time
          if (State != State.Realtime)
          return;

          string[] entryOrder = GetAtmStrategyEntryOrderStatus("orde rId");

          // checks if the entry order exists
          // and the order state is not already cancelled/filled/rejected
          if (entryOrder.Length > 0 && entryOrder[2] == "Working")
          {
          AtmStrategyCancelEntryOrder("orderId");
          }
          }

          to apply to my logic

          if (close [0]> open [0] && close [1] <open [1])
          {entryprice = open [0] candleX = currentbar} // here atm is placed
          if (currentbar> candleX + 5) if i got 5 candles without fill, cancel atmorder
          {CancelATMorder}

          Comment


            #6
            Hello manueldecastro,

            string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");

            "orderId" with quotes is a string not a variable.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by manueldecastro View Post
              hi
              what i need is something like this;

              protected override void OnBarUpdate()
              {
              // ATM strategy methods only work during real-time
              if (State != State.Realtime)
              return;

              string[] entryOrder = GetAtmStrategyEntryOrderStatus("orde rId");

              // checks if the entry order exists
              // and the order state is not already cancelled/filled/rejected
              if (entryOrder.Length > 0 && entryOrder[2] == "Working")
              {
              AtmStrategyCancelEntryOrder("orderId");
              }
              }

              to apply to my logic

              if (close [0]> open [0] && close [1] <open [1])
              {entryprice = open [0] candleX = currentbar} // here atm is placed
              if (currentbar> candleX + 5) if i got 5 candles without fill, cancel atmorder
              {CancelATMorder}
              in the example code appears with quotes ;

              protected override void OnBarUpdate()
              {
              // ATM strategy methods only work during real-time
              if (State != State.Realtime)
              return;

              string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");

              // checks if the entry order exists
              // and the order state is not already cancelled/filled/rejected
              if (entryOrder.Length > 0 && entryOrder[2] == "Working")
              {
              AtmStrategyCancelEntryOrder("orderId");
              }
              }


              Comment


                #8
                Hello manueldecastro,

                This may indicate that the SampleAtmStrategy example provided with NinjaTrader has been modified from its original version.

                A screenshot is attached showing the code in the original example.

                To reset this to the original code, please run the repair from the NinjaTrader installer.
                1. Shutdown NinjaTrader
                2. Download the NinjaTrader installation package from the link below
                3. http://ninjatrader.com/GetStarted
                4. Run the repair from this (or update to the latest version) (if the repair is unsuccessful, uninstall and then re-install NinjaTrader)
                After this the SampleAtmStrategy should be reverted back to the original code.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello NinjaTrader_ChelseaB,

                  What's the new URL for this?
                  // HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies" under NinjaScript--> Educational Resources--> http://ninjatrader.com/support/helpG...strategies.htm

                  Comment


                    #10
                    NinjaTrader_ChelseaB do you have a sample showing ATM changing order from strategy?
                    The ATM is executed from the ChartTrader panel, not from a script.

                    I need to modify this to use inside a strategy script not an indicator script with the ChartTrader panel executed ATM:

                    Code:
                            #region MOVESL METHODS
                            
                                private void MoveSL (int Ticks)
                                {
                                    xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
                                    string currentAccount = xAlselector.SelectedAccount.ToString();
                                    
                                    Account Acct = Account.All.FirstOrDefault(x => currentAccount.Contains(x.Name));
                                    
                                    xInSelector = Window.GetWindow(ChartControl.OwnerChart).FindFirst("ChartWindowInstrumentSelector") as NinjaTrader.Gui.Tools.InstrumentSelector;
                                    string currentInstrument =    xInSelector.Instrument.ToString();
                                    
                                    Position thisPosition=Acct.Positions.FirstOrDefault(x => currentInstrument.Contains(x.Instrument.FullName));
                                    foreach (Order order in Acct.Orders)
                                    {
                                        if (thisPosition.Account == order.Account && thisPosition.Instrument == order.Instrument)
                                        {
                                            if(order.OrderType==OrderType.StopMarket || order.OrderType==OrderType.StopLimit)
                                            {                
                                                if(order.OrderState != OrderState.Cancelled & order.OrderState != OrderState.Filled)
                                                {        
                                                    Order stopOrder=order;
                                                    if (thisPosition.MarketPosition.ToString() == "Short")
                                                    {
                                                        stopOrder.StopPriceChanged = order.StopPrice - Ticks * order.Instrument.MasterInstrument.TickSize;
                                                        ChangeOrder(stopOrder, stopOrder.Quantity, 0, 0);
                                                    }
                                                    if (thisPosition.MarketPosition.ToString() == "Long")
                                                    {
                                                        stopOrder.StopPriceChanged = order.StopPrice + Ticks * order.Instrument.MasterInstrument.TickSize;
                                                        ChangeOrder(stopOrder, stopOrder.Quantity, 0, 0);
                                                    }
                                                    #region CANCEL ORDER
                                                        /*
                                                        if (thisPosition.MarketPosition.ToString() == "Flat")
                                                        {
                                                            CancelOrder( stopOrder );
                                                        }
                                                        */
                                                    #endregion
                                                }
                                            }        
                                        }
                                    }        
                                }
                                
                            #endregion​

                    I tested the original code below and it works, but I'd like to do the same with ATM Strategy code for testing purposes.

                    Code:
                    
                            
                            #region MOVESL METHODS
                            
                                private void MoveSL (int Ticks)
                                {
                                    xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
                                    string currentAccount = xAlselector.SelectedAccount.ToString();
                                    
                                    Account Acct = Account.All.FirstOrDefault(x => currentAccount.Contains(x.Name));
                                    
                                    xInSelector = Window.GetWindow(ChartControl.OwnerChart).FindFirst("ChartWindowInstrumentSelector") as NinjaTrader.Gui.Tools.InstrumentSelector;
                                    string currentInstrument =    xInSelector.Instrument.ToString();
                                    
                                    Position thisPosition=Acct.Positions.FirstOrDefault(x => currentInstrument.Contains(x.Instrument.FullName));
                                    foreach (Order order in Acct.Orders)
                                    {
                                        if (thisPosition.Account == order.Account && thisPosition.Instrument == order.Instrument)
                                        {
                                            if(order.OrderType==OrderType.StopMarket || order.OrderType==OrderType.StopLimit)
                                            {                
                                                if(order.OrderState != OrderState.Cancelled & order.OrderState != OrderState.Filled)
                                                {        
                                                    Order stopOrder=order;
                                                    if (thisPosition.MarketPosition.ToString() == "Short")
                                                    {
                                                        stopOrder.StopPriceChanged = order.StopPrice - Ticks * order.Instrument.MasterInstrument.TickSize;
                                                        Acct.Change(new[] { stopOrder });
                                                    }
                                                    if (thisPosition.MarketPosition.ToString() == "Long")
                                                    {
                                                        stopOrder.StopPriceChanged = order.StopPrice + Ticks * order.Instrument.MasterInstrument.TickSize;
                                                        Acct.Change(new[] { stopOrder });
                                                    }
                                                    #region CANCEL ORDER
                                                        /*
                                                        if (thisPosition.MarketPosition.ToString() == "Flat")
                                                        {
                                                              Acct.Cancel(new[] { stopOrder });
                                                        }
                                                        */
                                                    #endregion
                                                }
                                            }        
                                        }
                                    }        
                                }
                                
                            #endregion​
                    Last edited by PaulMohn; 08-04-2024, 04:55 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    56 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    133 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X