Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy calling Indicator Error

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

    Strategy calling Indicator Error

    I have written an indicator that is working when I place it on a chart. I am now trying to use that indicator in a Strategy using BackTest and get the following error:
    Error on calling 'OnBarUpdate method for strategy 'PTrent': Index was outside the bounds of the array.

    I put print statements in the indicator and find the logic has completed Initialize(). I would expect the next statement to be executed would be OnBarUpdate() but a print statement as the first line here is not executed.

    What is executed after Initialize() and before OnBarUpdate() that could cause this error.

    #2
    The Initialize method of other strategies found in the strategies folder will be called. Look for where "PTrent" is defined.

    Comment


      #3
      Strategy calling Indicator Error

      Thanks for the reply.
      The only place PTrent exits is in the name of the running strategy. I am calling Indicator PT in the OnBarUpdate of PTrent Strategy with the following:

      Print( " "+ PT(Close,1,12).Filter[0]);

      A print statement just before this is printed. Then the Initialize routine in the Indicator PT is executed and prints show it finishes. At that point I get the error.
      Could the reference to .Filter[0] be causing the error at this point?

      There must be something executed in the Indicator that gives the error. It would be logical that the indicator must run before retuning a value unless it is the reference to .Filter[0].

      Comment


        #4
        Your assessment is correct so I recommend placing code throughout your indicator to find where the logic is fouling up.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I have place Print statements throughout the Indicator and before and after the call to the Indicator in the Strategy. They indicate that the Strategy starts and the call to the indicator is made(see below). Once the call is made only the initialize method is executed (print statement at end of this procedure is printed). Then the error occurs.

          The OnBarUpdate in the Indicator is never entered as there is a print statement as the first statement in that procedure.

          As far as I know there is no other routine I have access to that could fail between the time the Initialize method in the indicator is finished and the OnBarUpdate for the indicator is executed. So I have no way of telling where the error is coming from.

          The indicator does run fine when I apply it to a chart so there is something that is happening differently when it is call by the Strategy.

          Comment


            #6
            Chiming in here late...

            The error to me suggests that in your strategy PTrent, you are accessing an array with an index value outside of the current array bounds.

            doing something like this:

            Print(Close[1]);

            When CurrentBar == 0 would throw this error. If the problem was in the indicator itself, you would get an error referencing your indicator name.

            Here is some more helpful information.

            RayNinjaTrader Customer Service

            Comment


              #7
              Thanks Ray. The problem was in the indicator. I was not filling the Filter DataSeries as I thought I was. Now the question is why did I get an error pointing to the Strategy before the indicator was even executed.

              The strategy had the following code:
              if (CurrentBar> 50):
              {
              Print("ST St");
              Print( " "+ PT(Close,1,12).Filter[0]);
              Print("ST End");
              }
              The printout shows that I reach "ST St" and in the Indicator the Initialize was executed but not the "OnBarUpdate". So what was the strategy looking for before it executed the OnBarUpdate?

              Comment


                #8
                Unfortunately I am not sure.
                RayNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Graci117, Today, 09:02 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by ETFVoyageur, Today, 07:55 PM
                0 responses
                7 views
                0 likes
                Last Post ETFVoyageur  
                Started by janio973, Today, 07:24 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by aligator, 01-06-2022, 12:14 PM
                4 responses
                248 views
                0 likes
                Last Post john_44573  
                Started by reynoldsn, Today, 05:56 PM
                0 responses
                15 views
                0 likes
                Last Post reynoldsn  
                Working...
                X