Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleFileReadWrite class already registered?

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

    SampleFileReadWrite class already registered?

    What I'm trying to do is to output a text file containing O,H,L,C,date,time and bar number. When I found the SampleFileReadWrite indicator, it seemed that it would be perfect for the job. All I would have to do is modify the output string to add the output of the bar number. To check it out, I imported SampleFileReadWrite and ran it on a 5min emini chart. Great results, no problem. So I changed the output string from:

    string ohlc = ToDay(Time[0]) + " " + Open[0] + " " + High[0] + " " + Low[0] + " " + Close[0] + Environment.NewLine; //this is line 58

    to:

    string ohlc = ToDay(Time[0]) + " " + Open[0] + " " + High[0] + " " + Low[0] + " " + Close[0] + " " + Convert.ToString(CurrentBar) + Environment.NewLine;



    When I went to compile this, I got the message:

    The following Ninja Script files have programming errors and must be resolved before compiling:

    Indicator\BarNumsOut2.cs The namespace 'NinjaTrader.Indicator' already contains a definition for 'SampleFileReadWrite' CS0101 - click for info 28 18

    //CS0101 has no documentation


    I'm new to C#, but have programmed in c before, as well as a few other languages, so I dug around online, and my best guess is that once SampleFileReadWrite was registered(?) as a derived class of NinjaTrader.Indicator, which happened when I tested out the original unaltered SampleFileReadWrite indicator, I was not allowed to compile the same code again (with my minor alteration) because it attempts to register *again* a public class of the same name, SampleFileReadWrite.

    *Is this the problem I'm having?* If this is what is happening, would it be right to say that if I had not run the original SampleFileReadWrite indicator, which registered the class in the first place, I would not have had a problem the second time around with my modified version?

    Based on this thinking, I first tried to delete the indicator from the list of compiled indicators, but I still got the error message when attempting to compile. So deleting the offending indicator did not remove the added class.

    I then went back to my modified version and renamed every occurance of "SampleFileReadWrite" to "SampleFileReadWrite2", thinking this would allow a new class to be registered, albeit with the same functionality. This allowed the modified indicator to compile without the error message, but the indicator then did not appear at all in the indicator list available to a chart, whereas the original SampleFileReadWrite indicator, which is now removed, had done so.

    So, having said all that, is there a way to remove the original SampleFileReadWrite class that the first, original indicator registered, so that the modified indicator will install? That would seem to be easiest, but is that even possible, or is that even my goal? Which is the best way to go from here?
    Thanks,
    Klopfgeist

    #2
    Klopfgeist, welcome to our forums here - all NinjaScripts would be compiled into one assembly file for runtime use, thus all current indicators and strategies need to be in compilable state to proceed - you can just doubleclick on the errors at the bottom of the NinjaScript editor to be taken directly to the offending lines in your scripts that would need debugging / commenting out to achieve a compile - http://www.ninjatrader.com/support/f...ead.php?t=4678

    When changing a class name (making for example a copy to works custom modifications in) you should always use the 'Save as' available via rightclick in the code - this will change the references as needed, too. In your case please delete the script giving you the issue and attempt to recompile from your new script.

    Comment


      #3
      Thank you, Bertrand

      Thank you, Bertrand. I cannot really tell from your answer whether you understood what was happening or not, but your answer made me realize that if I deleted all the indicators, and only made my changes in the NinjaTrader editor, that NinjaTrader would stop me on every error and keep me going in the right direction. I have done this and now have the output I need.

      Also, as you are in Germany, you certainly know who klopfgeist is. Years ago I was a customer of Emagic, the originators of the Logic Audio software products - products that were years ahead of their time - now owned by Apple. Klopfgeist was their metronome ghost.
      best,
      Chris

      Comment


        #4
        Glad to hear you got it resolved and working for you - I was not aware of Klopfgeist's history....

        Comment


          #5
          Hello, where can I get this SampleFileReadWrite indicator?

          Comment


            #6
            Hello,

            Thanks for your patience.

            Sure all samples are here:

            Following are links to all available NinjaScript reference samples within this forum section: Strategy Reference Samples (NinjaTrader 8) - also applicable to NT7 Using a time filter to limit trading hours (http://www.ninjatrader.com/support/forum/showthread.php?t=3226) Using multiple entry/exit signals simultaneously


            What your specifically interested in is the following:
            1. Using StreamWriter to write to a text file - also applicable to strategies
            2. Using StreamReader to read from a text file - also applicable to strategies
            3. Using System.IO File properties to write to and read from a text file - also applicable to strategies
            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X