Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to know on which bar a Buy Stop market order is filled

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

    How to know on which bar a Buy Stop market order is filled

    Hi,

    I am developing a strategy which executes a Buy Stop market order and maintains it on each successive bar until the price crosses it.

    I'd like to run a check in my code to know if the order was filled in the Current Bar, I thought I could check the change in market position between it being flat on the previous bar and long in the current bar however MarketPosition does not let you access the previous bar.

    Is there a way I can achieve this?

    Thanks,

    Neil

    #2
    Hello burtoninlondon,

    You can use BarsSinceEntryExecution for that purpose: https://ninjatrader.com/support/help...=barssinceentr

    That reports -1 for no fills found or a 0/positive number when found.

    Comment


      #3
      Thanks NinjaTrader_Jesse.

      Can I ask a follow on question? My strategy is base on 5-minute intervals...assume the order is filled at some point on the current bar, is there a way to modify a stop loss position on the same bar a minute or so later or would I have to wait for the end of the current bar and process the adjustment on the next bar?

      Neil

      Comment


        #4
        Hello burtoninlondon,

        If you are using OnEachTick or OnPriceChange that would be possible. Alternatively in manual coding a secondary series can be used for more granular logic at a fixed interval.


        Comment


          #5
          Thanks

          Originally posted by NinjaTrader_Jesse View Post
          Alternatively in manual coding a secondary series can be used for more granular logic at a fixed interval.
          Do you mean, using a 1 min time series for example?

          Comment


            #6
            Hello burtoninlondon,

            That's right, you can use AddDataSeries and BarsInProgress to delegate logic to a secondary series. https://ninjatrader.com/support/help...=AddDataSeries

            Comment


              #7
              I've been looking at the documentation for BarsSinceEntryExecution() and if I have a second data series based on 1-min time frame, presumably running BarsSinceEntryExecution() will return the integer value based on the primary data series which is 5-min time frame.

              I'm unsure how to associate BarsSinceEntryExecution() with the second data series (1-min), can you help?

              Thanks

              Comment


                #8
                Hello burtoninlondon,

                In the use case with the secondary series you wouldn't need to use BarsSinceEntryExecution,, you could instead store the CurrentBars[1] at the time of the entry and then compare that against the current bar in the secondary series.

                An example would be:

                Code:
                private int storedBar;
                
                protected override void OnBarUpdate()
                {
                
                if(BarsInProgress == 0)
                { 
                    // some entry condition
                    EnterLong
                    storedBar = CurrentBars[1];
                }
                if(BarsInProgress == 1)
                { 
                    if(CurrentBar - storedBar >= 2)  // the difference in bars between the stored bar and now is greater equal 2 meaning 2 or more minutes while using a 1 minute series. 
                
                
                }

                Comment


                  #9
                  HI, NinjaTrader_Jesse, thanks for the suggestion.

                  Just out of interest, the syntax in the documentation for BarsSinceEntryExecution() is BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo) so presumably would the code for the the primary data series be BarsSinceEntryExecution(0, "", 0) and the secondary data series be BarsSinceEntryExecution(1, "", 0)?

                  Also, I don't understand what the entryExecutionsAgo parameter does, the documentation says "Number of entry executions ago. Pass in 0 for the number of bars since the last entry execution."...can you help me understand what this means?

                  Thanks again for your help.

                  Neil

                  Comment


                    #10
                    Hello burtoninlondon,

                    Just out of interest, the syntax in the documentation for BarsSinceEntryExecution() is BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo) so presumably would the code for the the primary data series be BarsSinceEntryExecution(0, "", 0) and the secondary data series be BarsSinceEntryExecution(1, "", 0)?
                    Thats correct however as the note says in the help guide any same instrument will report based on the primary, so if you had 1 minute and 15 minute as the same instrument then the 1 minute series will be used for BarsSinceEntryExecution(1, "", 0).

                    The "Number of entry executions ago" is the instance of the execution. For example you could want to get a few instances ago of an order to get historical price, if you use more than 0 it gets a farther back execution in history. 0 is the latest execution.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    56 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    132 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X