Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Plotting 3 lines beside Wizard generated code

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

    Plotting 3 lines beside Wizard generated code

    Using Wizard, I first generated this code in order to plot 3 lines :

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "Plot2"));
    CalculateOnBarClose = false;
    Overlay = false;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(Close[0]);
    Plot1.Set(Close[0]);
    Plot2.Set(Close[0]);
    }

    It went Ok, displaying a DarkViolet pricemarker.


    Then I altered the plotting that way :

    Plot1.Set(Close[1]);
    Plot2.Set(Close[2]);

    As a result, I no longer get any line displayed on my chart. How come ?

    #2
    The reason you are not getting any line is because your code is now referencing indexes out of range. To fix this you need to add this at the beginning of OnBarUpdate():
    Code:
    if(CurrentBar < 2)
         return;
    Basically on the very first bar there is no Close[1] or Close[2] and it causes errors. When you add the above code it tells NinjaTrader to not run the calculations till there are at least 2 bars and that will circumvent the error of referencing nonexistent indexes. Hope that helps.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot, Josh. Best regards.
      Gérard

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      192 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,234 views
      0 likes
      Last Post xiinteractive  
      Working...
      X