Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Order on ATM Strategy

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

    Cancel Order on ATM Strategy

    Hello,

    I am trying to use the AtmStrategyCancelEntryOrder method to cancel an limit order if the price moves 3 ticks away using the sample atm strategy.

    How do I reference the limit order using ATM strategy commands.
    I have previously used IORDER management. It looks something like this

    PHP Code:
    if (entryOrder1 != null && entryOrder1.LimitPrice != null && Close[0] == entryOrder1.LimitPrice TickSize)
     

    CancelOrder(entryOrder1);
     

    Thanks

    #2
    jthom, please take a look at the help guide document for AtmStrategyCancelEntryOrder() if you haven't already.

    Basically, you just have to pass in the orderId (the one used to create the ATM strategy) to the cancel method to cancel the entry order.
    Code:
    // create orderId
    string orderId = GetAtmStrategyUniqueId();
    
    // to create ATM strat, use this orderId
    AtmStrategyCreate(OrderAction action, OrderType orderType, double limitPrice, double stopPrice, TimeInForce timeInForce, string orderId, string strategyTemplateName, string AtmStrategyId)
    
    // then to cancel, use the same orderId  
    // AtmStrategyCancelEntryOrder(string orderId)
    AtmStrategyCancelEntryOrder(orderId);
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hey Austin,
      Thanks for the quick reply.
      I understand all that. Im having problems referencing if the price moves away more than 3 ticks to cancel.
      Do I use
      Close[0] == OrderType.Limit + 3 * TickSize

      Thanks

      Comment


        #4
        Hi there, sorry about misreading your first post. You will need to store the limit price you submit your ATM strategy for and then reference that value. As you may have noticed, ATM strategies are more or less on their own after they are created. Because of that, it can take a few extra steps to extract relevant information. I would think this is probably the easiest way to do it:
        Code:
        // get limit price and submit order
        double orderLimitPrice = whatever;
        AtmStrategyCreate(..., orderLimitPrice, orderId,...);
        
        // check order info
        string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");
         
        // Check length to ensure that returned array holds order information
        if (entryOrder.Length > 0)
        {
           Print("Average fill price is " + entryOrder[0].ToString());
           Print("Filled amount is " + entryOrder[1].ToString());
           Print("Current state is " + entryOrder[2].ToString());
        }
        
        // if order working and price is away, cancel order
        // not sure about the exact text returned from the order status method ("Working"), you'll have to double check
        if (entryOrder[2] == "Working" && Close[0] + 3 * TickSize < orderLimitPrice)
        {
           AtmStrategyCancelEntryOrder(orderId);
        }
        Here is the reference for GetAtmStrategyEntryOrderStatus().
        AustinNinjaTrader Customer Service

        Comment


          #5
          So once the ATM order is created, there is no way to programatically return the stop or limit price of that ATM?
          Last edited by Kentoes; 07-07-2010, 11:50 PM.

          Comment


            #6
            Originally posted by Kentoes View Post
            So once the ATM order is created, there is no way to programatically return the stop or limit price of that ATM?
            This is unfortunately correct Kentoes.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              This is unfortunately correct Kentoes.
              Okay, so if I just create a variable under public class/#region variables and update that value when I create the ATM, I'll have the stop price?

              Comment


                #8
                Correct Kentoes, you would need to keep track of the price yourself through a variable.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hey Austin,

                  Ive been trying every possible combination to get the code you posted to work. It places the order effectivelty. However it cancels the order almost instantly. Can you reference price action within the sting [] statement as I have below?
                  Here is the code ive got exactly:

                  PHP Code:
                  // Check for a pending entry order
                                  
                  if (orderId.Length 0)
                                  {
                                  
                  string[] status GetAtmStrategyEntryOrderStatus(orderId);
                   
                                  
                  // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                                  
                  if (status.GetLength(0) > 0)
                                  {
                   
                   
                                  
                  // If the order state is terminal, reset the order id value
                                  
                  if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                                          
                  orderId string.Empty;
                   
                   
                                  if ( 
                  status[2] == "Working" && Close[0] + TickSize orderLimitPrice)
                                      {
                                         
                  AtmStrategyCancelEntryOrder(orderId);
                                      } 
                  Last edited by jthom; 07-12-2010, 12:23 AM.

                  Comment


                    #10
                    aha,
                    I figured it out.
                    Close [0] + 3 * TickSize > LimitOrder.
                    This will not work at all. I had to add a smaller timeframe (eg: range 1), then reference that by:

                    PHP Code:
                    if BarsInProgress == 1
                     
                    if 
                    status[2] == "Working" && Close[0] == orderLimitPrice TickSize)
                    {
                    AtmStrategyCancelEntryOrder(orderId);



                    Many Thanks for helping in the right direction
                    Last edited by jthom; 07-12-2010, 01:27 AM.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Austin View Post
                      jthom, please take a look at the help guide document for AtmStrategyCancelEntryOrder() if you haven't already.

                      Basically, you just have to pass in the orderId (the one used to create the ATM strategy) to the cancel method to cancel the entry order.
                      Code:
                      // create orderId
                      string orderId = GetAtmStrategyUniqueId();
                      
                      // to create ATM strat, use this orderId
                      AtmStrategyCreate(OrderAction action, OrderType orderType, double limitPrice, double stopPrice, TimeInForce timeInForce, string orderId, string strategyTemplateName, string AtmStrategyId)
                      
                      // then to cancel, use the same orderId  
                      // AtmStrategyCancelEntryOrder(string orderId)
                      AtmStrategyCancelEntryOrder(orderId);
                      Hello - Do you have a sample strategy with AtmStrategyCancelEntryOrder working in it? Either one with cancel after n bars or cancel after n ticks +/- ?

                      I looked at http://www.ninjatrader.com/support/h...entryorder.htm but it doesn't have the private ints listed necessary to call the cancel command or the cancel criteria if statements in it.

                      Basically, I'm looking for a sample strat that has AtmStrategyCancelEntryOrder in it.


                      Thanks,

                      Gavin.

                      Comment


                        #12
                        Hello Gavin,

                        The closest sample we have to this is Using CancelOrder() method to cancel orders

                        You can use the same type of conditionals for the ATM strategy CancelOrder, although not all of the built in methods will apply here - BarsSinceEntry only applies to NinjaScript placed orders.

                        This page offers a sample implementation on tracking this value manually.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          Hello Gavin,

                          The closest sample we have to this is Using CancelOrder() method to cancel orders

                          You can use the same type of conditionals for the ATM strategy CancelOrder, although not all of the built in methods will apply here - BarsSinceEntry only applies to NinjaScript placed orders.

                          This page offers a sample implementation on tracking this value manually.
                          Hi Ryan,

                          Thanks for the links. I tried both of those methods already.

                          When I follow the sample from this page http://www.ninjatrader-support.com/H...ml?CancelOrder with the code
                          PHP Code:
                          myEntryOrder AtmStrategyCreate(Cbi.OrderAction.BuyOrderType.Stop0High[1] + PrevBarsPlusTicks TickSizeTimeInForce.DayorderId"FDAX_long_500T"atmStrategyId); 
                          I run into an error when compiling

                          Cannot implicitly convert type 'bool' to 'NinjaTrader.Cbi.IOrder'

                          Then, when I try and follow the example from the SampleCancelOrder strat I get the same error also. It doesn't like me trying to attach an int to the AtmStrategyCreate call.
                          I tried to attach
                          PHP Code:
                          entryOrder AtmStrategyCreate(Cbi.OrderAction.BuyOrderType.Stop0High[1] + PrevBarsPlusTicks TickSizeTimeInForce.DayorderId"FDAX_long_500T"atmStrategyId); 
                          I can see the logic in both examples you gave me but don't know how to get around the errors. Is there another way to attach an IOrder variable to the AtmStrategyCreate command?

                          The equivalent for those two examples you gave for ninjascript in order to cancel the order created by an ATM create call with AtmStrategyCreate call by ticks +/- * TickSize or BarsSinceEntry is my goal here.


                          Thanks,

                          Gavin.

                          Comment


                            #14
                            Gavin,

                            If you want to cancel an ATM strategy you would actually need to use this instead: http://www.ninjatrader-support.com/H...tegyClose.html
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Gavin,

                              I included the CancelOrder() link only because it offers an example at tracking the entry bar manually.

                              You capture the current bar at the time of entry and can then use (CurrentBar - savedCurrentBar) to find out the # of bars since entry.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X