Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Delayed by a Bar

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

    Order Delayed by a Bar

    Hi,
    Sorry to bother you (again), but I have a condition in an autostrategy that calls an ATM that I just can't figure out. I'm using 10 Minute bars.

    If a position enters and exits in the SAME bar, another full bar prints, and then another bar prints before the strategy places another order.

    BUT, if a position enters on one bar, then exits one or more bars later, the following bar initiates the next order (does not wait as in the first situation) like it should.

    I suspect it's an orderId issue. Shouldn't the orderId be reset to Empty once the bar closes, even though both entry and exit were in the same bar?

    I'm sure you will want to see the code so here it is (a version):

    if (ToTime(Time[0]) >= ToTime(7, 50, 0)
    && ToTime(Time[0]) <= ToTime(14, 0, 0)
    && orderId.Length == 0
    && atmStrategyId.Length == 0
    && Close[0] < Open[0])

    {
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Action.Sell, OrderType.Limit, Close[0], 0,
    TimeInForce.Day,orderId , "ATM Name",
    atmStrategyId);
    }

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


    Thanks,
    Joe

    #2
    Hello,

    I am not sure. I would have to play with it and debug it. I recommend Print()'ing out your order ID's just inside and outside the if conditions.

    You also may want to use TraceOrders to track your orders:


    Just in case you don't have this link already:
    DenNinjaTrader Customer Service

    Comment


      #3
      Thanks much Ben,
      I'll give it a go.
      Joe

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ETFVoyageur, Yesterday, 02:04 PM
      5 responses
      38 views
      0 likes
      Last Post ETFVoyageur  
      Started by Creamers, 04-27-2024, 05:32 AM
      6 responses
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by iceman2018, Today, 11:46 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Torontobluejays, Yesterday, 08:43 AM
      4 responses
      23 views
      0 likes
      Last Post Torontobluejays  
      Started by Ticks_66, Today, 09:50 AM
      2 responses
      14 views
      0 likes
      Last Post Ticks_66  
      Working...
      X