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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        83 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        45 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        65 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