• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit Orders vs. CancelOrder

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

    Limit Orders vs. CancelOrder

    Hi -

    I have a long/short strategy and on a signal the strategy creates a trade set. A trade set contains up to 7 to 8 trades long or short (mutually exclusive). The orders are a mix of market and limit orders.

    The problem I have is that my "limit orders" do not get canceled when there's a counter trade signal.

    For example,

    (1) On LONG signal submit 1x EnterLong(name, quantity) and 6 x EnterLongLimit(0, true, quantity, limit_price, name).

    (2) Market orders get filled, some limit orders do to. So far, so good.

    (3) On SHORT signal submit 1x EnterShort(name, quantity) and 7 x EnterShortLimit(0, true, quantity, limit_price, name).

    (4) Long positions close. 1 or more short signals get filled.

    (5) Long orders that didn't get filled in (1) get filled after (3).

    Here's an example of a test strategy to illustrate this problem:



    (6) Long orders with the prefix "Long_EP_60_x" were submitted with the trade set in step (1). I've tried canceling them but they don't show up in Orders.

    (7) I've looked into Foreach (Order o in Orders) {....} to see if I can trace but Orders.count ==0

    I'm stumped.

    If the strategy is LONG then SHORT, does NT automatically close all long positions and outstanding orders? It appears that way when I check Orders.count; however, on the chart and in the strategy report it appears that pending orders do not get canceled on a counter trade signal.

    Thank you
    Last edited by bigsurftrader; 03-13-2017, 06:36 AM.

    #2
    It appears I may have found the issue...

    Under "Advanced Order Handling", I see the following:

    "Each order method, such as EnterLongLimit(), has a method overload designed to submit a "live until canceled" order. When using this overload, it is important to retain a reference to the Order object, so that it can be canceled via CancelOrder() at a later time."

    I currently watch for events on OnExecutionUpdate() and even maintain my own Dictionary of trade orders. What i don't do is save a reference to the Order object after calling EnterLongLimit(....).

    If this work, then my next question is -- am I properly supplying the first input value to this function call?

    EnterLongLimit(0, true, quantity, limit_price, name)

    I'm a bit confused what I'm suppose to pass in there.

    Comment


      #3
      Hello bigsurftrader, and thank you for your question.

      It will be easier to answer questions about strategies not producing expected results if we could answer as many of the following questions as possible. Could you take a few minutes to review these questions? I am happy to explain further any of the below questions and the rationale behind asking them.


      • Do you see expected results when running the same test environment on the SampleMaCrossOver strategy in NinjaTrader with a 3 and 14 period?
        • By expected results, I mean that the SampleMACrossover places trades whenever a 3 and 14 period SMA cross
      • Who are you connected to? This is displayed in green on lower left corner of the Control Center window.
      • Are you connected to your data feed provider when running this test?
      • What instrument(s) (and expiry if applicable) have you selected?
      • What Data Series Type have you selected? Example: Tick, Minute, Day
      • What From and To date is selected?
      • Is your strategy a multi instrument or multi time frame strategy?
      • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Hi Jessica - thank you for the response.

        I've resolved my primary issue by assigning order = EnterLongLimit(...) or EnterShortLimit(...), and then referencing the order object later for cancellation. I'm uncertain if answering the remainder of your questions will help answer the following question.....(let me know if u need more info):

        My 2nd questions is "what is the 1st" input value (barsInProgressIndex)?

        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

        I've seen others use "0" for the input value...but not 100% sure why.

        Comment


          #5
          I am happy to help with this question. This is in relation to multi-timeframe strategies. I'll briefly go over these here but for more detailed information I recommend reviewing the help guide,

          http://ninjatrader.com/support/helpG...nstruments.htm

          A single NinjaScript strategy can trade more than one instrument, or more than one bar type for the primary instrument. Each traded instrument can use the primary bar type, or its own bar type. A code example which would add a 150 tick series for the primarily traded instrument would be

          Code:
          protected override void OnStateChange()
          {
              if (State == State.Configure)
              {
                  AddDataSeries(BarsPeriodType.Tick, 150);
              }
          }
          If you ran the above code, you would have two bar series in your code now :

          • Your primary bars series
            • For the sake of argument, let's say you selected ES 06-17 with 5 minute bars
          • Your secondary bars series
            • Building off the above example, these would be ES 06-17 150 tick bars

          The routine OnBarUpdate will be run for each of these bars series. This code


          Code:
          protected override void OnBarUpdate()
          {
              Print("BarsInProgress is now " + BarsInProgress);
          
          }

          will print "BarsInProgress is now 0" when your e.g. 5 minute bars call OnBarUpdate, and "BarsInProgress is now 1" when your 150 tick bars call OBU (OnBarUpdate).


          Let's say BIP (BarsInProgress) is 0, because you are on your e.g. 5 minute bars. Let's say though that you don't want to wait 5 minutes to place your trade. If, instead, you would like to place your trade when the next 150 tick bar closes, you can send 1 in as your first argument to e.g. EnterLong, so that this trade places when BIP = 1.
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Oh, I see. Thanks Jessica!!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pureblast2, Today, 10:44 PM
            0 responses
            2 views
            0 likes
            Last Post pureblast2  
            Started by ntbone, 07-13-2019, 11:37 PM
            10 responses
            28 views
            0 likes
            Last Post ntbone
            by ntbone
             
            Started by nicknamed, Today, 05:10 PM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by pstrusi, Today, 04:57 PM
            0 responses
            7 views
            0 likes
            Last Post pstrusi
            by pstrusi
             
            Started by williamzz, Today, 04:18 PM
            0 responses
            6 views
            0 likes
            Last Post williamzz  
            Working...
            X