Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot A Price Line

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

    Plot A Price Line


    Hi

    Me + a friend are trying to plot a simple line that follows the close price. But we cant get it working.

    I know that the function is already available. But this is an exercise to learn Ninjascript. So... what are we doing wrong?

    /thanks

    {
    public class PlotCurrentPrice : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "PlotCurrentPrice";
    Calculate = Calculate.OnPriceChange;
    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;
    Price = 1;
    AddPlot(Brushes.White, "PriceLine");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {

    }

    protected override void OnBarUpdate()
    {
    Value[0] = Input[CurrentBar];
    }

    #2
    Hello danerius,

    Thank you for the post.

    The problem here is that you are setting the Plot to the Input of [CurrentBars] ago. This would set the price to a constant value of the first bar on the charts value.

    BarsAgo works backwards from the current processing bar meaning if you use Input[0], this is the currently processing bar or current price or the price most right on the chart. CurrentBar is the index of that bar. By using the index of the most right bar as the BarsAgo, you are saying to get the price from the beginning of the series ( CurrentBar BarsAgo from now).

    One other note is that you are using Input, I am not certain if that was intentional or not but Input will use whatever series is supplied to your indicator, if you specifically want to use Open High Low or Close, please see the following page which has some examples of commonly used series and also BarsAgo being used:


    For learning I also suggest the following section, specifically the References and Tips sections contain samples: https://ninjatrader.com/support/help..._resources.htm

    I look forward to being of further assistance.

    Comment


      #3
      Hi and thanks for the quick reply

      We will look into this asap

      /danerius

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      583 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      339 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