Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Event handler probelm

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

    Event handler probelm

    Hi my strategy gets disable with following output. What do i need to do?

    Indicator 'EMA': Error on calling 'OnBarUpdate' method on bar 16218: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    Strategy 'Algo': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.


    I have

    else if (State == State.DataLoaded)
    {
    ClearOutputWindow(); //Clears Output window every time strategy is enabled
    fastEMA = EMA(FastEMAPeriod);
    slowEMA = EMA(SlowEMAPeriod);
    baseEMA = EMA(BaseEMAPeriod);​
    }
    region Bars in progress 2
    else if (BarsInProgress == 2 && IsFirstTickOfBar)
    {
    if (CurrentBars[0] < 20 || CurrentBars[2] < 6 )
    return;

    fastHTFEMA = EMA(BarsArray[2], 8);
    slowHTFEMA = EMA(BarsArray[2], 34);
    baseHTFEMA = EMA(BarsArray[2], 89);
    base200HTFEMA = EMA(BarsArray[2], 200);​​

    #2
    Sometimes in my logic i use other emas but i dont define them anywhere just like this. Would this throw an error? or its totally fine
    Close[1] > EMA(600)[1]

    Comment


      #3
      EMA(600)[1]? EMA's need a dataseries of some kind here instead of a number like 600.
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Can you provide an example of how i would do that?

        Comment


          #5
          I'm assuming he means like EMA(Close,600)[1] or some other Input(s).

          Comment


            #6
            It's perfectly fine to use a statement like Close[1] > EMA(Close, 600)[1] but is not as efficient.
            eDanny
            NinjaTrader Ecosystem Vendor - Integrity Traders

            Comment


              #7
              Hello tkaboris,

              What is the specific line of code causing the error?

              Have you called AddDataSeries() twice in State.Configure?

              If you print BarsArray.Count() does this print 3 or higher?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                So for my EMAs i have
                private EMA fastEMA, slowEMA, baseEMA;
                in dataload i define them
                fastEMA = EMA(Close, 8);
                slowEMA = EMA(Close, 34);
                baseEMA = EMA(Close, 89);

                and i reference them as
                Low[1] <= slowEMA[1]

                I am still getting the same error after strategy runs for a while
                Indicator 'EMA': Error on calling 'OnBarUpdate' method on bar 34295: You are accessing an index with a value that is invalid since it is out-of-range.
                What can it be?​

                Question
                I declare EMAs for secondary series in the same place where i declare EMAs for my primary series. is this right?
                private EMA fastEMA, slowEMA, baseEMA;
                private EMA slowHTFEMA, baseHTFEMA, fastHTFEMA, base200HTFEMA;
                Last edited by tkaboris; 08-28-2023, 10:41 AM.

                Comment


                  #9
                  Hello tkaboris,

                  If you still have an error you need to simplify the problem. We can't tell why you get that error just based on the lines you extracted. As Chelsea mentioned we need to know what specific line of code is having an error to be able to help.

                  To proceed you would have to debug the code and find what specific line inside OnBarUpdate is having an error and post that line only. Based on that line we can see what is being used and provide further direction.

                  Comment


                    #10
                    BarsArray.Count() dispalys 3.
                    0 - primary.
                    1 - for ticks graniluity
                    2 - HTF higher time frame

                    I will try to single out what line cauising an issue..

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    59 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    134 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    75 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X