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

1 Second Delay Between Orders

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

    1 Second Delay Between Orders

    I am implementing a strategy with 2 orders. They are currently sent at the same time and the broker (TDA) is able to manage the initial creation of the 2. When I need to close one or both of them and then enter the other direction, the broker gets confused by receiving the too much data at the same time. I would like to implement a one second delay between the orders. Do you know of a sample code set that I can use to accomplish this?
    Thanks!

    #2
    Hello cpabiz20k,

    Are you getting an error message when this happens?
    If so, what is the error message?

    Are you using the managed approach and attempting to call an exit and an entry on the same bar?


    You could wait until the next tick updates OnBarUpdate if you don't want to use a timer. However, I would not expect a 'Close position' and 'SellShort' order to be too many orders for TD Ameritrade.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      // Condition set 3...If we have not hit our Take Profit target and the candle changes,
      // exit and go the other way
      if (Position.MarketPosition == MarketPosition.Long
      && Close[1] > Close[0]
      && BarsSinceEntry() <= TakeProfitBars
      && (ToTime(Time[0]) >= TimeBegin
      && ToTime(Time[0]) < TimeEnd))
      {
      Print ("3: < TP, Reverse Long to Short");
      EnterShort(NumSharesA, "Regular Short A");
      EnterShort(NumSharesB, "Regular Short B");
      }

      This is the code I am using. In the description of EnterShort it says it will automatically close out any long that exists. I am wondering if adding an ExitLong() before the EnterShort would clear it and then allow it to process.

      There were no error commands, just a cancelled order response for the B shares. All 3 (exit, enter A, enter B) had the same time stamp, that is why I thought that adding a one second timer between them might be good to allow TDA to catch up.

      Comment


        #4
        Hello cpabiz20k,

        If the orders are not being rejected, it may not be an issue with TDA receiving the orders.

        Calling ExitLong() and EnterShort() on the same bar will cause the strategy to enter double in the opposite direction or will cause an overfill. This is detailed in the post I have linked in post #2.

        What is the exact issue?
        You mentioned there was a cancelled order response. Was there a cancellation request sent from NinjaTrader. Did the order enter a CancelPending state?

        Is the issue that an order was cancelled unexpectedly?

        You appear to be sending two entry orders at the same time. What is EntriesPerDirection set to in the strategy parameters?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello cpabiz20k,

          One thing I would suggest doing to discover why the close orders are causing issues would be to turn on TraceOrders.

          Code:
           [TABLE="border: 0, cellpadding: 0, cellspacing: 0"]
          [TR]
          [TD]protected override void Initialize()
          			{ 
          			    TraceOrders = true; 
          			}[/TD]
           		[/TR]
          [/TABLE]
          Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

          Here is a link to our help guide that goes into more detail on tracing orders:

          https://ninjatrader.com/support/helpGuides/nt7/traceorders2.htm

          As a side note, to amzounslide's comment, using BarsSinceEntry() (this is the correct syntax) would be an option to stagger the reversals by a bar or two:



          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by frankthearm, Today, 09:08 AM
          7 responses
          28 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by NRITV, Today, 01:15 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by maybeimnotrader, Yesterday, 05:46 PM
          5 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by quantismo, Yesterday, 05:13 PM
          2 responses
          16 views
          0 likes
          Last Post quantismo  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X