Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange Profit Targets

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

    Strange Profit Targets

    I have been testing a strategy for quite a while now that uses the following code:

    Code:
            protected override void Initialize()
            {
    			SetStopLoss(sENTRY1L, CalculationMode.Ticks, 6, false);
    			SetProfitTarget(sENTRY1L, CalculationMode.Ticks, 4);
    ........
    }
    In my testing, I have never had an issue with the "StopLoss" or "Target". However, I have given my strategy to a friend and his targets are messed up. Instead of using target = 4, sometimes it gets out after 3 ticks or even 1 tick. It's bizarre. Is there another way I should be specifying stop and target?

    #2
    Hi Scott,

    There's no reason to expect a profit target to fill at a different tick level than you specify. Please have your friend email the strategy and steps to see this to support 'at' ninjatrader 'dot' com. Include a link to this thread.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      OK, I have narrowed the problem down - the strategy ALWAYS uses limit orders and yet when I look at my friend's "Orders tab", the strategy is sometimes taking market orders! What I see is say a long limit order filled and then a few seconds later sold at market price. Under what scenario would this happen? I do have CancelOrder logic in case price moves far enough and an order is not yet filled but I wouldn't think that CancelOrder would interfere with positions - correct?

      Comment


        #4
        Unfortunately I'm not sure what would explain your results. If you have some screenshots you can post that show the problem you're seeing, it will be helpful. If it's only seen on your friends computer, can you please encourage him to write us directly.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK, let me ask this. Suppose CancelOrder is called on an open position which really doesn't make sense but suppose it gets called. Would CancelOrder affect the open position in any way?

          Comment


            #6
            CancelOrder() accepts an IOrder object representing an order. It cannot be called on an open position. If you call CancelOrder on an order that is not available, then there will likely be an error message "Object reference not set to an instance of an object" in both TraceOrders output and log tab of control center.

            We're happy to help work through strategy items you're having trouble with. The best way for us to do so is if you provide some code snippets, example sequences, messages you aren't sure about or screenshot evidence of any issues you're seeing.
            Last edited by NinjaTrader_RyanM1; 11-17-2011, 01:02 PM.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Here is some code:

              Code:
              protected override void Initialize()
              {						
                  SetProfitTarget(sENTRY1L, CalculationMode.Ticks, ProfitTarget);
                  SetProfitTarget(sENTRY1S, CalculationMode.Ticks, ProfitTarget);
                  SetStopLoss(CalculationMode.Ticks, StopLoss);
              			
                  EntriesPerDirection=1;
                  EntryHandling = EntryHandling.UniqueEntries;
              
                  CalculateOnBarClose = true;
              			
                  //Exit On Close
                  ExitOnClose = false;
                  //Error Handling in event of "Rejected Order"
                  //RealtimeErrorHandling = RealtimeErrorHandling.StopStrategyCancelOrdersClosePosition; (Default)
                  RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
                  //Trace Orders to LOG
                  TraceOrders = true;
              			
                  //Init Connections
                  dStatus = ConnectionStatus.Connected;
                  oStatus = ConnectionStatus.Connected;
              
                  //Init order objects
                  iOrderL1 = null;
                  iOrderS1 = null;				
              }
              Here is the order part to go long (order type is set to BID_ASK):

              Code:
              if (((TakeHistorical && Historical) || !Historical)) {
              								
              	if (iOrderType == eOrderType.MARKET) {
              		iOrderL1 = EnterLong(iQuantity1, sENTRY1L);
              	}
              	else if (iOrderType == eOrderType.BID_ASK) {
              		tVars.lEntry = GetCurrentBid();
              		iOrderL1 = EnterLongLimit(0, true, iQuantity1, tVars.lEntry, sENTRY1L);
              	}
              	else if (iOrderType == eOrderType.LIMIT) {
              		tVars.lEntry = Close[0] - iLimitOffsetTicks * TickSize;
              		iOrderL1 = EnterLongLimit(0, true, iQuantity1, tVars.lEntry, sENTRY1L);
              	}
              }
              Here is the OnExecution part:

              Code:
              protected override void OnExecution(IExecution execution)
              {
                  #region orderL1
                  if (iOrderL1 != null)
                  {
                      if (iOrderL1.Token == execution.Order.Token)
                      {
                          //-----------------------------------------------------
                          // PENDING ORDERS (PendingSubmit / Working / Accepted)
                          //-----------------------------------------------------
                          if (
                                  execution.Order.OrderState == OrderState.PendingSubmit ||
                                  execution.Order.OrderState == OrderState.Working ||
                                  execution.Order.OrderState == OrderState.Accepted
                              )
                          {
                              //Log This
                              ////LogFile.LogToFile(Historical, "OnExecution  : Long - Orderstate PendingSubmit / Working / Accepted", true);
                          }
              
                          //----------------------------
                          // Filled Order Response?
                          //----------------------------
                          if (execution.Order.OrderState == OrderState.Filled)
                          {
                              //clear the order variable
                              iOrderL1 = null;
                          }
              
                          //----------------------------
                          //Rejected Long Order?
                          //----------------------------
                          if (execution.Order.OrderState == OrderState.Rejected)
                          {
                              //clear the order variable
                              iOrderL1 = null;
                              //Log This
                              ////LogFile.LogToFile(Historical, "OnExecution  : Long - Rejected", true);
                          }
                      }
                  }
                  #endregion			
                  #region orderS1
                  if (iOrderS1 != null)
                  {
                      if (iOrderS1.Token == execution.Order.Token)
                      {
                          //-----------------------------------------------------
                          // PENDING ORDERS (PendingSubmit / Working / Accepted)
                          //-----------------------------------------------------
                          if (
                                  execution.Order.OrderState == OrderState.PendingSubmit ||
                                  execution.Order.OrderState == OrderState.Working ||
                                  execution.Order.OrderState == OrderState.Accepted
                              )
                          {
                          }
              
                          //----------------------------
                          // Filled Order Response?
                          //----------------------------
                          if (execution.Order.OrderState == OrderState.Filled)
                          {
                              //clear the order variable
                              iOrderS1 = null;
                          }
              
                          //----------------------------
                          //Rejected Long Order?
                          //----------------------------
                          if (execution.Order.OrderState == OrderState.Rejected)
                          {
                              //clear the order variable
                              iOrderS1 = null;
                              //Log This
                              //LogFile.LogToFile(Historical, "OnExecution  : Short - Rejected", true);
                          }
                      }
                  }
                  #endregion		
              }

              Comment


                #8
                Great, Thanks for including the code snippet. Can you also please include the following details that will allow us to reproduce what you're seeing.
                1) The steps needed to see.
                2) Your expectations of behavior based on the strategy and steps.

                For # 1 you can attach a screenshot of the strategy settings. For #2 this is just to find out what you are expecting and where the results deviate from your expectations.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  OK, pls see attachments for settings and my friends trades.

                  He has two trades. You can clearly see the targets are wrong, being filled at +1 tick and -3 ticks. But notice the settings are +4 profit target and -6 stop loss. And notice the setting is BID_ASK for order type.

                  Notice on his order tab, there are MARKET orders.
                  Attached Files

                  Comment


                    #10
                    Are you sure he's running the strategy you posted? I don't see any connection with the signal names and the screenshot you posted, and the name provided for set orders is always "Profit Target" and "Stop Loss", never "Sell". At this point, there is no need for you to be in the middle between NT support and your friend. Please have him email support 'at' ninjatrader 'dot' com and we'll arrange a time where I can take a look at things over remote assistance.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by scottreynolds View Post
                      OK, I have narrowed the problem down - the strategy ALWAYS uses limit orders and yet when I look at my friend's "Orders tab", the strategy is sometimes taking market orders! What I see is say a long limit order filled and then a few seconds later sold at market price. Under what scenario would this happen? I do have CancelOrder logic in case price moves far enough and an order is not yet filled but I wouldn't think that CancelOrder would interfere with positions - correct?
                      Are you resetting your StopLoss when you go flat ?

                      Comment


                        #12
                        koganam,

                        No I don't reset StopLoss when flat - is that necessary? Why?

                        Comment


                          #13
                          Yes Scott, that would be needed as otherwise the script may use a legacy stop price in it's calcs : http://www.ninjatrader.com/support/f...ead.php?t=3222

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          647 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          369 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          108 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          572 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          573 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X