Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequiredToPlot Error

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

    BarsRequiredToPlot Error

    When BarsRequiredToPlot is set to 0, Chart Marker objects throw an error when placed on the first bar.

    #2
    No, they don't - at least not in general.

    I would imagine what you might be doing is adding more than one data series, but not checking if CurrentBars[0] >= 0 before you add the marker.

    Here's proof.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class NT8TestChartMarkerFirstBar : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name                                        = "NT8TestChartMarkerFirstBar";
    
                    BarsRequiredToPlot = 0;
                    IsOverlay = true;
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar == 0) Draw.ArrowUp(this, "TEST", false, 0, Low[0], Brushes.Purple);
            }
        }
    }​
    Click image for larger version

Name:	image.png
Views:	121
Size:	30.3 KB
ID:	1245246
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello schmidtbc16,

      Thanks for your post.

      It is not expected that setting BarsRequiredToPlot to 0 would cause an issue with drawing objects appearing on the chart.

      As QuantKey_Bruce stated, it could be caused from adding secondary data series to your script but not ensuring that there are enough bars on the chart before calling your draw object.

      Are you adding secondary series to your script using the AddDataSeries() method?

      If so, are you making a CurrentBars check to ensure you have enough bars processed in the series your are accessing?

      Make sure you have enough bars: https://ninjatrader.com/support/help...nough_bars.htm

      Please let me know if I may assist further.
      Last edited by NinjaTrader_BrandonH; 04-20-2023, 07:02 AM.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        This error only occurs when adding these objects manually on a chart, and not through a script.

        Comment


          #5
          Hello schmidtbc16,

          Thanks for your notes.

          It is not expected that a custom NinjaScript indicator would throw a BarsRequiredToPlot error when you manually draw objects on a chart.

          To clarify, are you using a custom NinjaScript indicator that you developed on the chart when this error occurs? Or, are you manually drawing objects on a chart that has no indicators attached?

          If you are using a custom NinjaScript on the chart when manually drawing objects, please share a reduced copy of the script throwing the error and the exact steps and settings used to reproduce the behavior.

          Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

          To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.​

          If you are not using a custom NinjaScript indicator on the chart when manually drawing objects, please send me the exact steps and settings you are using to reproduce the behavior.
          Last edited by NinjaTrader_BrandonH; 04-20-2023, 08:48 AM.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X