Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry in multi-time frame & instrument strategies

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

    BarsSinceEntry in multi-time frame & instrument strategies

    Hi!,

    I think this could probably be a bug, I used this statement:

    BarsSinceEntry(1, "Up", 0)

    And it allways returns a zero

    By the way when I use:

    BarsSinceEntry(1, "Up", 1)

    it returns the numbers of bars of the last position, but It doesn't returns the number of bars of the last opened and not closed position, what I was expecting since there is another statement BarsSinceExit... it's a bit confusing.


    Ok if this is the way this works, then please:

    do you know how can I get the number of bars since I have an order in market and not closed?

    Thanks

    #2
    joanNT,

    0 should show you the number of bars on your BIP1 context trades with the name "Up". Please be sure you actually have a trade open with this name and in this BIP context.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Yes I'm sure cause of the code:

      in context BIP==0 I throw this order to BIP==1:
      ordenlanzada = EnterLongStop(1, true, contratos, entrada, "Up");

      and in BIP==1:
      if (Position.MarketPosition != MarketPosition.Flat) {
      Print ("Intento salida2 " + BarsSinceEntry(1, "Up", 0));
      if (BarsSinceEntry(1, "Up", 0)== tiempo_maximo ) {
      ExitLong(contratos, "OutUp_t", "Up");
      }
      }

      Another thing that I'm sure it's that this happens doing backtesting, I don't know if this is important or not.

      Thans

      Comment


        #4
        joanNT, got a reproducible case here and will look into, thanks for reporting in.

        Comment


          #5
          joanNT, to clarify - were you trading two different instruments in this script? The expected outcome would be BarsSinceEntry returning you the bars you're in the trade for the specific instrument added as Bars object.

          Comment


            #6
            No I was trading only one instrument with another data series smaller.

            Comment


              #7
              joanNT,

              To clarify when you are using a single instrument, when you use BarsSinceEntry() with a BIP index, the BIP index is not to notify which BIP context you are trying to access, but to notify the BIP index of the instrument being traded. When both BIP indexes are of the same instrument it will use the primary index to return you the bars back. There is no way to get bars since entry value in terms of different BIPs for the same instrument with this method.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Then which method do I have to use? if this is not valid there is another one? or perhaps if I try BarsSinceEntry(0, "Up", 0) it will work?

                Comment


                  #9
                  No, there is no other method. The method will always return you the bars since entry in terms of the BIP0 context when you are using single instrument strategies. Pushing in BIP1 with BarsSinceEntry(1, "someEntry", 0) just means get the instrument of BIP1. Since BIP1 is the same instrument as BIP0 you get back the bars since entry in terms of the primary Bars for that instrument. Should you want it in your other BIPs you need to self program your own methods to do so.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Perfectly clear. Thanks Josh

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    602 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    347 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    103 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    560 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    559 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X