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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X