Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order of Conditions with OnBarUpdate

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

    Order of Conditions with OnBarUpdate

    Does the order of the conditions matter in OnBarUpdate. For example:

    Condition1 {EnterLong()}
    Condition2 {ExitLong()}
    Condition3 {EnterShort()}
    Condition4 {ExitShort()}

    With the above setup, I've noticed that my EnterShort command are often delayed one bar from when is expected, when both condition2 and condition3 are true. This means that the strategy ends up exiting a long position, but hesitating on the short





    #2
    Hello samish18,

    Thank you for your post.

    Yes, the order of the conditions does matter in OnBarUpdate(). The code will process the conditions from first to last.

    Please note is not recommended to call an enter and exit method on the same call of OnBarUpdate() as it will result in either the strategy position entering the opposite position with double the quantity or will result in an Overfill.

    An order with the name 'Close position' is automatically sent by NinjaTrader when calling an entry order in the opposite direction of the position.

    Calling an exit order and an entry order at the same time will result in 3 orders being submitted. The Exit order, the Close position order, and the Entry order.

    This will double the position in the opposite direction or cause an overfill. If this is your strategy you are programming, and if you are trying to reverse the position, call the entry in the opposite direction without calling an exit order.

    Please see this forum post for a detailed explanation:


    If you have any other questions, please let me know.​

    Comment


      #3
      Is it safe to have the structure:
      condition 1: enterLong()
      condition 2: entershort()
      condition 3: exitLong(); exitShort();​

      i.e. is it ok to call an exit order when there are currently no open positions?

      Comment


        #4
        Hello samish18,

        This depends entirely on the conditions themselves. If the 2 conditions become true that allow an enter and an exit method to be called on the same bar, this could cause issues as explained in my previous reply.

        If you call an exit order when there are no open positions you will also get an error explaining "There was an exit order but no position exists to exit".

        Please let us know if you have any further questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 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