Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry - BIP

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

    BarsSinceEntry - BIP

    This is probably all due to some erroneous user input, but every time I think I am beginning to understand the multi-time frame process, I get some weird/unexpected results. Driving me crazy.

    BIP = 0 = Day
    BIP = 1 = Week
    BIP = 2 = 10 minutes

    Here is the jist of the problem code:

    Code:
    if (BarsInProgress == 2)
    {
    	// Test for intraday
    	if (daily == true
    		&& Close[0] > CurrentDayOHL().CurrentOpen[0]
    		&& ToTime(Time[0]) >= 133500)
    	{
    		intraday = true;
    	}
    	
    	else
    	
    	{
    		intraday = false;
    	}
    	
    	// Enter long position
    	if (Position.MarketPosition == MarketPosition.Flat
    			&& intraday == true)
    	{	
    		EnterLong(2,1000,"Long");
    		SetProfitTarget("Long",CalculationMode.Ticks,ProfitTick);
    	}
    	//Exit one day after purchase
    	
    	if (Position.MarketPosition == MarketPosition.Long)
    	{					
    		if (BarsSinceEntry(2,"Long",0) > 0 //* 20  / BarsPeriods[2].Value
    			&& ToTime(Time[0]) >= 74000
    			&& ToTime(Time[0]) <= 83000)
    		{
    			Print("Exiting on Time" + ", " +Time[0] +", " + BarsSinceEntry(2,"Long",0)+"   "+BarsPeriods[2].Value);
    			ExitLong("Long");
    		}
    	
    
    	}
    
    }
    I am testing on a single instrument. The profit target kicks in most of the time. On the single time that it doesn't, the entry order is placed on 1/25/2010 at 1:50 p.m. Well and good. But - the exit order is realized on 1/27/2010 at 7:40 a.m.

    Output window yields:

    Exiting on Time, 1/27/2010 7:40:00 AM, 1 10

    In the course of testing, I set the critieria to > 0 just to see what happens. Setting the criteria to 1 changes the exit to 1/28/2010 7:40 a.m. It seems that the BarsSinceEntry is somehow using the primary BIP, which is not at all what I would expect from what I have gathered via forum and syntax references.

    Any help?
    Last edited by Day Trading Fool; 02-18-2010, 10:51 AM.

    #2
    Day Trading Fool,

    This is accurate behavior. BarsSinceEntry/Exit() is in relation to the first series with the instrument. It is not tied to other bar objects. The reason you use BIP is if you are using multiple instruments.

    To work with this you need to count the bars yourself on the other BIP contexts if that is your logic requirement.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the response.

      I am still confused. What do you mean by 'is in relation to the first series with the instrument'? Are you saying that BarsSinceEntry is always related to the primary bar? The Help reference makes it sound like the BIP index parameter is meant to associate/specify a BIP with BarsSinceEntry.

      Briefly - if a profit target is not met within a given time frame (by the end of the next trading day), I want to exit the position within another time frame (exit by a certain hour & minute of the next trading day). Which bars do I need count? The shortest? A combination?

      Comment


        #4
        No, not primary. It is related to the first bar series of that instrument. When using the same instrument then yes it is the primary. When using multiple instruments this may not necessarily be the primary.

        If you need minute granularity, count on minutes. If you need hours, doing a higher one will work.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Unfortunately I have no idea what the first bar series of an instrument is or how it is defined/assigned - is there any reference material that you could point me to?

          Thanks for the help.

          Comment


            #6
            You know it by how you are adding the series. You have to explicitly choose the order you add the Bar series when you do Add(). That is how you know which one is of which instrument. If you add it 3rd then it is going to be the 3rd BIP. If you add it 2nd then it will be the second.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Sorry - I am just not getting this.

              I am testing the strategy on one instrument.

              The primary bar is set via the options panel.

              The first and second bars are added as Week and Minute, 10 respectively.

              On the condition that BIP == 2, a long position is entered:

              EnterLong(2,1000,"Long");

              What is the '2' referring to? I assumed that this ties the entry to the '2' BIP. The position is entered on the tertiary bar, at least the time stamp reflects this.

              Why is some other - the 'first' - bar related to the tested instrument? What is the first bar in the presented case? Where could I find documentation on this? Is there a way I can print the bar that is related to the instrument for purposes of testing and understanding?

              Comment


                #8
                Day Trading Fool,

                What I have been saying is not in relation to Enter methods. It is for BarSinceEntry/Exit.

                If you go EnterLong(2, 1000, "Long") it will get filled on the next BIP2 context. BarsSinceEntry(2) will not return it to you in context of BIP2, but in context of the FIRST bars series for that instrument. In your scenario when you are only using one instrument that means the primary series will be used for counting.
                Attached Files
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                666 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                377 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                580 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X