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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      68 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      151 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X