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 sjsj2732, 03-23-2026, 04:31 AM
            0 responses
            42 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            295 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            290 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            135 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            98 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X