Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The time of the first 10 bars are not processed

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

    The time of the first 10 bars are not processed

    I have a very simple indicator that reads:
    Code:
    if(CurrentBar < 1) { return; }
    Values[0][0] = (Time[0]-Time[1]).TotalSeconds;
    However, it does not plot for the first 10 bars or so and then afterward it works correctly. I cannot figure out what the issue is. Appreciate any suggestions.

    #2
    Hello Photon66,

    Thank you for your post.

    Do you have a BarsRequiredToPlot setting specified in State.SetDefaults? If you set this to the following do you see it plot starting on the first bar from the left:

    Code:
    if (State == State.SetDefaults)
    
        {
    
             BarsRequiredToPlot = 1; 
    
        }
    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hi Kate, Thank you for the comment. I did not have BarsRequiredToPlot option in my code and even by adding it and setting it to 1, it did not correct it. The entire indicator is shown below:
      Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class timeBet : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "timeBet";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      IsSuspendedWhileInactive = true;
      BarsRequiredToPlot = 1; // -- > Added but did not make any diffrence
      
      AddPlot(Brushes.Orange, "TimeBetweenBars");
      }
      else if (State == State.Configure)
      {
      }
      }
      
      protected override void OnBarUpdate()
      {
      if(CurrentBar < 1) { return; }
      Values[0][0] = (Time[0]-Time[1]).TotalSeconds;
      }
      Thank you.

      Comment


        #4
        Hello Photon66,

        Thank you for your reply.

        I'm seeing this plotting all the way back to the 2nd bar on the chart (the first would be skipped since there's nothing to compare that first bar to). Have you removed the indicator from the chart and re-added it to ensure all changes are in place?

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Hi Kate, Thank you for checking my code. Since I could not figure out what the problem was, I reinstalled the NinjaTrader with the newest version and it solved the problem. Not sure what happened but the issue is resolved now. Thank you.
          Last edited by Photon66; 09-30-2021, 09:34 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 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
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X