Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Target Price

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

    Target Price

    Once an order is filled and a position taken, how do I retrieve the target price during run-time in my strategy?

    #2
    Hello,

    The best way to do this will be to assign your profit target order to an IOrder object as it is being submitted. However, you will not be able to accomplish this with SetStopLoss(), which I assume you are using. If you would like to check back on the state of the order, including it's stop/limit price, then you would be better served using one of the Exit methods, which you can assign to an IOrder object, like so:

    Code:
     Edited:       
    #region Variables
    
    		private IOrder profitTarget;
    		private IOrder entryOrder;
            #endregion
    
    
            protected override void OnBarUpdate()
            {
    			if(Close[0] > Close[1])
    			{
    			   entryOrder = EnterLong();
    			   profitTarget = ExitLongLimit(Close[0] + 10 * TickSize);
    			}
    			
    			Print(profitTarget.StopPrice);
            }
    Last edited by NinjaTrader_DaveI; 06-24-2015, 02:38 PM.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      I am trying to debug a problem where the fill price is different from what I expect. To place an order I use something like:
      Code:
      iOrderL2 = EnterLong(iQuantity1, sENTRY2L);
      which is followed by something like:
      Code:
      SetProfitTarget(sENTRY1L, CalculationMode.Price, targetPx);
      The price I see the order getting filled at (during market replay) is different from the value, targetPx. So, I'd like to check the profit setting of iOrderL2 before the fill.

      Comment


        #4
        Gotcha. The process outlined in my previous post will likely be the best solution to allow you to debug the code and see what values are being used.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Just to clarify:

          Are you saying that iOrderL2.StopPrice should equal targetPx?

          Code:
          iOrderL2 = EnterLong(iQuantity1, sENTRY2L);
          SetProfitTarget(sENTRY1L, CalculationMode.Price, targetPx);
          Print(iOrderL2 .StopPrice);      // equals targetPx?

          Comment


            #6
            Hello,

            Not exactly. What you are doing there is using SetStopLoss(), then checking the stop price of your entry order.

            You will need to assign your stop loss to an IOrder interface, just like you are doing with your entry. However, since we cannot assign the return value of SetStopLoss() to an IOrder interface, you would need to use one of the managed Exit methods instead (one quick note -- I used ExitLongStop() in my example below, but that would result in an order rejection due to the order being placed on the wrong side of the market, so you would want to use ExitLongLimit() instead).

            You can then check the limit price of that stop loss order. I've attached a working script that will show this in action, as well.
            Attached Files
            Dave I.NinjaTrader Product Management

            Comment


              #7
              You are saying use ExitLongLimit() instead of SetProfitTarget() since ExitLongLimit returns an IOrder interface. Then I can inspect profitTarget.LimitPrice which should equal targetPx.
              Am I following?

              Comment


                #8
                Exactly right. As long as you are passing in targetPx as the limit price for ExitLongLimit().
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  Except I want to use a market order and EnterLong() doesn't let me set a target.

                  Comment


                    #10
                    You would be using ExitLongLimit() as your target in this scenario. It would break down like this:

                    EnterLong() -- enter a position via a market order
                    ExitLongLimit() -- place a pending limit order that will act as your profit target

                    Then, you could even do an ExitLongStop() below the market to use as a stop loss. You have to remember that profit targets and stop losses are not order types, they are simply purposes for an order. So by placing a sell limit order via ExitLongLimit(), you are setting yourself up with a profit target.
                    Dave I.NinjaTrader Product Management

                    Comment


                      #11
                      Your code enters the market before setting the limit target is that a concern? I usually SetProfitTarget first.

                      Also, can you provide a more complete example using IOrder? Thanks.

                      Comment


                        #12
                        That should be fine in this instance. When placing stop losses and profit targets manually, it seems to be standard practice to place the entry order first.

                        You can find all of the properties associated with IOrder interfaces at the link below:

                        http://ninjatrader.com/support/helpG...t7/?iorder.htm

                        You can also see many real-world examples of using IOrders within the code snippets in help guide pages related to Unmanaged order-entry methods.
                        Dave I.NinjaTrader Product Management

                        Comment


                          #13
                          When I debug this code, t=0.0 and not tgtPx - what am I doing wrong?

                          Code:
                          iOrderL1 = EnterLong(iQuantity1, sENTRY1L);
                          ExitLongLimit(tgtPx, sENTRY1L);
                          double t = iOrderL1.LimitPrice;

                          Comment


                            #14
                            Originally posted by reynoldsn View Post
                            When I debug this code, t=0.0 and not tgtPx - what am I doing wrong?

                            Code:
                            iOrderL1 = EnterLong(iQuantity1, sENTRY1L);
                            ExitLongLimit(tgtPx, sENTRY1L);
                            double t = iOrderL1.LimitPrice;
                            In this scenario, that is exactly what t should equal. You are trying to access the limit price of a market order (EnterLong() submits market orders), so the LimitPrice property should either be null, or be holding a 0 as a placeholder. Please see the code examples in posts # 6 and 2 of this thread, as well as the IOrder help guide page in post # 12, for more information.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              I tried the code found in #2:

                              Code:
                              iOrderL1 = EnterLong(iQuantity1, sENTRY1L);
                              profitOrder = ExitLongLimit(tgtPx, sENTRY1L);
                              double t = profitOrder.LimitPrice; //profit target?
                              but profitOrder is null.

                              Again, all I'm trying to do is get the profit target of an order after it's been placed.

                              I appreciate your patience.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              23 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              26 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X