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 CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            27 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            20 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            183 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            335 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            260 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X