Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

simple question on Charting, first 20 bars missing?

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

    simple question on Charting, first 20 bars missing?

    Just created a simple indicator to plot the closing price of each bar, on the chart, the plot always starts from the 21st bar, the first 20 bars are not plotted, why is that?

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = 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]);
    }
    Attached Files

    #2
    redartanjin,

    I am happy to assist you.

    This is due to the fact that by default the indicator is waiting for 20 bars before it will allow it to start calculating. This is to prevent accessing elements in a dataseries that do not exist yet, which can cause indicators to throw exceptions and not work at all. You can right click your chart > go to data series > set bars or days to load to a larger number to plot these values.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      can you clarify how those first 20 bars are handled in the application, are they skipped altogether, so the calculation in the script will completely ignore them and start from whatever the 21st bar is?

      is it 20 bars regardless of the bar time? (20 days in daily bars and 20 min in 1-min bars)

      on a multi-time frame chart, for example, a 1-min and 15-min multi-time chart, how is that handled internally?

      Comment


        #4
        redartajnin,

        They are still used in any future calculations that need them but they are skipped to prevent out-of-bounds exceptions in arrays.

        On multi-time frame you need to be careful, as you can have out of bounds exceptions if you do not check for BarsInProgress, which is equal to 0 when OnBarUpdate is called for the primary dataseries, 1 when for the secondary, etc.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        11 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        9 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        387 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X