Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How is BarsInProgress being calculated exactly? Is it an arrayList?

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

    How is BarsInProgress being calculated exactly? Is it an arrayList?

    I've looked around for this topic, and couldn't find something like this discussed.

    This is what I have:
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    AddDataSeries(Data.BarsPeriodType.Minute, 15);
    /* there's other stuff, but these are the only data series inputs */

    }

    If I'm correct in understanding this:
    protected override void OnBarUpdate()
    {
    if (logic){

    gapUpLong = EnterLongLimit(1, true,(int)orderQuantity,getSecondFib(PriorDayOHLC( ).PriorClose[0], CurrentDayOHL().CurrentHigh[0]),GapUpLong);
    Print("Gap Up Same Day"+ Position.Instrument+ " At current price: "+GetCurrentBid() + "At current bar: " + CurrentBar);
    }

    "1" stands for looking at the 5-minute data series here, and this should only be tested once.

    However, when I get printouts, I get subsequent values as such:
    Gap Up Same DayPRCP Default At current price: 7.27At current bar: 682

    Gap Up Same DayPRCP Default At current price: 6.26At current bar: 460

    Gap Up Same DayPRCP Default At current price: 5.86At current bar: 685

    Gap Up Same DayPRCP Default At current price: 5.6At current bar: 465

    The entries are also ONLY made at 683 and 685 if everything works out fine / etc. I have it set to sell on the next bar while I'm testing this.

    If I remove the second data series, then I don't get the additional bar calculations, but I'm curious as to WHY am I seeing them populate my output window?
    Or is the situation here that we're running an index on everything?

    However, if that's the case, then why am I not seeing current bars for time frame with 1 minute, since "BarsInProgress" default is relevant at 0, and is always there. I have to specify 1 in my case, to ensure it's looking at the 5-minute case.

    Thank you

    #2
    Hi lmatiukas, thanks for your question.

    You must separate logic by the BarsInProgress context when you want to filter logic to only one time frame e.g.

    Code:
    OnBarUpdate()
    {
        if(BarsInProgress == 0)
        {
            //This code will only run when OnBarUpdate is called for the Primary Series
        }
    
        if(BarsInProgress == 1)
        {
            //This code will only run when OnBarUpdate is called for the Secondary Series
        }
    
        //and so on
    }
    Please read through the multi time frame and instrument guide if you have not already:


    Please let me know if I can assist any further.

    Comment


      #3
      hey there,

      thanks for the quick reply - yea that makes perfect sense.

      In the end, I realized this is what I want. I want to be able to test the logic on multiple timeframes within a single strategy. Correct me if I'm wrong, but that would essentially be Close[1][0] - so that would test the latest close on the 5 minutes, and Close[2][0] - latest close on the 15 minutes?

      Or am I already basically performing it automatically as is? Close[0] would be confirmed to be true to something on the 5 minutes, AS WELL AS true on the 15 minutes since I am using both data series simultaneously?

      Still, a question on why the BarsInProgress default value of 0 doesn't run also. That is default at 1 minute right?
      Last edited by lmatiukas; 07-20-2020, 06:35 PM.

      Comment


        #4
        Hi lmatiukas, thanks for your reply.

        You can perform operations on the higher series, just make sure there are enough bars in each series e.g.

        Code:
        OnBarUpdate()
        {
            if(BarsInProgress == 0)
            {
                if(CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1) //make sure there is at lease one bar in each series
                    return;
        
                Print(Closes[0][0]);
                Print(Closes[1][0]);
                Print(Closes[2][0]);
            }
        BarsInProgress == 0 will become true, you should see this working. When a minute bar processes, BarsInProgress will be set to 0, then OnBarUpdate will be called for the 1 minute series.

        Please let me know if I can assist any further.

        Comment


          #5
          Your responses are slightly confusing to me. To be clear, my bars are at "1" and "2" for 5 minutes and 15 minutes. The 0 is ALWAYS there as the default?

          Comment


            #6
            Hi lmatiukas,

            Yes, that is correct. If your script adds no data series, BarsInProgress with always equal 0.

            Please let me know if I can assist any further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            46 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            66 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X