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 cmoran13, 04-16-2026, 01:02 PM
            0 responses
            44 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            27 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            163 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            98 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            158 views
            2 likes
            Last Post CaptainJack  
            Working...
            X