Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A matter of timing?

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

    A matter of timing?


    NT Support Super Dudes, I'd like to check if I'm encountering an unexpected issue of timing. My code is something like:

    Calculate = Calculate.OnPriceChange;
    OnBarUpdate()
    if (entryOrder = null and some condition) entryorder = EnterLong()
    if (entryOrder != null and some condition) entryorder = ExitLong()


    OnOrderUpdate()
    if (Order.IsTerminalState(order.OrderState)) entryOrder = null;
    else entryOrder = order;


    When I run this in backtest, no problem. When I run on a live market, both the EnterLong and ExitLong get hit multiple times in a row, like 2-5 times. I'm guessing that's because, after the EnterLong or ExitLong is called, it takes a moment for the order execution. Therefore, the update to the entryOrder value is delayed. Essentially, I go through the loop again before entryOrder is updated, so I end up repeating under the previous conditions.

    Would this seem right to you? If so, any thoughts on how to address?

    Thanks,



    #2
    Hello timmbbo,

    In backtest, may I confirm that you have TickReplay enabled to allow Calculate to update for each price change and a 1 tick series is added and orders are placed to the 1 tick series for intra-bar granularity? (Other wise the script will be running with Calculate.OnBarClose)


    Yes, it does take a small amount of time for the order to be submitted, accepted, working, filled, and then for the message the order was filled to be sent back to ninjatrader, and then for the execution to be processed and update OnOrderUpdate(). However, with Calculate.OnPriceChange I would expect a market order to fill before the next bar update.
    Printing the information above the condition and from OnOrderUpdate() to the output window would let you know for sure.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by timmbbo View Post
      if (entryOrder = null and some condition) ...
      Just to confirm, the above = should really be ==, like this,

      if (entryOrder == null and some condition) ...

      Right?

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      127 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X