Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

out of bound issue

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

    out of bound issue

    I have a problem with this simple code below. May someone help ?
    Seems to be an out of bound issue....


    #region Variables
    // Wizard generated variables
    private int length = 20; // Default setting for Length
    // User defined variables (add any user defined variables below)


    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Aqua), PlotStyle.Line, "Xaverageorig"));
    Add(new Line(Color.FromKnownColor(KnownColor.Menu), 0, "Zero"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (CurrentBar == 1) {Xaverageorig[0]=Input[0];}
    else


    {Xaverageorig[0]=Xaverageorig[1]+(1/length)*(Input[0]-Xaverageorig[1]);}

    }

    #2
    You cannot access [1] when CurrentBar == 0.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      and how can i change that ?

      Comment


        #4
        At the top of OnBarUpdate()
        Code:
        if (CurrentBar < 1)
             return;
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I did as you told me and add this script on top of my code BUT when I try to plot in a chart I only get constant values. Here's the result of my output window.

          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5
          4676,5

          Comment


            #6
            kuroro13,

            Now you need to debug your script and try to figure out how it is evaluating your calculations. I suggest printing out values for each of the components and calculating by hand to see why it is doing what it is doing.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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