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.
        https://ninjatrader.com/support/foru...121#post791121

        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 fafafdenis, Today, 04:56 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by pjsmith, 07-18-2019, 04:21 AM
          7 responses
          249 views
          0 likes
          Last Post aligator  
          Started by ark321, Today, 05:12 PM
          0 responses
          11 views
          0 likes
          Last Post ark321
          by ark321
           
          Started by futurenow, Today, 04:49 PM
          0 responses
          9 views
          0 likes
          Last Post futurenow  
          Started by ofer1964spivak, Today, 04:27 PM
          0 responses
          5 views
          0 likes
          Last Post ofer1964spivak  
          Working...
          X