Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Built-In Parabolic SAR

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

    Built-In Parabolic SAR

    Good Morning,
    I'm calling the built-in indicator into my strategy. Sometimes, (not every time) I'm getting the following error message:
    Indicator 'Parabolic SAR': Error on calling 'OnBarUpdate' method on bar 1254: 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.
    Not sure what to fix since I normally change this piece of code when I see this error:


    Code:
    if (CurrentBar < 3)
    				return;
    But since it also has this, I'm not sure what to do...
    Code:
    			if (CurrentBar == 3)
    			{
    				// Determine initial position
    				longPosition = High[0] > High[1];
    				xp = longPosition ? MAX(High, CurrentBar)[0] : MIN(Low, CurrentBar)[0];
    				af = Acceleration;
    				Value[0] = xp + (longPosition ? -1 : 1) * ((MAX(High, CurrentBar)[0] - MIN(Low, CurrentBar)[0]) * af);
    				return;
    			}
    			else if (BarsArray[0].BarsType.IsRemoveLastBarSupported && CurrentBar < prevBar)
    			{....
    Please provide direction to make sufficient modifications so this will not cause error messages. Thanks.

    #2
    Hello zeller4,

    Thank you for writing in.

    I would suggest adding prints to the script to isolate where the error is coming as we don't have enough information to debug the issue.

    For example you could add on different lines of the script,

    Code:
    Print("Making it to line line 89");
    Print("Making it to line line 100");
    Print("Making it to line line 110");
    This way when the output window is open, you can isolate what line is throwing the error. If you take this approach, can you provide the line which causes the error?

    I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...

    I’ve provided a link covering debugging which you may find helpful.

    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    If you try the above and still unable to figure out the issue, please leave the print statements in the script and you can upload a copy and I'll take a look and see if anything jumps out.

    To export a NinjaScript from NinjaTrader 8 do the following:
    From the Control Center window select Tools -> Export -> NinjaScript...
    Click Add>Select the indicator>OK>Export.
    Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Since this is happening to the built-in NT indicator within my strategy, are you saying that adding print statements in my strategy will allow me to see how far the code made it through the Parabolic SAR code before it prints? Why would it create an error only sometime and not every time? It appears to me a try/catch block should be added to the NT built-in indicator to find out why it kicks out...
      Last edited by zeller4; 09-25-2018, 08:33 AM.

      Comment


        #4
        Hello zeller4,

        I overlooked that the code you posted was from the ParabolicSar and not your strategy, so no the prints wouldn't work in the strategy, however you could save a copy of the Parabolic Sar and add those prints in the copy to determine where the issue gets triggered. Try Catches would also be a good approach.

        Is there a specific instrument, time frame, bar type, day of the week, which triggers this error?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Using it on CL 11-18 on a UniRenko 242, today it kicked out 3 times but then allowed me to use it again... so it's running now. Not sure what is the bug?

          Comment


            #6
            Hello zeller4,

            Could you provide the strategy which gets this error?

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              AlanP,
              It's a highly customized set of indicators inside a customized strategy. Got any other suggestions?

              Comment


                #8
                Hello zeller4,

                I think the prints on different lines of a replicated Parabolic indicator would be the quickest way of finding the issue. Next time it happens, check the log, see the line.

                You could also debug with VS, however if it doesn't happen every time this approach may not be best. See,


                I look forward to your reply.
                Alan P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by giulyko00, Today, 12:03 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by f.saeidi, Today, 12:14 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by aprilfool, 12-03-2022, 03:01 PM
                2 responses
                327 views
                0 likes
                Last Post BottomShark77  
                Started by AnnBarnes, Today, 12:17 PM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by Lopat, 03-05-2023, 01:19 PM
                4 responses
                169 views
                0 likes
                Last Post Sam2515
                by Sam2515
                 
                Working...
                X