Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please! Help with code on Volume.

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

    Please! Help with code on Volume.

    Why is this not returning anything on chart.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class PL : Indicator
    {

    private double pol;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"PL";
    Name = "PL";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;

    AddPlot(new Stroke(Brushes.Red), PlotStyle.Line, "Plot0");

    }
    else if (State == State.Configure)
    {

    }
    }
    protected override void OnBarUpdate()
    {

    }

    #region Properties

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Plot0
    {
    get { return Values[0]; }
    }
    #endregion
    Last edited by olchik; 01-01-2021, 03:44 AM.

    #2
    Hello olchik,
    Add below code before your calculation:
    Code:
    if(CurrentBar < 2)
    return;
    Hope it helps!

    Comment


      #3
      s.kinra Yes! Thank you very much!

      Comment


        #4
        Hello olchik,

        Welcome to the NinjaTrader forums!

        s.kinra is indicating there may be an indexing error when calling Volume[2] or Close[2] before there are two bars existing.

        If a script does not appear to enabled, be sure to check the Log tab of Control Center for run-time error messages which disable the script.

        Below are links to the help guide on indexing errors and CurrentBar.

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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