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

code works on some charts, but not on others

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

    code works on some charts, but not on others

    I recently added new plots to an older pre-existing ninjascript that can be found here in post #3 (ElliotOscillator1.2.zip):


    My modified version of the above indicator is attached here in this post for reference purposes.
    In the attached picture, one can identify the two new plots which I added by looking for the yellow colored lines in the subgraph.

    For testing purposes, I added an input which allows the user to enable or disable the new plots which I added.

    When the input called "OSC_strengthband_show" is set to false, the code always works and is identical to the older original version from the link above.

    When the input called "OSC_strengthband_show" is set to true, I have observed that the indicator only works on certain combinations of instrument, resolution, and session but not on others. I suspect that the code is throwing an exception due to a null value or a NaN or something similar which is being generated within the code changes which I added.

    My lack of deep experience with ninjascript programming should be noted. If anyone here can offer any ideas on how to fix the attached code, it would be greatly appreciated.
    Attached Files

    #2
    kh_model,

    I have loaded your indicator and testing it on about 8 different instruments. I am currently unable to replicate your issue.

    When you experience the issue, please check your Log tab in the control center for error messages.

    Also, please post replication steps i.e. instrument you are using, time frame, etc.

    Though we don't normally debug custom indicators for people as it is unsupported, Im happy to see if there is something causing this issue that is obvious.

    I look forward to helping.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      workspaces and log for replication of problem conditions

      Thank you Adam for your efforts. I have uploaded two sample workspaces and a log. These should make it easy to replicate the problem that I described earlier.

      The first workspace should not have any problems, it is called "test_eOscBands_1".
      The second workspace called "test_eOscBands_2" simply changes resolution from 6 point to 12 point, and the indicator stops working as described previously.

      After loading the second workspace called "test_eOscBands_2", the log reports:
      "12/9/2011 1:05:51 PM|3|4|Error on calling 'OnBarUpdate' method for indicator 'ElliotOscBands' on bar 559: Index was outside the bounds of the array."
      Attached Files

      Comment


        #4
        kh_model,

        Using a Try/Catch its says the issue is with line 166. Here is a reference sample on using Try/Catch.



        Unfortunately your code is quite long so it would be difficult for me to pinpoint the exact issue. Most likely it has something to do with this :

        OSC_var14 = OSC_var24[(int)OSC_var21, 0];

        The (int)OSC_var21 portion.

        You may want to double check the OSC_Var21 wherever it is set using Print() statements and the output window. Ensure that such an index exists on the OSC_var24 array.

        Please let me know if I may assist further.
        Last edited by NinjaTrader_AdamP; 12-09-2011, 03:36 PM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thank you Adam, for your hard work and extremely helpful insights yet again! I will try to replicate your Try Catch statements in my code, and I will look at the link you provided carefully. Since I am inexperienced with try/catch and you seem to have applied it already with some success, would it be possible for you to upload what you were working on even if it is in very rough shape? I could certainly benefit from seeing what you did. Thanks again and please have a good weekend!

          Comment


            #6
            kh_model,

            No problem.

            Essentially I did this :

            Code:
            protected override void OnBarUpdate()
            {
            
               try
               {
            
                   //all of your code is in here that is in the OnBarUpdate() brackets
            
               }
               catch( Exception e)
               {
                   Print(e.ToString());
               }
            
            
            }
            You only need to be careful where you put that brackets { } . Essentially I just put the Try{} around your code, then added the Catch(Exception e ){ Print(e.ToString()); } at the end, but before the closing bracket } of the OnBarUpdate() method.

            You can also add these try/catches by section so you have some identification where its coming from. Anything in the Try block will get caught by the Catch, however. Try/Catch blocks are generally used for gracefully handling errors and debugging. The nice thing is they also identify the lines the error comes from in NT.

            Please don't hesitate to contact us should you require additional assistance.
            Last edited by NinjaTrader_AdamP; 12-09-2011, 03:40 PM.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Stanfillirenfro, Today, 07:23 AM
            8 responses
            23 views
            0 likes
            Last Post Stanfillirenfro  
            Started by DayTradingDEMON, Today, 09:28 AM
            2 responses
            15 views
            0 likes
            Last Post DayTradingDEMON  
            Started by navyguy06, Today, 09:28 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            32 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            22 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X