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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          63 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          92 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          48 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          106 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          63 views
          0 likes
          Last Post PaulMohn  
          Working...
          X