Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry()

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

    BarsSinceEntry()

    I'm new to NT and I've tried to figure things out of my own but I have two questions that I need help on.

    The first thing I want to do is to set up a strategy to place a limit buy order which if isn't filled within a few bars is then canceled.

    The second thing I want to do is to not short if I've only been long for a few bars.

    I'm totally lost on question 1. How do cancel an order if my code is EnterLong(Shares, "Long");? How do I reference this order to find out its status and such?

    I've tried to detect how many bars have passed with the following code:
    if (BarsSinceEntry() < 10 )
    ...
    entryOrder = EnterLong(Shares, "Long");

    The problem here is that as soon as I add the if statement with BarsSinceEntry() my strategy never goes long during back testing. If I comment out that if statement there is no problem with going long. (The EnterLong is outside of the if logic)

    #2
    partial answer

    I think I've figured out the problem but I'm too new at this to know how to solve it from here.

    The problem seems to be that I've added another period and BarsSinceEntry() is relative to which period you're looking at? I used:

    Add(PeriodType.Minute, Interval);

    How do I get the bars since entry to work when I have more than one period?

    Comment


      #3
      Hi Phyre, for MultiInstrument and MultiTime strategies you want to use this syntax then -

      BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)

      For more info on strategies involving more than one Bars object please review this link - http://www.ninjatrader-support.com/H...struments.html

      Comment


        #4
        ?

        I don't understand what's going on here.

        Code:
        if (BarsInProgress == 0) 
            {
                if (BarsSinceEntry(0,"Long",1) < 10)
                  { 
                      // do nothing
                  }
             }
        First, I don't understand why when I add this code the number of total trades drops to 3. Even if this code is wrong why does it break the rest of my strategy?

        Second, why is this wrong?

        Comment


          #5
          Phyre,

          We have no way of evaluating your strategy with just snippets. If you feel it is limiting your trades you will want to debug. Please use TraceOrders = true along with Print() calls throughout to track your strategy.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            How can this code snippet possibly change the way the rest of my code works?

            Originally posted by NinjaTrader_Josh View Post
            Phyre,

            We have no way of evaluating your strategy with just snippets. If you feel it is limiting your trades you will want to debug. Please use TraceOrders = true along with Print() calls throughout to track your strategy.

            Comment


              #7
              Phyre,

              We have no way to evaluate this for you. You would need to debug on your end. Please proceed with TraceOrders and Print()s. Thank you.

              If behavior has changed, then something in your code has been influenced. Code does exactly what it is told. It is a matter of digging to the bottom of it. Unfortunately we are not in a position to do this for you.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Ok, forget the original question. My new question is how can the if statement I posted change the output of the program? The if statement does nothing so I'm confused. The only way this makes any sense to me is if the BarsSinceEntry call changes something.

                I had assumed that the BarsSinceEntry was not capable of making changes and only returned the results. Is this a wrong assumption?

                Comment


                  #9
                  Problem found

                  I had a print statement which still had BarsSinceEntry() in it instead of BarsSinceEntry(0,"Long",1).

                  Why does that call cause a break in the code?

                  Comment


                    #10
                    As Josh indicated, it's hard if not impossible to comment on those snippets without the relation to your full strategy code, I'm glad though you found the issue you lined out. If you post your code, we can take a look to help you out.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    630 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    566 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X