Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Move Chart trader Profit Targets

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

    Move Chart trader Profit Targets

    Is there a way that I can program a button to move my profit 'targets' to say Breakeven +1? I would like to do this if I feel the trade is not going to way I like and I just want to get out it it trades back to entry. I have the following that allows me to move the 'Stop1' to BE but I am looking to move the 'Target(s)'

    Thanks in Advance

    Account Acct = Account.All.FirstOrDefault(x => x.Name == xAlselector.SelectedAccount.ToString());
    Position thisPosition=Acct.Positions.FirstOrDefault(x => x.Instrument.FullName==Instrument.FullName) ;
    foreach (Order order in Acct.Orders)
    {
    if(order.OrderType==OrderType.StopMarket || order.OrderType==OrderType.StopLimit)
    {
    if(order.OrderState != OrderState.Cancelled & order.OrderState != OrderState.Filled)
    {
    if (order.Name=="Stop1")
    {
    thisPosition.BreakEven(new[] { order } ) ;
    }
    }
    }
    }

    #2
    Hello thepcmd,

    Thanks for your post.

    For a chart trader button example, please see this post by my colleague Chelsea: https://ninjatrader.com/support/foru...ions#post96376

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your response. I already have the buttons created and functional., I am looking for coding guidance for moving the target on an order. I already can move the Stop but cannot figure out the code for the Targets.

      Steve

      Comment


        #4
        Hello thepcmd,

        Thanks for your reply.

        I see you are using Position.BreakEven(), please note that this code is undocumented and unsupported and may be subject to change/removal in future versions of NinjaTrader..

        For changing orders, we recommend using documented Account.Change().

        Reference: https://ninjatrader.com/support/help...t8/?change.htm

        You can trigger from your button click.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          OK, I can change my stops, but that did not answer the original question. I am looking to move the targets and all the examples you have shown deal with stops.

          Can the Targets be moved and are there examples either in the manual or in the forum to show this?

          Comment


            #6
            Hello thepcmd,

            Thanks for your reply.

            Yes, the targets would be moved and in the same way.

            Sorry, I am not aware of any specific examples to point you to.


            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Can you at least list the variables - Like in an ATM Strategy you have 'Target 1', 'Target 2' and so on.

              Steve

              Comment


                #8
                Hello Steve,

                Thanks for your reply.

                Here is an example:

                protected void Button1Click(object sender, RoutedEventArgs e)
                {
                // A button click is a custom event, that is not on a data processing event. BarsAgo references will not work without it, so it is included if BarsAgo references are needed here.
                TriggerCustomEvent(o =>
                {
                if (account == null)
                return;

                // Create an order and find it on the account
                NinjaTrader.Cbi.Order myOrderToChange = null;

                foreach (NinjaTrader.Cbi.Order order in account.Orders)
                {
                if (order.Name == "Target1" && order.Instrument == Instrument)
                {
                myOrderToChange = order;
                }
                }

                // Create a Position and find it on the account
                NinjaTrader.Cbi.Position thisPosition = null;

                foreach (NinjaTrader.Cbi.Position position in account.Positions)
                {
                if (position.Instrument == Instrument)
                {
                thisPosition = position;
                }
                }

                // If we found a position and order, change the order.
                if (myOrderToChange != null && thisPosition != null)
                {
                // change LimitPriceChanged
                myOrderToChange.LimitPriceChanged = thisPosition.AveragePrice+ 8 * TickSize; // adjust to +8 ticks above entry price

                // send it to account.Change
                account.Change(new [] { myOrderToChange });
                }
                }, null);


                Draw.TextFixed(this, "infobox", "Button 1 Clicked", TextPosition.BottomLeft, Brushes.Green, new Gui.Tools.SimpleFont("Arial", 25), Brushes.Transparent, Brushes.Transparent, 100);
                // refresh the chart so that the text box will appear on the next render pass even if there is no incoming data
                ForceRefresh();

                }
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by raffu, Yesterday, 11:41 AM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cmtjoancolmenero, Yesterday, 11:56 AM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by reynoldsn, 04-21-2024, 07:53 PM
                3 responses
                25 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by cmtjoancolmenero, Yesterday, 03:40 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by ageeholdings, 04-28-2024, 07:43 AM
                2 responses
                24 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X