Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lines Won't Draw

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

    Lines Won't Draw

    Hello,

    I have been playing around with indicators, and am just trying to draw a simple line based on the examples and documentation. However, I just cannot get it to draw. Nothing appears. Below is the code:

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TestPivot3 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TestPivot3";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    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;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    double PivotPoint = (High[1] + Low[1] + Close[1]) / 3;
    Draw.Line(this, "PP" + CurrentBar, false, 10, Low[0], 0, Low[10], Brushes.LimeGreen, DashStyleHelper.Dot, 2, true);

    // Draws a blue rectangle from the low 10 bars back to the high of 5 bars back
    Draw.Rectangle(this, "tag1", 10, Low[10] - TickSize, 5, High[5] + TickSize, Brushes.Blue);
    }
    }
    }

    Thank you

    #2
    Hello techsigma,

    Thanks for your post.

    When testing any code, it is good practice to keep an eye on the Log tab of the Control Center for any errors that occur. After testing the code you shared I see the following error occurring in the Log tab of the Control Center.

    Indicator 'TestPivot3': Error on calling 'OnBarUpdate' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    A CurrentBars check should be used in your indicator's logic to ensure that a certain number of bars have processed for all data series being used by the script before it begins calculation. A CurrentBars check would look something like this.

    Code:
    if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
        return;
    This would check to make sure that 10 bars have processed for the primary data series and added secondary series before the indicator begins it's calculations.

    See the help guide documentation below for more information.
    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

    Let us know if we may assist further.
    <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


      #3
      Thanks...I see the error.

      Comment

      Latest Posts

      Collapse

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