Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT Reflection error caused by indicator. Can't save or restore.

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

    NT Reflection error caused by indicator. Can't save or restore.

    RESOLVED: Shouldn't have public variables/fields. Changed to private and no more errors.

    When shutting down NT with my indicator loaded, I received the following error:
    Could not save indicator 'AAHSRIO': There was an error reflecting type 'NinjaTrader.NinjaScript.Indicators.AAHSRIO'.

    When I start NT back up, the following error is displayed in the control panel:
    Failed to restore indicator 'Unknown'. Most likely (a) the implementation changed or (b) one or more properties have been renamed or removed or (c) the custom assembly which implements this indicator no longer is there.

    I am not very knowledgeable with c# and my indicator is reading from a file, drawing some lines, and periodically exporting the price anchor of those lines back to a file in case they've changed.

    Can anyone see if there's something in my code that would be causing the above errors? I removed the auto-generated code at the bottom just for this post.
    Thanks!
    Last edited by hillborne; 07-17-2020, 11:28 PM.

    #2
    Hello hillborne,

    It looks like you were able to correct the script.

    Public objects are used as inputs in the Indicators window. Objects that are not inputs should be private.

    The XmlIgnore() attribute can be used to prevent objects from being saved in Xml if they are objects that auto convert to strings.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      A note about the "There was an error reflecting type ..." exception in NT8:

      I got the same error this (Monday) morning. It happened when the chart templates were loading after NT8 startup. I figured out what causes this cryptic error. Late on Friday, I had made a change to an indicator, changing one of the plot series variables from private to public, so that I could access it from a strategy. The indicator and strategy worked fine. However, this indicator happens to be part of a chart template that I use. Apparently, NT8 chart templates CANNOT HANDLE THAT, even though the indicator and the strategy (that references that indicator field) compile and work just fine. For some reason, the chart templates fail when trying to load that particular indicator into a chart (from the template). I had to change the plot series variable back to private (from public), and then the chart template loaded without issues.

      Comment


        #4
        Hello Plan 9,

        Templates have to be resaved if a script is modified.

        Otherwise the template will be referencing old code and may be incorrect.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I tried re-creating the template - several times. It still bombed when the new chart templates loaded. This may actually be an NT8 "undocumented feature". It is easy enough to reproduce.

          Comment


            #6
            Hello Plan 9,

            May I have a reduced export of the script to test on my end?
            Please remove all logic from the script that is not necessary to reproduce the error.

            To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
            1. Click Tools -> Export -> NinjaScript...
            2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
            3. Click the 'Export' button
            4. Enter a unique name for the file in the value for 'File name:'
            5. Choose a save location -> click Save
            6. Click OK to clear the export location message
            By default your exported file will be in the following location:
            • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
            Below is a link to the help guide on Exporting NinjaScripts.
            http://ninjatrader.com/support/helpG...-us/export.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Attached is an NT8 export of an indicator script that can be used to quickly reproduce the error. It is copy of @MACD, with the name changed to "MACD3". The ONLY other difference (other than the name) is that MACD3 has one Series declaration changed from "private" to "public" (near the top of the file). I wanted to expose a private series so that I can access it from another indicator. This same error happens with any indicator script, and with any private series being changed to public (I am just using MACD as an example). Here are the steps to reproduce the error:

              1) Import the archive into NT8. This will create a new version of MACD called MACD3.
              2) Bring up a new chart (any futures instrument will do).
              3) Load the MACD3 indicator onto the chart - It will load without a problem, and it works perfectly.
              4) Save a new chart template called "Test 1" (or any other name).
              5) Load the new chart template back into the chart (or into any other chart). The error will show up in the output window and in the log window.

              -- Plan 9
              Attached Files

              Comment


                #8
                Hello Plan 9,

                The line:
                public Series<double> slowEma;

                Would cause an issue.
                As it is public NinjaTrader will try and save this in xml when it is not an object that can be saved in xml which would cause an error.

                This needs to use the [XmlIgnore()] attribute.

                Please see the help guide.
                https://ninjatrader.com/support/help...eattribute.htm

                And take a look at the other public series in your script that are declared properly such as the Avg series on line 106.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks, that is essentially what I did to work around the issue (without realizing what the cause of the error was). The NT8 error message is not very helpful to programmers who are relatively new to NT8 ("NT Reflection error caused by indicator ...").

                  Comment


                    #10
                    Thank you Charls and thank you Plan 9, this was very helpful. Once I mastered the correct way to define properties, the errors I had disappeared for a while, but suddenly they came back when saving workspace.

                    Following the discussion above, I changed most of my variables to be private, protected or added the [XmlIgnore()] at the line above them. Workspace is saved without errors.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    576 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    553 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X