Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator button to modify ATM Target

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

    Indicator button to modify ATM Target

    I currently have an indicator that can modify Stop1 order to BE of an ATM that has been placed on the Chart. I am trying to get another button to Modify the Target1 order to BE +1 is this possible, I have pasted the button 'code' below

    protected void myTargetBE(object sender, RoutedEventArgs e)
    {
    Account Acct = Account.All.FirstOrDefault(x => x.Name == xAlselector.SelectedAccount.ToString());
    Position thisPosition=Acct.Positions.FirstOrDefault(x => x.Instrument.FullName==Instrument.FullName) ;
    NinjaTrader.Cbi.Order myOrderToChange = null;
    foreach (Order order in Acct.Orders)
    {
    if(order.OrderType==OrderType.Limit || order.OrderType==OrderType.MIT)

    if(order.OrderState != OrderState.Cancelled & order.OrderState != OrderState.Filled)
    {
    if (order.Name=="Target1")
    {
    myOrderToChange.LimitPriceChanged = thisPosition.AveragePrice+ 1 * TickSize; // adjust to +1 ticks above entry price
    Acct.Change(new [] { myOrderToChange });
    }
    }


    }
    }

    #2
    Hello thepcmd,

    Yes, it would be possible to change the price of an order from a button click handler method.

    This is from a manually submitted entry that has an Atm Strategy attached?
    As a heads up, the Atm Strategy would continue running and would likely undo any price changes you make as it continues operating.

    Is there an issue or error you having you want assistance with?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Whenever I use the code above I get the following 'Unhandled exception: Object reference not set to an instance of the object.' That is what I am having issue with.

      Comment


        #4
        Hello thepcmd,

        The error is stating that a variable you are using has a null value.

        You can add prints above each line and look to see what the last print to appear is. The line of code below is likely the line causing the error.

        You can test each variable and check to see if it is null.

        For example:

        private Order myOrderToChange;

        if (myOrderToChange == null)
        {
        Print("myOrderToChange is null");
        }

        If you are not finding the order in the account Orders collection, print each order in the collection.
        Print(order.ToString());

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.


        What variable has a null value?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your input - I was able to resolve my issue

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          232 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          150 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          161 views
          1 like
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          243 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          198 views
          0 likes
          Last Post CarlTrading  
          Working...
          X