Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Cancel unfilled Auto order not working ..need help

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

    Cancel unfilled Auto order not working ..need help

    Hello,

    I am trying to cancel an unfilled entry order after 1 bar. Here is how I am trying to accomplish this (I'll spare you the if() conditions):

    if()
    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0] + -.1, 0, TimeInForce.Day, orderId, "133t Trail", atmStrategyId);
    DrawArrowUp("ZLR Long", 0, Low[0] - TickSize, Color.Lime);
    Print("The order triggered atmStrategyId# is: " + (atmStrategyId));
    Print("The order triggered orderId# is: " + (orderId));
    }

    // Cancel if order is not filled after close of entry bar
    if (atmStrategyId.Length > 0
    && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
    {
    AtmStrategyCancelEntryOrder("atmStrategyId");
    Print("Cancelling Unfilled ATM Entry #"+(atmStrategyId));
    }

    Here what the output window gives when an order didn't get filled:

    The order triggered atmStrategyId# is: d9e0f3914a974925974d28122e98f3a2
    The order triggered orderId# is: f23e4f7d1db64725989917b63131ff74
    The entry order average fill price is: 0
    The entry order filled amount is: 0
    The entry order order state is: Initialized
    Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
    The current ATM Strategy market position is: Flat
    The current ATM Strategy position quantity is: 0
    The current ATM Strategy average price is: 0
    The current ATM Strategy Unrealized PnL is: 0
    The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
    The entry order average fill price is: 0
    The entry order filled amount is: 0
    The entry order order state is: Working
    Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
    The current ATM Strategy market position is: Flat
    The current ATM Strategy position quantity is: 0
    The current ATM Strategy average price is: 0
    The current ATM Strategy Unrealized PnL is: 0
    The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
    The entry order average fill price is: 0
    The entry order filled amount is: 0
    The entry order order state is: Working

    ..and on and on as the entry order never gets cancelled and sits there trying to fill. What am I missing? Can someone point me in the right direction?

    Thanks.

    #2
    Always look in the Control Center log tab to see if there are any error/warning messages. I suspect you might see something like "OrderId does not exist".

    Try

    AtmStrategyCancelEntryOrder(orderId);
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks. I checked the log and sure enough I saw an error message:

      6/26/2007 10:52:26 AM Strategy AtmStrategyCancelEntryOrder() method error: orderId 'orderId' does not exist

      It seems that passing AtmStrategyCancelEntryOrder("orderId") with quotes was passing that text as opposed to the actual variable. So I changed it to just (orderId).

      So next I did a test to see if an order would actually be cancelled:

      6/26/2007 11:08:53 AM Order Submitting order with strategy id-f82f180169c245c9a5dbb4b717811ca1'
      6/26/2007 11:08:53 AM Strategy AtmStrategyCancelEntryOrder() method error: orderId '0f3ad1c6c2a1434f94e9e9a17bbfb80f' does not exist

      it seems that the unique values generated from:

      atmStrategyId = GetAtmStrategyUniqueId();
      orderId = GetAtmStrategyUniqueId();

      Differ from the strategy id of the sent order. Any ideas here?

      Comment


        #4
        Looks like you are in for a debug session.

        Add some Print() statements such as printing out the orderId at the time you place the order and then print out the orderId at the time you cancel to make sure they are in fact the same id value.
        RayNinjaTrader Customer Service

        Comment


          #5
          Ray,

          Thanks for the responses. Here is the order command:
          {
          atmStrategyId = GetAtmStrategyUniqueId();
          orderId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0] + -.1, 0, TimeInForce.Day, orderId, "133t Trail", atmStrategyId);
          DrawArrowUp("ZLR Long", 0, Low[0] - TickSize, Color.Lime);
          Print("The order triggered atmStrategyId# is: " + (atmStrategyId));
          Print("The order triggered orderId# is: " + (orderId));
          }

          The Id's printed differ from what's in the log. At the moment I don't know what else I could print that would be generating a different Id. As a workaround I used AtmStrategyClose():

          // Checks on bar update if any entry order has been filled or not. If not then cancel and reset strategy id.
          // Reset the strategy id here too for completed order from prior bar.

          if (atmStrategyId.Length > 0
          && GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
          {
          AtmStrategyClose(atmStrategyId);
          Print("Closing ATM Strategy #"+(atmStrategyId));
          atmStrategyId = string.Empty;
          Print("Resetting the atmStrategyId. Strategy Value is now: " +(atmStrategyId));
          }

          Comment


            #6
            You need to make sure that that you do not create a new orderId until after the order is filled or cancelled.
            RayNinjaTrader Customer Service

            Comment


              #7
              Ray,

              I have a print command everywhere there is a possible order command and Id reset command so if there was another Id being generated it should show up on the output window.

              Here is the output window on a non-filled order:

              The order triggered atmStrategyId# is: de4345459cb844b4a5032a55f855bcd9
              The order triggered orderId# is: 57e688f32e1f47c4873bb31feb87b9ed
              The entry order average fill price is: 0
              The entry order filled amount is: 0
              The entry order order state is: Initialized
              The current ATM Strategy market position is: Flat
              The current ATM Strategy position quantity is: 0
              The current ATM Strategy average price is: 0
              The current ATM Strategy Unrealized PnL is: 0
              The current ATM Strategy ID# is: de4345459cb844b4a5032a55f855bcd9
              Closing ATM Strategy #de4345459cb844b4a5032a55f855bcd9
              Resetting the atmStrategyId. Strategy Value is now:
              The entry order average fill price is: 0
              The entry order filled amount is: 0
              The entry order order state is: PendingCancel
              The entry order average fill price is: 0
              The entry order filled amount is: 0
              The entry order order state is: Cancelled
              The Order state is Cancelled resetting the order id value to:
              The strategy has terminated resetting the atmStrategyId. Strategy Value is now:

              The log shows:

              6/27/2007 6:02:24 AM Order Submitting order with strategy id-ceb7cb4840d24966bc8bbee45d58a9bd'
              6/27/2007 6:02:24 AM Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingSubmit Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02:24 AM Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Accepted Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Cancelled Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingCancel Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Strategy Cancelling any remaining strategy orders
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Working Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Accepted Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Strategy Auto chase price modification to '835.1'
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingChange Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
              6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Working Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

              The (atmStrategyID) and (orderId) being parsed from from the buy command is differing from the actual values in the log. No new orderId or strategy Id's are being created from the script.

              Any ideas?

              Comment


                #8
                Hi pdawg,

                No ideas here, you will have to debug your code. Attached is a sample strategy that demonstrates the creation and cancellation of an ATM entry order. Works as expected.

                You can import this strategy via File > Utilities > Import. Make sure you are on 6.0.1000.3 or higher. Also make sure you have an ATM strategy named "Test".
                Attached Files
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Ray,

                  Thanks for that. I will test it out let you know what I find.

                  Comment


                    #10
                    What about regular strategy entries? If I have an EnterLong() that I need canceled how do I go about achieving this?
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Simply don't resubmit the entry signal on next bar. Note: You can not explicitly cancel out strategy orders.

                      Comment


                        #12
                        Hmm. I thought the orders generated would be "working" till the end of the day or till canceled. I'm trying to enter a limit order to do some very quick momentum scalping, but if it does not meet my limit within say 10 seconds I don't want that order anymore because the scalpable gains are already. Should I look into ATM strategy to achieve this? Also what is the reason for not being able to cancel out of strategy orders?
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          The concept of NS orders (not ATM... methods, only regular NS signals) is that the orders are canceled out if you don't resubmit the signal with the next bar. This is the same concept as e.g. TS provides it.

                          However, by fall time frame we will provide an additional feature to fully control your orders (incl. explicit cancellation). Note: You then will not have the convenience of the current implementation. We'll publish details as we roll that release.

                          Comment


                            #14
                            Hi NinjaTarder Ray,

                            I'm trying to get one of my Atm Strategies to work with my one of my strategies. I'm trying to use the AtmTest.zip from a post below. I created a ATM Strategy named "Test" like you suggested. My question is about the "testStrategyIdValue" from the code below.
                            Is this a specfic value that I need to get from somewhere and enter in here like the strategy name or is it a strategy/computer generated value that enters by itself?
                            If I need to enter a IdValue in there myself and my strategy name was different, like "Test100", would that change that value to "test100StrategyIdValue"?

                            orderId = GetAtmStrategyUniqueId();
                            AtmStrategyCreate(Action.Buy, OrderType.Limit, GetCurrentBid() - 10 * TickSize, 0, TimeInForce.Day, orderId, "Test", "testStrategyIdValue");
                            orderPlaced = true;


                            or from the help file I found this under AtmStrategyCreate():

                            protected override void OnBarUpdate()
                            {
                            if (Historical)
                            return;

                            // Check for valid condition and create an ATM Strategy
                            if (Close[0] > SMA(20)[0])
                            AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,
                            TimeInForce.Day, GetATMStrategyUniqueId(), "MyTemplate",
                            GetAtmStrategyUniqueId());
                            }

                            Is this the same type of Atm Strataegy?


                            Thanks for your help

                            Comment


                              #15
                              "testStrategyIdValue" is just an ID which will identify your strategy for further calls to manage the ATM strategy. You may pick any unique ID in order to identify your strategy.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DawnTreader, 05-08-2024, 05:58 PM
                              10 responses
                              38 views
                              0 likes
                              Last Post DawnTreader  
                              Started by gaz0001, Today, 10:09 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post gaz0001
                              by gaz0001
                               
                              Started by proptradingshop, Today, 10:07 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post proptradingshop  
                              Started by franatas, Today, 09:49 AM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ZeroKuhl, Yesterday, 04:31 PM
                              6 responses
                              36 views
                              0 likes
                              Last Post ZeroKuhl  
                              Working...
                              X