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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        63 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        90 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        47 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        105 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        63 views
        0 likes
        Last Post PaulMohn  
        Working...
        X