Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is Last Tick?

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

    Is Last Tick?

    I see Ninjascript has a property available, 'IsFirstTickOfBar', to check if it's the first tick of a new bar.

    I have Calculate = Calculate.OnEachTick, but noticed that when I had it set to end of bar, that IsFirstTickOfBar was true when it was iterating through historical processing at the end of each bar.

    But I am wondering if there is some way to check if it is the last tick of the bar, while still using OnEachTick (and tick replay for historical)?

    #2
    Hello DerkWehler,

    Historical data is processed OnBarClose so there is no last tick, the IsFirstTickOfBar is true because the bar is both the first tick and the bar close.

    There is otherwise no property for realtime use that is for the last tick, the last tick of a bar would have to be accessed on the first tick of the next bar which is the tick that closed the previous bar.

    Comment


      #3
      Okay, thank you. Follow up question then:

      I have a strategy where I want to close the open trade at the end of a bar and open another one on the first tick of the new bar. Using the managed approach, can I just send the exit call and the entry call back-to-back and trust that the order processing thread will do them sequentially, asap?

      Comment


        #4
        Hello DerkWehler,

        If you are using a specific tick series you could try using an int counter to count OnBarUpdate events to submit the order before the end of the bar however for historical tests using OnBarClose processing that won't work. You would not be able to submit both orders on the first tick of the bar because that is the tick which closes the bar so the orders would end up getting sent at the same time. If the point is a reversal you don't need to submit an exit, you can simply call the opposite entry condition on the first tick of the bar and that will close and reverse the position.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          If the point is a reversal you don't need to submit an exit, you can simply call the opposite entry condition on the first tick of the bar and that will close and reverse the position.
          No, I actually need to closed the order and open another in the same direction. What do you recommend for that?

          Comment


            #6
            Hello DerkWehler,

            In that case you would have to submit the exit at some point, with at least one or more OnBarUpdate event between them. The Position won't be immediately updated just by submitting the order, in realtime that will take at least 1 OBU event to get a response back to toggle the position. You likely would need to submit the exit at least a few ticks before the end of the bar so you have time for the platform to process that event and get a response. Once that happens you could resubmit the order on the first tick assuming the position is now flat.

            Comment


              #7
              Ok, thank you again.

              When I learned, it seemed interesting that NT operates by default on last tick, rather than first tick, as it is pretty hard to tell if it was the last tick until the new tick happens (on some if not all bar types). I don't know why it was done that way, but I presume that in reality, it does end-of-bar processing when the new first tick is recognized, and is merely called OnBarClose to indicate that when the first new tick comes, the "OnBarClose" processing will be done before... some other processes.

              Ninjatrader seems to have some strange behaviour with start/end of bar processing with non-standard (range) bars, especially on historical processing with Tick Replay. All of my strategy processing is under a 'IsFirstTickOfBar' conditional, but often (about half the time) the historical entry is shown as starting on the last bar, not the first tick of the bar where it triggered.​

              Comment


                #8
                Hello DerkWehler,

                You are correct, the first tick of the bar is what closes the previous bar so there is really not a way in the API to know that's the last tick until the new tick comes in. If that's at the end of the session you won't see the bar close until the following session starts so any last tick type logic would have to be done using counters for tick series.

                Regarding the range bars I am unsure on that item specifically, if there is some issue with that I would need to see a sample of what code was used and what result was observed. That would likely be best off as a new thread if you wanted to investigate that further.

                Comment


                  #9
                  Originally posted by DerkWehler View Post
                  Ninjatrader seems to have some strange behaviour with start/end of bar processing with non-standard (range) bars, especially on historical processing with Tick Replay. All of my strategy processing is under a 'IsFirstTickOfBar' conditional, but often (about half the time) the historical entry is shown as starting on the last bar, not the first tick of the bar where it triggered.​
                  Okay, will do. I have presumed it is related to the time of the trade and time of close bar. It opens and closes at the right place, it just doesn't always show the open as being on the new bar.
                  But set to check on each tick, with tick replay enabled, the historical is supposed to do the same as real time, right?

                  Comment


                    #10
                    Hello DerkWehler,

                    TickReplay will process the tick data similar to realtime however there could be differences from realtime if you are using ask/bid prices as those are less granular than last prices.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    110 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    59 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    37 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    41 views
                    0 likes
                    Last Post TheRealMorford  
                    Started by Mindset, 02-28-2026, 06:16 AM
                    0 responses
                    78 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X