Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Order on ATM Strategy

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

    #16
    Originally posted by NinjaTrader_Josh View Post
    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
    Hi Josh - Is that for closing an open position or a pending order? I'm looking for a list of strings that will work with the AtmStrategyCancelEntryOrder call.

    I tried to use this at the beginning of the strat before AtmStrategyCreate instead:
    PHP Code:
     protected override void OnBarUpdate()
            {
                
    // HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies"

                // Make sure this strategy does not execute against historical data
                
    if (Historical)
                    return;
                
                
    // First, we need a simple entry. Then entryOrder == null checks to make sure entryOrder does not contain an order yet.

                
    if (Position.MarketPosition == MarketPosition.Flat)
                    
                if  (
    orderId.Length && Close[0] == limitPrice TickSize)
                    {
                    
    AtmStrategyCancelEntryOrder(orderId);
                    } 
    But I get an error saying "The name 'limitPrice' does not exist in the current context", same thing happens if I try and reference stopPrice instead.

    Those two params are the listed on http://www.ninjatrader-support.com/H...mStrategyClose. What could I reference instead of stopPrice or limitPrice?

    Comment


      #17
      Is that for closing an open position or a pending order?
      That method is to cancel an existing order, not close a position.

      I'm looking for a list of strings that will work with the AtmStrategyCancelEntryOrder call.
      There is not a list of strings available that will cancel the id.

      The value for orderId is populated using the following statement:
      string orderId = GetAtmStrategyUniqueId();

      But I get an error saying "The name 'limitPrice' does not exist in the current context", same thing happens if I try and reference stopPrice instead.
      These aren't built-in properties. They're user defined variables that could refer to anything. Please refer to Kentoes participation in this thread in posts 5, 6, 7 for a discussion on this. If you want to track this value, it will be with your own variables which should be properly defined in the variables region.
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_RyanM View Post
        That method is to cancel an existing order, not close a position.


        There is not a list of strings available that will cancel the id.

        The value for orderId is populated using the following statement:
        string orderId = GetAtmStrategyUniqueId();



        These aren't built-in properties. They're user defined variables that could refer to anything. Please refer to Kentoes participation in this thread in posts 5, 6, 7 for a discussion on this. If you want to track this value, it will be with your own variables which should be properly defined in the variables region.
        OK will take a closer look at 5,6 and 7. Thought stopPrice and limitPrice were built in as they were listed as parameters along with OrderID on the page http://www.ninjatrader-support.com/H...ml?CancelOrder .

        Trying to get this is proving most difficult but it must be excruciatingly painful for you trying to help people like me help themselves.


        Thanks,

        Gavin.

        Comment


          #19
          MrTicks,

          I'm happy to offer help here. Keep sharing your progress and we'll offer input. Hooking up a NinjaScript strategy to an ATM strategy is one of the more complex issues to deal with so it's expected to work through these types of things. At any point feel free to clarify your goals and we may be able to offer suggestions in a different direction.
          Ryan M.NinjaTrader Customer Service

          Comment


            #20
            Thanks, I'll keep at it. If I work it out, I'll post the code.

            Comment


              #21
              If I use:

              AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Stop, 0, High[5] + PrevBarsPlusTicks * TickSize, TimeInForce.Day, orderId, "FDAX_long", atmStrategyId);

              How could I pass that stop price the long order is looking for to a private int? What would the code look like?

              I think there are two ways to do it.
              1. if(Close[0]==private int + 8 && (status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
              {

              AtmStrategyCancelEntryOrder(orderId);
              atmStrategyId = string.Empty;
              orderId = string.Empty;


              or

              2. Place the following underneath AtmStrategyCreate

              if (orderId.Length > 0 && (Close[0] == Private int - 8 * TickSize))
              {
              AtmStrategyCancelEntryOrder(orderId);
              }


              Am I close? Calling a private int against current market price on the pending order? I'm not sure about the correct syntax for naming a stop price attached to pending order to reference, which method would be better or where to place it?
              Last edited by MrTicks; 07-16-2010, 02:28 AM. Reason: replacing incorrect Close[0} with correct Close[0]

              Comment


                #22
                Am getting there.

                If I could amend this:
                PHP Code:
                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)
                                {
                                    
                // Print out some information about the order to the output window
                                    
                Print("The entry order average fill price is: " status[0]);
                                    Print(
                "The entry order filled amount is: " status[1]);
                                    Print(
                "The entry order order state is: " status[2]);

                                    
                // 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 the strategy has terminated reset the strategy id
                            
                else if (atmStrategyId.Length && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                                
                atmStrategyId string.Empty; 
                to contain an else if with:

                PHP Code:
                if("current price == pending stop order + 8" && (status[2] == "Accepted" ||  status[2] == "Working" || status[2] == "Pending"))
                                {
                AtmStrategyCancelEntryOrder(orderId);
                                    
                atmStrategyId string.Empty;
                                    
                orderId string.Empty;
                                } 
                Then I could go to bed and get some sleep!

                Comment


                  #23
                  Think I found it in the public strategy called Woodies CCI Autrotrader submitted by snaphook. It has the code beginning on line 303,

                  PHP Code:
                  if(CurrentBar==entrybar-&& (status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
                                  
                                  {

                                      
                  AtmStrategyCancelEntryOrder(orderId);
                                      
                  atmStrategyId string.Empty;
                                      
                  orderId string.Empty;
                                  } 
                  I have a corresponding private int with:
                  private int entrybar;

                  My ATM strat has compiled OK so will test it on FDAX sim now.

                  Comment


                    #24
                    MrTicks, glad you got your amendments worked in - please let us know how your sim FDAX testing goes today.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #25
                      Will do. Have created a new problem for myself which I need to sort first though.

                      Comment


                        #26
                        Still needs work. Orders are not canceling. Code compiled OK though.

                        Comment


                          #27
                          Please provide complete code instead of snippets as it is becoming extremely difficult to know what state your code is in. Thank you.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #28
                            Am close, here is the relevant code. Will get it soon hopefully.

                            PHP Code:

                            #region Variables
                            private int entrybar;

                            // Check for a pending entry order
                                        
                            if (orderId.Length 0)
                                        {
                                            
                            string[] status GetAtmStrategyEntryOrderStatus(orderId);
                                            
                                            if(
                            CurrentBar==entrybar && (status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
                                            {
                                                Print(
                            "91   Cancelled Order");
                                                
                            AtmStrategyCancelEntryOrder(orderId);
                                                
                            atmStrategyId string.Empty;
                                                
                            orderId string.Empty;
                                            }
                                            
                                            
                            // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                                             
                            else if (status.GetLength(0) > 0)
                                            {
                                                
                            // Print out some information about the order to the output window
                                                
                            Print("The entry order average fill price is: " status[0]);
                                                Print(
                            "The entry order filled amount is: " status[1]);
                                                Print(
                            "The entry order order state is: " status[2]);

                                                
                            // 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 the strategy has terminated reset the strategy id
                                        //else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                                        //    atmStrategyId = string.Empty;
                                        
                                        
                            else 
                                        if (
                            atmStrategyId.Length && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
                                            {
                            Print(
                            "302   reset the strategy id");
                                            
                            atmStrategyId string.Empty;
                                            
                            orderId string.Empty;
                                            }


                                        if (
                            atmStrategyId.Length 0)
                                        {
                                            
                            // You can change the stop price
                                            //if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                                            //    AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

                                            // Print some information about the strategy to the output window
                                            
                            Print("The current ATM Strategy market position is: " GetAtmStrategyMarketPosition(atmStrategyId));
                                            Print(
                            "The current ATM Strategy position quantity is: " GetAtmStrategyPositionQuantity(atmStrategyId));
                                            Print(
                            "The current ATM Strategy average price is: " GetAtmStrategyPositionAveragePrice(atmStrategyId));
                                            Print(
                            "The current ATM Strategy Unrealized PnL is: " GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
                                            Print(
                            "The current ATM Strategy Realized PnL is: " GetAtmStrategyRealizedProfitLoss(atmStrategyId));
                                        }
                                    } 

                            Comment


                              #29
                              Originally posted by NinjaTrader_Josh View Post
                              Please provide complete code instead of snippets as it is becoming extremely difficult to know what state your code is in. Thank you.
                              OK, sorry.

                              PHP Code:
                              public class FDAXSATM Strategy
                                  
                              {
                                      
                              #region Variables
                                      
                                      
                              private string    atmStrategyId        string.Empty;
                                      private 
                              string    orderId                string.Empty;
                                      
                                      private 
                              int prevBarsMinusTicks 1// Default setting for PrevBarsPlusTicks
                                      
                                      
                              private int entrybar;
                                      
                                      
                              #endregion

                                      /// <summary>
                                      /// This method is used to configure the strategy and is called once before any strategy method is called.
                                      /// </summary>
                                      
                              protected override void Initialize()
                                      {
                                          
                              CalculateOnBarClose false;
                                      }
                                      
                                      
                              /// <summary>
                                      /// Called on each bar update event (incoming tick)
                                      /// </summary>
                                      
                              protected override void OnBarUpdate()
                                      {
                                         

                                          
                              // Make sure this strategy does not execute against historical data
                                          
                              if (Historical)
                                              return;


                                          
                              // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
                                          // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
                                          
                              if (Position.MarketPosition == MarketPosition.Flat && orderId.Length == && atmStrategyId.Length == 
                                              
                                              
                              && blah >= blah [3]
                                              && 
                              Low   [1] - PrevBarsMinusTicks TickSize GetCurrentAsk())
                                          
                                          
                                          {
                                              
                                              
                              int entrybar CurrentBar;
                                              
                              atmStrategyId GetAtmStrategyUniqueId();
                                              
                              orderId GetAtmStrategyUniqueId();
                                                             
                                              
                              AtmStrategyCreate(Cbi.OrderAction.SellOrderType.Stop0Low[1] - prevBarsMinusTicks TickSizeTimeInForce.DayorderId"FDAX_short_500T"atmStrategyId);

                                          }


                                          
                              // Check for a pending entry order
                                          
                              if (orderId.Length 0)
                                          {
                                              
                              string[] status GetAtmStrategyEntryOrderStatus(orderId);
                                              
                                              if(
                              CurrentBar==entrybar && (status[2] == "Accepted" || status[2] == "Working" || status[2] == "Pending"))
                                              {
                                                  Print(
                              "91   Cancelled Order");
                                                  
                              AtmStrategyCancelEntryOrder(orderId);
                                                  
                              atmStrategyId string.Empty;
                                                  
                              orderId string.Empty;
                                              }
                                              
                                              
                              // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                                               
                              else if (status.GetLength(0) > 0)
                                              {
                                                  
                              // Print out some information about the order to the output window
                                                  
                              Print("The entry order average fill price is: " status[0]);
                                                  Print(
                              "The entry order filled amount is: " status[1]);
                                                  Print(
                              "The entry order order state is: " status[2]);

                                                  
                              // 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 the strategy has terminated reset the strategy id
                                          //else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                                          //    atmStrategyId = string.Empty;
                                          
                                          
                              else 
                                          if (
                              atmStrategyId.Length && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
                                              {
                              Print(
                              "302   reset the strategy id");
                                              
                              atmStrategyId string.Empty;
                                              
                              orderId string.Empty;
                                              }


                                          if (
                              atmStrategyId.Length 0)
                                          {
                                              

                                              
                              // Print some information about the strategy to the output window
                                              
                              Print("The current ATM Strategy market position is: " GetAtmStrategyMarketPosition(atmStrategyId));
                                              Print(
                              "The current ATM Strategy position quantity is: " GetAtmStrategyPositionQuantity(atmStrategyId));
                                              Print(
                              "The current ATM Strategy average price is: " GetAtmStrategyPositionAveragePrice(atmStrategyId));
                                              Print(
                              "The current ATM Strategy Unrealized PnL is: " GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
                                              Print(
                              "The current ATM Strategy Realized PnL is: " GetAtmStrategyRealizedProfitLoss(atmStrategyId));
                                          }
                                      } 

                              Comment


                                #30
                                MrTicks,

                                Are you getting the Print results in your cancel code block?
                                Print("91 Cancelled Order");
                                Ryan M.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by alifarahani, Today, 09:40 AM
                                2 responses
                                12 views
                                0 likes
                                Last Post alifarahani  
                                Started by junkone, Today, 11:37 AM
                                3 responses
                                15 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by pickmyonlineclass, Today, 12:23 PM
                                0 responses
                                1 view
                                0 likes
                                Last Post pickmyonlineclass  
                                Started by frankthearm, Yesterday, 09:08 AM
                                12 responses
                                44 views
                                0 likes
                                Last Post NinjaTrader_Clayton  
                                Started by quantismo, 04-17-2024, 05:13 PM
                                5 responses
                                35 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X