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

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 bortz, 11-06-2023, 08:04 AM
          47 responses
          1,610 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          9 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          6 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          16 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X