Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeStopTarget gives intermittent method error

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

    AtmStrategyChangeStopTarget gives intermittent method error

    this line
    result = AtmStrategyChangeStopTarget(target, 0, "TARGET1", atmStrategyId);
    fails occasionally and gives message
    **NT** AtmStrategyChangeStopTarget() method error: OrderName 'TARGET1' does not exist
    just AFTER order is executed even though order state shows "Filled"
    and orderId.Length > 0.
    I think this is happening if there are multiple partial fills.
    Any ideas? Is it serious? What is the fix?

    #2
    Hello,

    Just to clarify -- it sounds like you are checking to see if TARGET1 is filled in OnOrderExecution() before trying to modify the ATM strategy. Am I reading that correctly? If so, then this would be expected, since if the ATM's profit target is filled, the position will have been closed, and the stop loss will have been canceled.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      No. Target will be reached many bars later after execution.
      I am not using OnOrderExecution.
      Instead i continually monitor orderId.Length on each tick.
      This error happens DIRECTLY after execution,
      that is to say, directly after orderId.Length > 0 and orderstate shows "Filled"
      The error also occurs with
      result = AtmStrategyChangeStopTarget(0, stop, "STOP1", atmStrategyId);
      but i left that out in the earlier post

      I change the stop and target directly after execution because the ATM template only has temporary values which i update once execution of the limit order has occurred.

      Comment


        #4
        There could be something going wrong due to the way that you are checking the order state. I highly recommend moving all of this logic to OnExecution(), so that you can actually perform these actions immediately after the entry order is filled. By leaving this logic in OnBarUpdate(), the order could have been filled much earlier than the first time that your code will recognize it, and it would only be a coincidence for you to detect the instant of the fill in this way, since OnBarUpdate() is not run until there is a new bar update, rather than at the precise moment of an execution.

        Also, can you please tell me what the temporary values of the ATM strategy bracket orders are? These may be causing some unexpected behavior, as well.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Thanks for your thoughts Dave.
          Your point about OnExecution vs OnBarUpdate is a good one.
          And while I do not want to argue with the expert, it would seem that OnbarUpdate can only be late. What might be happening is OnBarUpate occurs during a partial fill
          and this causes an error because the stop for that particular fill has not yet been allocated.
          So my question then would be does OnExecution event happen after all partial fills of a limit order are complete or do you get an event on every partial fill?

          The temporary placeholder stops in the ATM remplate are $5.00 for stocks (500 .01 ticks)
          for both target and stop. I change upon execution to values derived from an indicator.

          Comment


            #6
            Yes, you are correct that OnBarUpdate() could only be later (or coincidentally at the same moment), so the order should exist at the point you reference it in OnBarUpdate(), and with your initial bracket being placed so far away, it is highly unlikely for a profit target or stop loss to be filled before you check the entry order state.

            OnExecution does occur after a partial fill, but you could detect it using OrderState.PartFilled. So if you are seeing that OrderState == OrderState.Filled, then that would indicate that you have gotten a complete fill. You can see all of the possible order states
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Thanks for you help.

              Comment


                #8
                folow up partial fill AtmStrategyChnage

                Following up on the idea of OnExecution;
                The Help file shows
                // Example #1
                // Finding the executions of a particular IOrder object
                private IOrder entryOrder = null;

                protected override void OnBarUpdate()
                {
                if (entryOrder == null && Close[0] > Open[0])
                entryOrder = EnterLong();
                }
                How do I get an Iorder from ATMStrategyCreate since i am not using EnterLong() style of order placement?

                OR in this example:
                // Example #2
                // Generic execution logic not specific to a particular IOrder object
                protected override void OnExecution(IExecution execution)
                {
                // Remember to check the underlying IOrder object for null before trying to access its properties
                if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
                Print(execution.ToString());
                }
                do i get the same things I would expect from GetAtmStrategyEntryOrderStatus
                Put another way, where do i find all the returnable value names for "execution.".
                I don't have an Iorder available since I am not using that style of entry.


                Thanks.

                Comment


                  #9
                  That is a good point. You will not be able to check IOrder states using AtmStrategyCreate(). You would need to essentially set up your own ATM-style logic using managed or unmanaged order-entry methods. For example, a simple ATM-style setup could look something like this:

                  Code:
                  if(entryCondition)
                  {
                  	entryOrder = EnterLong();
                  	stopLoss = ExitLongStop(Low[0] - 10 * TickSize);
                  	stopLoss = ExitLongStop(
                  	profitTarget = ExitLongLimit(High[0] + 15 * TickSize);
                  }
                  With this approach, you would then have three IOrders to work with.

                  If you use the managed approach, as above, then you would also need to manually cancel the stop loss / profit target when one of them was filled. Alternatively, if you use the unmanaged approach (which I recommend), you will be able to set an OCO ID to handle the OCO functionality automatically.
                  Dave I.NinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  45 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  21 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X