Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do you get Bars.PercentComplete on multiple time frames?

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

    How do you get Bars.PercentComplete on multiple time frames?

    Hi, I know how to do this on the single time frame:

    if (Bars.PercentComplete <= .5)
    {
    return (
    false);
    }

    // add the second time frame for trade execution of buys and sells
    Add(PeriodType.Minute, 5);

    I was expecting to be able to be able to do the following:
    if (Bars[1].PercentComplete <= .5)
    {
    return (
    false);
    }

    This returns an error.

    QUESTION: How do I get Bars.PercentComplete on the second time frame?

    #2
    Hello DaFish,
    Thanks for writing in and I am happy to assist you.

    Please use the BarsArray method to get the bar data information.

    Code:
    if (BarsArray[1].PercentComplete <= .5)
    {
      //do something
    }


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      hi, my code doesn't seem to be working for this.....

      protectedoverridevoid Initialize()
      {
      EntryHandling = EntryHandling.UniqueEntries;
      AllowRemovalOfDrawObjects =
      true;

      Add(PeriodType.Minute, intraPeriodInMinutes);
      CalculateOnBarClose = false;
      }

      protectedoverridevoid OnBarUpdate()
      {


      Print ("CurrentBars[0]: " + CurrentBars[0] + ", BarsArray[0].PercentComplete: " + BarsArray[0].PercentComplete);
      Print (
      "CurrentBars[1]: " + CurrentBars[1] + ", BarsArray[1].PercentComplete: " + BarsArray[1].PercentComplete);

      if(BarsInProgress == 0)
      {
      Print (
      "BarsArray[0].PercentComplete: " + BarsArray[0].PercentComplete);

      }
      if(BarsInProgress == 1)
      {
      Print (
      "BarsArray[1].PercentComplete: " + BarsArray[1].PercentComplete);

      }


      Does this code seem right to you? I was expecting the output window to be whipping out entries for EACH TICK of data. I only get one output per bar.....

      This is the output I get:

      IBM:Minute:5:FMDivergTFTLB:, CurrentBars[0]: 248, BarsArray[0].PercentComplete: 0.618345950666667, 3/28/12 10:45:00 AM
      IBM:Minute:1:FMDivergTFTLB:, CurrentBars[1]: 1247, BarsArray[1].PercentComplete: 0.0917297533333333, 3/28/12 10:48:00 AM
      IBM:Minute:1:FMDivergTFTLB:,, BarsArray[1].PercentComplete: 0.0917297533333333, 3/28/12 10:48:00 AM
      IBM:Minute:5:FMDivergTFTLB:, CurrentBars[0]: 248, BarsArray[0].PercentComplete: 0.811146978333333, 3/28/12 10:45:00 AM
      IBM:Minute:1:FMDivergTFTLB:, CurrentBars[1]: 1248, BarsArray[1].PercentComplete: 0.0557348916666667, 3/28/12 10:49:00 AM
      IBM:Minute:1:FMDivergTFTLB:,, BarsArray[1].PercentComplete: 0.0557348916666667, 3/28/12 10:49:00 AM
      IBM:Minute:5:FMDivergTFTLB:, CurrentBars[0]: 249, BarsArray[0].PercentComplete: 0.0190622036666668, 3/28/12 10:50:00 AM
      IBM:Minute:1:FMDivergTFTLB:, CurrentBars[1]: 1249, BarsArray[1].PercentComplete: 0.0953110183333333, 3/28/12 10:50:00 AM
      IBM:Minute:5:FMDivergTFTLB:, BarsArray[0].PercentComplete: 0.0190622036666668, 3/28/12 10:50:00 AM
      IBM:Minute:5:FMDivergTFTLB:, CurrentBars[0]: 249, BarsArray[0].PercentComplete: 0.0190622036666668, 3/28/12 10:50:00 AM
      IBM:Minute:1:FMDivergTFTLB:, CurrentBars[1]: 1249, BarsArray[1].PercentComplete: 0.0953110183333333, 3/28/12 10:50:00 AM
      IBM:Minute:1:FMDivergTFTLB:,, BarsArray[1].PercentComplete: 0.0953110183333333, 3/28/12 10:50:00 AM



      Comment


        #4
        Hello DaFish,
        Historical bars are evaluated at the end of the bar only. Only realtime data is evaluated tick-by-tick. To get the update on each tick please make sure you are running the code in realtime bars only and you are connected to your data feed.

        Please include the following code just below the OnBarUpdate

        Code:
        protected override void OnBarUpdate()
        {
          if (Historical) return;
        
           //rest of the code
        
        }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello DaFish,
          Historical bars are evaluated at the end of the bar only.
          I don't need to filter bars, I am ONLY getting Historical bars in my strategy.

          Originally posted by NinjaTrader_Joydeep View Post
          Only realtime data is evaluated tick-by-tick. To get the update on each tick please make sure you are running the code in realtime bars only and you are connected to your data feed.
          Hi Joydeep.

          1) I am running intraday data feed from Interactive Brokers AND Kinetic End of Day (free). I have disabled the Kinetic data feed - and still see the same problem. I see the current bar being generated up and down as the ticks come in on the actual chart. I see the BAR TIMER indicator counting down in real time - visually it looks right.

          2) I have CalculateOnClose = false;

          3) BUT my strategy is not firing off the messages I pasted in my original thread on EACH tick - which is what I expect to see.

          Question: Please check the code below should this be generating percent complete messages EACH TICK that comes in ?

          Comment


            #6
            I tried this code on it's own and it works as properly JoyDeep. Thanks you.

            I must have something in my code that is stopping the tick by tick processing. I'll have another look.


            protectedoverridevoid Initialize()
            {
            Add(PeriodType.Minute,
            5);
            Add(PeriodType.Minute,
            1);

            CalculateOnBarClose =
            false;
            }
            protectedoverridevoid OnBarUpdate()
            {
            if(BarsInProgress == 1)
            {
            if (BarsArray[1].PercentComplete >= .8)
            {
            Print (
            "CurrentBars[0]: " + CurrentBars[0] + " 5 Min bars - BarsArray[1].PercentComplete is over 80: " + BarsArray[0].PercentComplete);
            }
            }
            if(BarsInProgress == 2)
            {
            if (BarsArray[2].PercentComplete >= .8)
            {
            Print (
            "CurrentBars[0]: " + CurrentBars[0] + " 1 Min bars - BarsArray[2].PercentComplete is over 80: " + BarsArray[0].PercentComplete);
            }
            }
            }
            }

            Comment


              #7
              Hello DaFish,
              You have filtered the code as
              if (BarsArray[1].PercentComplete >= .8)
              {
              }

              thus if the bar do not completes >= .8 you wont get any tick-by-tick update.

              BarsArray[0].PercentageComplete is a real-time property only. I have seeked further clarification from development regarding this and will update you once I hear from them.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Hi Joydeep. No need. the code is working as you have provided the guidance to me.

                I have it working in my strategy now - thanks to you.

                Issue closed.

                Thanks

                Originally posted by NinjaTrader_Joydeep View Post
                Hello DaFish,
                You have filtered the code as
                if (BarsArray[1].PercentComplete >= .8)
                {
                }

                thus if the bar do not completes >= .8 you wont get any tick-by-tick update.

                BarsArray[0].PercentageComplete is a real-time property only. I have seeked further clarification from development regarding this and will update you once I hear from them.

                Comment


                  #9
                  Hello DaFish,
                  Thanks for the update.
                  Please let me know if I can assist you any further.
                  JoydeepNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  648 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  572 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X