• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

My Indicator stopped working ?

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

    My Indicator stopped working ?

    Hi,

    I had a developed an Indicator to work with 5 minute bars on a 2 minute chart. It was working all right but since yesterday it is giving me error. I can't think of any valid reason for it to stop working. I modified the indicator to very minimal code below to figure out why I am getting the error, but even the simple code below is not working. Totally lost as to what is going on. Here is the minimal code which is giving error:

    protected override void Initialize()
    {
    Overlay = true;
    Add(PeriodType.Minute, 5);
    }

    protected override void OnBarUpdate()
    {
    if(BarsInProgress > 0) //no need to process other time frames here
    return;

    if(CurrentBar > 500)
    {
    double emaFast = EMA(Closes[1],8)[0];
    //since its not working, just trying to print the values
    Print("CurrentBar: "+CurrentBar+" 5min-emaFast: "+emaFast);
    }

    I am getting the error:
    Error on calling 'OnBarUpdate' method for indicator 'AshIndicator1' on bar 501: You are accessing an index with a value that is invalid since its out of range.

    Please advise....

    #2
    put a try catch block.

    Comment


      #3
      The try / catch block will just catch the same error that is posted above.
      This code was working on Ninja Trader v7. But no longer works now for some mysterious reason. The CurrentBar > 500 makes sure that there are enough 5 minutes bars for 8 period EMA. Usually this kind of error shows up when the DataSeries does not have enough data points, but I fail to see a reason why 500 bars are not enough to calculate 8 period EMA ?

      Comment


        #4
        Hello Ash101, and thank you for your question. While your primary data series may be on bar 501, your secondary series may not be. Since you are trying to reference something 8 bars ago on your second series, you may like to use,

        Code:
        if (CurrentBar > 500 && CurrentBars[1] > 8)
        That will allow you to look up information in Closes[1] safely.

        Please let us know if there are any other ways we can help.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Yeah I understand that it may be good idea to check that other series has enough data points but in this case CurrentBar > 500 should be enough for 8 bars of 5 minutes (8*5/2 = 20 so I only need 20 bars of 2 minutes for the code to work).

          Anyway the code is working again unmodified. All I had to do was close all my charts and re-open them. It may be a weird bug in NinjaTrader v7 caching system or some other design artifact. I am good for now and if this issues repeats again, I will re-open my charts or if it gets annoying I will switch to version 8

          Comment


            #6
            While I can understand the expectation that bars always appear in chronological order, NinjaScript strategies must be developed so that OnBarUpdate is run asynchronously, or in other words, that when BarsInProgress == 1, no assumptions should be made about the case where BarsInProgress == 0, and programmers will need to take steps on their end to ensure data is synchronized. This is especially important in strategies that interface with incoming market data, which can be updated several times within the same millisecond.

            To make this easier on our users, we have provided the CurrentBars array. Checking every member of CurrentBars to make sure that each has enough bars to process will always allow you to run your strategy safely.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              OK. Thanks for the update !

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by tcfcigvo, Yesterday, 11:39 PM
              0 responses
              6 views
              0 likes
              Last Post tcfcigvo  
              Started by BobbyWan, Yesterday, 09:15 PM
              0 responses
              9 views
              0 likes
              Last Post BobbyWan  
              Started by trader14, Yesterday, 08:23 PM
              0 responses
              4 views
              0 likes
              Last Post trader14  
              Started by ares5918, Yesterday, 02:37 PM
              2 responses
              18 views
              0 likes
              Last Post ares5918  
              Started by RTR1701, 11-15-2016, 11:38 AM
              22 responses
              1,272 views
              0 likes
              Last Post afcmaff
              by afcmaff
               
              Working...
              X